diff --git a/Content/Editor/Scripting/CppAssetTemplate.h b/Content/Editor/Scripting/CppAssetTemplate.h index 43fcaea90..8d6cca1d4 100644 --- a/Content/Editor/Scripting/CppAssetTemplate.h +++ b/Content/Editor/Scripting/CppAssetTemplate.h @@ -14,8 +14,10 @@ API_CLASS() class %module%%class% : public ISerializable API_AUTO_SERIALIZATION(); DECLARE_SCRIPTING_TYPE_NO_SPAWN(%class%); public: + // Custom float value. API_FIELD(Attributes = "Range(0, 20), EditorOrder(0), EditorDisplay(\"Data\")") float FloatValue = 20.0f; + // Custom vector data. API_FIELD(Attributes = "EditorOrder(1), EditorDisplay(\"Data\")") Vector3 Vector3Value = Vector3(0.1f); }; diff --git a/Content/Editor/Scripting/CppStaticClassTemplate.cpp b/Content/Editor/Scripting/CppStaticClassTemplate.cpp index f1e6c0714..084f83281 100644 --- a/Content/Editor/Scripting/CppStaticClassTemplate.cpp +++ b/Content/Editor/Scripting/CppStaticClassTemplate.cpp @@ -4,7 +4,5 @@ void %class%::RunNativeAction(Vector4 data) { - LOG(Warning, "Data in RunNativeAction: {0}", data.ToString()); + LOG(Warning, "Data in RunNativeAction: {0}", data); } - - diff --git a/Content/Editor/Scripting/CppStaticClassTemplate.h b/Content/Editor/Scripting/CppStaticClassTemplate.h index bf207a1e0..dccfceecf 100644 --- a/Content/Editor/Scripting/CppStaticClassTemplate.h +++ b/Content/Editor/Scripting/CppStaticClassTemplate.h @@ -3,6 +3,7 @@ #include #include + /// /// %class% Function Library /// @@ -10,10 +11,10 @@ API_CLASS(Static) class %module%%class% { DECLARE_SCRIPTING_TYPE_MINIMAL(%class%); public: + /// /// Logs the function parameter natively. /// - /// Vector4 parameter - /// void + /// Data to pass to native code API_FUNCTION() static void RunNativeAction(Vector4 data); }; diff --git a/Content/Editor/Scripting/ScriptTemplate.h b/Content/Editor/Scripting/ScriptTemplate.h index f52b767e3..a865498fa 100644 --- a/Content/Editor/Scripting/ScriptTemplate.h +++ b/Content/Editor/Scripting/ScriptTemplate.h @@ -1,7 +1,7 @@ %copyright% #pragma once -#include "Engine/Scripting/Script.h" +#include API_CLASS() class %module%%class% : public Script { diff --git a/Source/Editor/Content/Proxy/CppAssetProxy.cs b/Source/Editor/Content/Proxy/CppAssetProxy.cs deleted file mode 100644 index d0ca63a42..000000000 --- a/Source/Editor/Content/Proxy/CppAssetProxy.cs +++ /dev/null @@ -1,57 +0,0 @@ -// 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 -{ - /// - /// Context proxy object for C++ Json Asset files. - /// - /// - public class CppAssetProxy : ScriptProxy - { - /// - public override string Name => "C++ Json Asset"; - - /// - public override bool IsProxyFor(ContentItem item) - { - return item is CppScriptItem; - } - - /// - 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); - } - - /// - public override string FileExtension => "cpp"; - - /// - public override Color AccentColor => Color.FromRGB(0x9c1c9c); - } -} diff --git a/Source/Editor/Content/Proxy/CppProxy.cs b/Source/Editor/Content/Proxy/CppProxy.cs new file mode 100644 index 000000000..9ced48653 --- /dev/null +++ b/Source/Editor/Content/Proxy/CppProxy.cs @@ -0,0 +1,134 @@ +// 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 +{ + /// + /// Context proxy object for C++ files. + /// + /// + public abstract class CppProxy : ScriptProxy + { + /// + /// Gets the paths for header and source files to format. + /// + /// The header template path. + /// The source template path. + protected abstract void GetTemplatePaths(out string headerTemplate, out string sourceTemplate); + + /// + public override bool IsProxyFor(ContentItem item) + { + return false; + } + + /// + public override void Create(string outputPath, object arg) + { + // 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 "; + } + + 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); + + GetTemplatePaths(out var headerTemplatePath, out var sourceTemplatePath); + if (headerTemplatePath != null) + { + var headerTemplate = File.ReadAllText(headerTemplatePath); + headerTemplate = headerTemplate.Replace("%copyright%", copyrightComment); + headerTemplate = headerTemplate.Replace("%class%", scriptName); + headerTemplate = headerTemplate.Replace("%module%", module); + headerTemplate = headerTemplate.Replace("%filename%", filename); + File.WriteAllText(Path.ChangeExtension(outputPath, ".h"), headerTemplate, Encoding.UTF8); + } + if (sourceTemplatePath != null) + { + var sourceTemplate = File.ReadAllText(sourceTemplatePath); + sourceTemplate = sourceTemplate.Replace("%copyright%", copyrightComment); + sourceTemplate = sourceTemplate.Replace("%class%", scriptName); + sourceTemplate = sourceTemplate.Replace("%module%", module); + sourceTemplate = sourceTemplate.Replace("%filename%", filename); + File.WriteAllText(outputPath, sourceTemplate, Encoding.UTF8); + } + } + + /// + public override string FileExtension => "cpp"; + + /// + public override Color AccentColor => Color.FromRGB(0x9c1c9c); + } + + /// + /// Context proxy object for C++ script files. + /// + /// + public class CppScriptProxy : CppProxy + { + /// + public override string Name => "C++ Script"; + + /// + public override bool IsProxyFor(ContentItem item) + { + return item is CppScriptItem; + } + + /// + protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate) + { + headerTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.h"); + sourceTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.cpp"); + } + } + + /// + /// Context proxy object for C++ Json Asset files. + /// + /// + public class CppStaticClassProxy : CppProxy + { + /// + public override string Name => "C++ Function Library"; + + /// + protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate) + { + headerTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppStaticClassTemplate.h"); + sourceTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppStaticClassTemplate.cpp"); + } + } + + /// + /// Context proxy object for C++ Json Asset files. + /// + /// + public class CppAssetProxy : CppProxy + { + /// + public override string Name => "C++ Json Asset"; + + /// + protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate) + { + headerTemplate = null; + sourceTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppAssetTemplate.h"); + //sourceTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppAssetTemplate.cpp"); + } + + /// + public override string FileExtension => "h"; + } +} diff --git a/Source/Editor/Content/Proxy/CppScriptProxy.cs b/Source/Editor/Content/Proxy/CppScriptProxy.cs deleted file mode 100644 index 8bad93021..000000000 --- a/Source/Editor/Content/Proxy/CppScriptProxy.cs +++ /dev/null @@ -1,65 +0,0 @@ -// 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 -{ - /// - /// Context proxy object for C++ script files. - /// - /// - public class CppScriptProxy : ScriptProxy - { - /// - public override string Name => "C++ Script"; - - /// - public override bool IsProxyFor(ContentItem item) - { - return item is CppScriptItem; - } - - /// - public override void Create(string outputPath, object arg) - { - // Load templates - var headerTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.h")); - var sourceTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.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); - } - - /// - public override string FileExtension => "cpp"; - - /// - public override Color AccentColor => Color.FromRGB(0x9c1c9c); - } -} diff --git a/Source/Editor/Content/Proxy/CppStaticClassProxy.cs b/Source/Editor/Content/Proxy/CppStaticClassProxy.cs deleted file mode 100644 index 7d4ac7b22..000000000 --- a/Source/Editor/Content/Proxy/CppStaticClassProxy.cs +++ /dev/null @@ -1,65 +0,0 @@ -// 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 -{ - /// - /// Context proxy object for C++ Json Asset files. - /// - /// - public class CppStaticClassProxy : ScriptProxy - { - /// - public override string Name => "C++ Function Library"; - - /// - public override bool IsProxyFor(ContentItem item) - { - return item is CppScriptItem; - } - - /// - 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); - } - - /// - public override string FileExtension => "cpp"; - - /// - public override Color AccentColor => Color.FromRGB(0x9c1c9c); - } -}