Merge branch 'master' of git://github.com/LCRW/FlaxEngine into LCRW-master
This commit is contained in:
21
Content/Editor/Scripting/CppAssetTemplate.h
Normal file
21
Content/Editor/Scripting/CppAssetTemplate.h
Normal file
@@ -0,0 +1,21 @@
|
||||
%copyright%
|
||||
#pragma once
|
||||
|
||||
#include <Engine/Core/ISerializable.h>
|
||||
#include <Engine/Core/Types/BaseTypes.h>
|
||||
#include <Engine/Content/Assets/Model.h>
|
||||
#include <Engine/Scripting/ScriptingType.h>
|
||||
|
||||
/// <summary>
|
||||
/// %class% Json Asset.
|
||||
/// </summary>
|
||||
API_CLASS() class %module%%class% : public ISerializable
|
||||
{
|
||||
API_AUTO_SERIALIZATION();
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(%class%);
|
||||
public:
|
||||
API_FIELD(Attributes = "Range(0, 20), EditorOrder(0), EditorDisplay(\"Data\")")
|
||||
float FloatValue = 20.0f;
|
||||
API_FIELD(Attributes = "EditorOrder(1), EditorDisplay(\"Data\")")
|
||||
Vector3 Vector3Value = Vector3(0.1f);
|
||||
};
|
||||
10
Content/Editor/Scripting/CppStaticClassTemplate.cpp
Normal file
10
Content/Editor/Scripting/CppStaticClassTemplate.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
%copyright%
|
||||
#include "%filename%.h"
|
||||
#include <Engine/Core/Log.h>
|
||||
|
||||
void %class%::RunNativeAction(Vector4 data)
|
||||
{
|
||||
LOG(Warning, "Data in RunNativeAction: {0}", data.ToString());
|
||||
}
|
||||
|
||||
|
||||
19
Content/Editor/Scripting/CppStaticClassTemplate.h
Normal file
19
Content/Editor/Scripting/CppStaticClassTemplate.h
Normal file
@@ -0,0 +1,19 @@
|
||||
%copyright%
|
||||
#pragma once
|
||||
|
||||
#include <Engine/Scripting/Script.h>
|
||||
#include <Engine/Core/Math/Vector4.h>
|
||||
/// <summary>
|
||||
/// %class% Function Library
|
||||
/// </summary>
|
||||
API_CLASS(Static) class %module%%class%
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(%class%);
|
||||
public:
|
||||
/// <summary>
|
||||
/// Logs the function parameter natively.
|
||||
/// </summary>
|
||||
/// <param name="data">Vector4 parameter</param>
|
||||
/// <returns>void</returns>
|
||||
API_FUNCTION() static void RunNativeAction(Vector4 data);
|
||||
};
|
||||
@@ -4,23 +4,30 @@ using FlaxEngine;
|
||||
|
||||
namespace %namespace%
|
||||
{
|
||||
/// <summary>
|
||||
/// %class% Script.
|
||||
/// </summary>
|
||||
public class %class% : Script
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override void OnStart()
|
||||
{
|
||||
// Here you can add code that needs to be called when script is created, just before the first game update
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void OnEnable()
|
||||
{
|
||||
// Here you can add code that needs to be called when script is enabled (eg. register for events)
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void OnDisable()
|
||||
{
|
||||
// Here you can add code that needs to be called when script is disabled (eg. unregister from events)
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void OnUpdate()
|
||||
{
|
||||
// Here you can add code that needs to be called every frame
|
||||
|
||||
57
Source/Editor/Content/Proxy/CppAssetProxy.cs
Normal file
57
Source/Editor/Content/Proxy/CppAssetProxy.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using FlaxEditor.Content.Settings;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace FlaxEditor.Content
|
||||
{
|
||||
/// <summary>
|
||||
/// Context proxy object for C++ Json Asset files.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||
public class CppAssetProxy : ScriptProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "C++ Json Asset";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsProxyFor(ContentItem item)
|
||||
{
|
||||
return item is CppScriptItem;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Create(string outputPath, object arg)
|
||||
{
|
||||
// Load templates
|
||||
var headerTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppAssetTemplate.h"));
|
||||
|
||||
// Find the module that this script is being added (based on the path)
|
||||
var module = string.Empty;
|
||||
var project = TryGetProjectAtFolder(outputPath, out var moduleName);
|
||||
if (project != null)
|
||||
{
|
||||
module = moduleName.ToUpperInvariant() + "_API ";
|
||||
}
|
||||
|
||||
// Format
|
||||
var gameSettings = GameSettings.Load();
|
||||
var scriptName = ScriptItem.CreateScriptName(outputPath);
|
||||
var copyrightComment = string.IsNullOrEmpty(gameSettings.CopyrightNotice) ? string.Empty : string.Format("// {0}{1}{1}", gameSettings.CopyrightNotice, Environment.NewLine);
|
||||
headerTemplate = headerTemplate.Replace("%copyright%", copyrightComment);
|
||||
headerTemplate = headerTemplate.Replace("%class%", scriptName);
|
||||
headerTemplate = headerTemplate.Replace("%module%", module);
|
||||
// Save
|
||||
File.WriteAllText(Path.ChangeExtension(outputPath, ".h"), headerTemplate, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FileExtension => "cpp";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Color AccentColor => Color.FromRGB(0x9c1c9c);
|
||||
}
|
||||
}
|
||||
65
Source/Editor/Content/Proxy/CppStaticClassProxy.cs
Normal file
65
Source/Editor/Content/Proxy/CppStaticClassProxy.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using FlaxEditor.Content.Settings;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace FlaxEditor.Content
|
||||
{
|
||||
/// <summary>
|
||||
/// Context proxy object for C++ Json Asset files.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||
public class CppStaticClassProxy : ScriptProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "C++ Function Library";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsProxyFor(ContentItem item)
|
||||
{
|
||||
return item is CppScriptItem;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Create(string outputPath, object arg)
|
||||
{
|
||||
// Load templates
|
||||
var headerTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppStaticClassTemplate.h"));
|
||||
var sourceTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppStaticClassTemplate.cpp"));
|
||||
|
||||
// Find the module that this script is being added (based on the path)
|
||||
var module = string.Empty;
|
||||
var project = TryGetProjectAtFolder(outputPath, out var moduleName);
|
||||
if (project != null)
|
||||
{
|
||||
module = moduleName.ToUpperInvariant() + "_API ";
|
||||
}
|
||||
|
||||
// Format
|
||||
var gameSettings = GameSettings.Load();
|
||||
var scriptName = ScriptItem.CreateScriptName(outputPath);
|
||||
var filename = Path.GetFileNameWithoutExtension(outputPath);
|
||||
var copyrightComment = string.IsNullOrEmpty(gameSettings.CopyrightNotice) ? string.Empty : string.Format("// {0}{1}{1}", gameSettings.CopyrightNotice, Environment.NewLine);
|
||||
headerTemplate = headerTemplate.Replace("%copyright%", copyrightComment);
|
||||
headerTemplate = headerTemplate.Replace("%class%", scriptName);
|
||||
headerTemplate = headerTemplate.Replace("%module%", module);
|
||||
sourceTemplate = sourceTemplate.Replace("%filename%", filename);
|
||||
sourceTemplate = sourceTemplate.Replace("%copyright%", copyrightComment);
|
||||
sourceTemplate = sourceTemplate.Replace("%class%", scriptName);
|
||||
sourceTemplate = sourceTemplate.Replace("%filename%", filename);
|
||||
|
||||
// Save
|
||||
File.WriteAllText(Path.ChangeExtension(outputPath, ".h"), headerTemplate, Encoding.UTF8);
|
||||
File.WriteAllText(outputPath, sourceTemplate, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FileExtension => "cpp";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Color AccentColor => Color.FromRGB(0x9c1c9c);
|
||||
}
|
||||
}
|
||||
@@ -911,6 +911,8 @@ namespace FlaxEditor.Modules
|
||||
Proxy.Add(new ParticleSystemProxy());
|
||||
Proxy.Add(new SceneAnimationProxy());
|
||||
Proxy.Add(new CSharpScriptProxy());
|
||||
Proxy.Add(new CppAssetProxy());
|
||||
Proxy.Add(new CppStaticClassProxy());
|
||||
Proxy.Add(new CppScriptProxy());
|
||||
Proxy.Add(new SceneProxy());
|
||||
Proxy.Add(new PrefabProxy());
|
||||
|
||||
Reference in New Issue
Block a user