New Features

This commit is contained in:
LcrW
2021-05-10 21:04:52 +01:00
parent 08a9a00330
commit f9e1dc3ffb
6 changed files with 174 additions and 0 deletions

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