diff --git a/Content/Editor/Scripting/CppAssetTemplate.h b/Content/Editor/Scripting/CppAssetTemplate.h new file mode 100644 index 000000000..43fcaea90 --- /dev/null +++ b/Content/Editor/Scripting/CppAssetTemplate.h @@ -0,0 +1,21 @@ +%copyright% +#pragma once + +#include +#include +#include +#include + +/// +/// %class% Json Asset. +/// +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); +}; diff --git a/Content/Editor/Scripting/CppStaticClassTemplate.cpp b/Content/Editor/Scripting/CppStaticClassTemplate.cpp new file mode 100644 index 000000000..f1e6c0714 --- /dev/null +++ b/Content/Editor/Scripting/CppStaticClassTemplate.cpp @@ -0,0 +1,10 @@ +%copyright% +#include "%filename%.h" +#include + +void %class%::RunNativeAction(Vector4 data) +{ + LOG(Warning, "Data in RunNativeAction: {0}", data.ToString()); +} + + diff --git a/Content/Editor/Scripting/CppStaticClassTemplate.h b/Content/Editor/Scripting/CppStaticClassTemplate.h new file mode 100644 index 000000000..c037f3564 --- /dev/null +++ b/Content/Editor/Scripting/CppStaticClassTemplate.h @@ -0,0 +1,19 @@ +%copyright% +#pragma once + +#include +#include +/// +/// %class% Function Library +/// +API_CLASS(Static) class %module%%class% +{ + DECLARE_SCRIPTING_TYPE_MINIMAL(%class%); +public: + /// + /// Logs the function parameter natively. + /// + /// Vector4 parameter + /// void + API_FUNCTION() void RunNativeAction(Vector4 data); +}; diff --git a/Source/Editor/Content/Proxy/CppAssetProxy.cs b/Source/Editor/Content/Proxy/CppAssetProxy.cs new file mode 100644 index 000000000..d0ca63a42 --- /dev/null +++ b/Source/Editor/Content/Proxy/CppAssetProxy.cs @@ -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 +{ + /// + /// 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/CppStaticClassProxy.cs b/Source/Editor/Content/Proxy/CppStaticClassProxy.cs new file mode 100644 index 000000000..7d4ac7b22 --- /dev/null +++ b/Source/Editor/Content/Proxy/CppStaticClassProxy.cs @@ -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 +{ + /// + /// 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); + } +} diff --git a/Source/Editor/Modules/ContentDatabaseModule.cs b/Source/Editor/Modules/ContentDatabaseModule.cs index ed1f69726..0ed73e987 100644 --- a/Source/Editor/Modules/ContentDatabaseModule.cs +++ b/Source/Editor/Modules/ContentDatabaseModule.cs @@ -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());