Merge branch 'master' of git://github.com/LCRW/FlaxEngine into LCRW-master

This commit is contained in:
Wojtek Figat
2021-05-12 12:22:23 +02:00
7 changed files with 182 additions and 1 deletions

View 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);
};

View 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());
}

View 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);
};

View File

@@ -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

View 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);
}
}

View 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);
}
}

View File

@@ -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());