开始更新ScriptableCall函数
This commit is contained in:
@@ -10,6 +10,14 @@ namespace Demo.Editor
|
|||||||
{
|
{
|
||||||
public static class ProjectCreateHelper
|
public static class ProjectCreateHelper
|
||||||
{
|
{
|
||||||
|
private static string GetTypename(Type type)
|
||||||
|
{
|
||||||
|
string result = type.Name;
|
||||||
|
if (result.Contains('`'))
|
||||||
|
return result[..result.LastIndexOf('`')];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static void WritePythonStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
|
private static void WritePythonStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
|
||||||
{
|
{
|
||||||
stream.Write($"def {name}({string.Join(',', paramList)}):\n");
|
stream.Write($"def {name}({string.Join(',', paramList)}):\n");
|
||||||
@@ -18,6 +26,8 @@ namespace Demo.Editor
|
|||||||
|
|
||||||
private static void WriteCPPClassBase(StreamWriter stream, Type currentType)
|
private static void WriteCPPClassBase(StreamWriter stream, Type currentType)
|
||||||
{
|
{
|
||||||
|
string currentTypeName = GetTypename(currentType);
|
||||||
|
string baseTypeName = GetTypename(currentType.BaseType);
|
||||||
if (currentType == typeof(ScriptableObject))
|
if (currentType == typeof(ScriptableObject))
|
||||||
{
|
{
|
||||||
// <20><><EFBFBD>ƹ<EFBFBD><C6B9>ߺ<EFBFBD>
|
// <20><><EFBFBD>ƹ<EFBFBD><C6B9>ߺ<EFBFBD>
|
||||||
@@ -32,12 +42,8 @@ namespace Demo.Editor
|
|||||||
// Functions
|
// Functions
|
||||||
if (typeof(ScriptableObject).IsAssignableFrom(type))
|
if (typeof(ScriptableObject).IsAssignableFrom(type))
|
||||||
{
|
{
|
||||||
string typeName = type.Name;
|
string typeName = GetTypename(type);
|
||||||
if (typeName.Contains('`'))
|
stream.WriteLine($"#define {typeName} \"{typeName}\"");
|
||||||
{
|
|
||||||
typeName = typeName[..typeName.LastIndexOf('`')];
|
|
||||||
}
|
|
||||||
stream.WriteLine($"#define {typeName}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,35 +56,56 @@ namespace Demo.Editor
|
|||||||
{
|
{
|
||||||
stream.WriteLine($"#define {curveType}");
|
stream.WriteLine($"#define {curveType}");
|
||||||
}
|
}
|
||||||
// <20><><EFBFBD><EFBFBD>label<65><6C>goto
|
// <20><><EFBFBD><EFBFBD>RScript<70>ؼ<EFBFBD><D8BC><EFBFBD>
|
||||||
|
{
|
||||||
stream.Write(@"
|
stream.Write(@"
|
||||||
/*
|
/*
|
||||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩ
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩ
|
||||||
*/
|
*/
|
||||||
");
|
");
|
||||||
stream.Write($"#define label(label_name) __build_in_pragma define label_name\n\n");
|
stream.Write($"#define label(label_name) __build_in_pragma define label_name\n\n");
|
||||||
stream.Write(@"
|
|
||||||
/*
|
|
||||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>a>bʱ<62><CAB1>ת<EFBFBD><D7AA>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>label<65><6C>
|
|
||||||
*/
|
|
||||||
");
|
|
||||||
stream.Write($"#define goto(a,b,label_name)\n\n");
|
|
||||||
// <20><><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>
|
|
||||||
stream.Write(@"
|
|
||||||
/*
|
|
||||||
<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ
|
|
||||||
e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
|
|
||||||
*/
|
|
||||||
");
|
|
||||||
stream.Write($"#define with(...)\n\n");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
string baseTypeName = currentType.BaseType.Name;
|
|
||||||
if (baseTypeName.Contains('`'))
|
|
||||||
{
|
{
|
||||||
baseTypeName = baseTypeName[..baseTypeName.LastIndexOf('`')];
|
stream.Write(@"
|
||||||
|
/*
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>prΪ<72><CEAA>ʱ<EFBFBD><CAB1>ת<EFBFBD><D7AA>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>label<65><6C>
|
||||||
|
*/
|
||||||
|
");
|
||||||
|
stream.Write($"#define goto(pr,label_name)\n\n");
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
stream.Write(@"
|
||||||
|
/*
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>prΪ<72><CEAA>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>goto<74><6F>λ<EFBFBD><CEBB>, ջģʽ
|
||||||
|
*/
|
||||||
|
");
|
||||||
|
stream.Write($"#define back(pr)\n\n");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
stream.Write(@"
|
||||||
|
/*
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>prΪ<72><CEAA>ʱ<EFBFBD>˳<EFBFBD><CBB3><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>
|
||||||
|
*/
|
||||||
|
");
|
||||||
|
stream.Write($"#define break(pr)\n\n");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
stream.Write(@"
|
||||||
|
/*
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ佫<D5BC><E4BDAB><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>, <20><>Ҫʹ<D2AA><CAB9>goto<74><6F><EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
");
|
||||||
|
stream.Write($"#define namespace(name)\n\n");
|
||||||
|
}
|
||||||
|
stream.WriteLine($"struct {currentTypeName}");
|
||||||
|
stream.WriteLine("{");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
stream.Write($"#include \"{baseTypeName}.helper.h\"\n\n");
|
stream.Write($"#include \"{baseTypeName}.helper.h\"\n\n");
|
||||||
|
stream.WriteLine($"struct {currentTypeName}:public {baseTypeName}");
|
||||||
|
stream.WriteLine("{");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteCPPStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
|
private static void WriteCPPStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
|
||||||
@@ -96,6 +123,12 @@ e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void WriteCPPClassEnd(StreamWriter stream, Type currentType)
|
||||||
|
{
|
||||||
|
stream.WriteLine("};");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void CreateHelperFiles(string dir, ProjectDefaultFileStyle style = ProjectDefaultFileStyle.CPP)
|
public static void CreateHelperFiles(string dir, ProjectDefaultFileStyle style = ProjectDefaultFileStyle.CPP)
|
||||||
{
|
{
|
||||||
var toolDir = new ToolFile(dir);
|
var toolDir = new ToolFile(dir);
|
||||||
@@ -115,11 +148,7 @@ e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
|
|||||||
where info is MethodInfo
|
where info is MethodInfo
|
||||||
where info.GetCustomAttribute<ScriptableCallAttribute>(false) != null
|
where info.GetCustomAttribute<ScriptableCallAttribute>(false) != null
|
||||||
select info as MethodInfo).ToList();
|
select info as MethodInfo).ToList();
|
||||||
var typeName = type.Name;
|
var typeName = GetTypename(type);
|
||||||
if (typeName.Contains('`'))
|
|
||||||
{
|
|
||||||
typeName = typeName[..typeName.LastIndexOf('`')];
|
|
||||||
}
|
|
||||||
string fileHeader = $"{typeName}.helper" + style switch
|
string fileHeader = $"{typeName}.helper" + style switch
|
||||||
{
|
{
|
||||||
ProjectDefaultFileStyle.PY => ",py",
|
ProjectDefaultFileStyle.PY => ",py",
|
||||||
@@ -147,6 +176,14 @@ e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch (style)
|
||||||
|
{
|
||||||
|
case ProjectDefaultFileStyle.CPP:
|
||||||
|
WriteCPPClassEnd(fs, type);
|
||||||
|
break;
|
||||||
|
case ProjectDefaultFileStyle.PY:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Enums
|
// Enums
|
||||||
if (typeof(Enum).IsAssignableFrom(type)&& type.GetCustomAttribute<ScriptableCallAttribute>(false) != null)
|
if (typeof(Enum).IsAssignableFrom(type)&& type.GetCustomAttribute<ScriptableCallAttribute>(false) != null)
|
||||||
|
|||||||
@@ -853,6 +853,10 @@ namespace Demo
|
|||||||
{ "this", new() { data = this, type = this.GetType() } },
|
{ "this", new() { data = this, type = this.GetType() } },
|
||||||
{ "self", new() { data = this, type = this.GetType() } }
|
{ "self", new() { data = this, type = this.GetType() } }
|
||||||
};
|
};
|
||||||
|
foreach (var type in DefaultInstantiate.GetScriptableObjectInstantiate().Keys)
|
||||||
|
{
|
||||||
|
variables.Add(type, new(type.GetType(), type));
|
||||||
|
}
|
||||||
return engine.RunAsync(script, importClass, variables);
|
return engine.RunAsync(script, importClass, variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Submodule Assets/Scripts/Framework/[RScript] updated: 7b48066aaf...58f3d1067c
Reference in New Issue
Block a user