开始更新ScriptableCall函数
This commit is contained in:
@@ -10,6 +10,14 @@ namespace Demo.Editor
|
||||
{
|
||||
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)
|
||||
{
|
||||
stream.Write($"def {name}({string.Join(',', paramList)}):\n");
|
||||
@@ -17,68 +25,87 @@ namespace Demo.Editor
|
||||
}
|
||||
|
||||
private static void WriteCPPClassBase(StreamWriter stream, Type currentType)
|
||||
{
|
||||
if (currentType == typeof(ScriptableObject))
|
||||
{
|
||||
{
|
||||
string currentTypeName = GetTypename(currentType);
|
||||
string baseTypeName = GetTypename(currentType.BaseType);
|
||||
if (currentType == typeof(ScriptableObject))
|
||||
{
|
||||
// <20><><EFBFBD>ƹ<EFBFBD><C6B9>ߺ<EFBFBD>
|
||||
stream.WriteLine("#define __build_in_pragma #");
|
||||
stream.WriteLine("#define __build_in_to_text(x) #x");
|
||||
stream.WriteLine("#define __build_in_pragma #");
|
||||
stream.WriteLine("#define __build_in_to_text(x) #x");
|
||||
stream.WriteLine("#define this");
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ඨ<EFBFBD><E0B6A8><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>
|
||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ඨ<EFBFBD><E0B6A8><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>
|
||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var type in asm.GetTypes())
|
||||
{
|
||||
// Functions
|
||||
if (typeof(ScriptableObject).IsAssignableFrom(type))
|
||||
{
|
||||
string typeName = type.Name;
|
||||
if (typeName.Contains('`'))
|
||||
{
|
||||
typeName = typeName[..typeName.LastIndexOf('`')];
|
||||
}
|
||||
stream.WriteLine($"#define {typeName}");
|
||||
string typeName = GetTypename(type);
|
||||
stream.WriteLine($"#define {typeName} \"{typeName}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>Mathf
|
||||
foreach (var method in typeof(Mathf).GetMethods())
|
||||
{
|
||||
{
|
||||
stream.WriteLine($"#define {method.Name}({string.Join(',', from param in method.GetParameters() select param.Name)})");
|
||||
}
|
||||
}
|
||||
foreach (var curveType in Enum.GetNames(typeof(MathExtension.EaseCurveType)))
|
||||
{
|
||||
stream.WriteLine($"#define {curveType}");
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>label<65><6C>goto
|
||||
stream.Write(@"
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>RScript<70>ؼ<EFBFBD><D8BC><EFBFBD>
|
||||
{
|
||||
stream.Write(@"
|
||||
/*
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩ
|
||||
*/
|
||||
");
|
||||
stream.Write($"#define label(label_name) __build_in_pragma define label_name\n\n");
|
||||
stream.Write(@"
|
||||
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ʱ<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>label<EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>prΪ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>label<EFBFBD><EFBFBD>
|
||||
*/
|
||||
");
|
||||
stream.Write($"#define goto(a,b,label_name)\n\n");
|
||||
// <20><><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>
|
||||
stream.Write(@"
|
||||
stream.Write($"#define goto(pr,label_name)\n\n");
|
||||
}
|
||||
{
|
||||
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);
|
||||
<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 with(...)\n\n");
|
||||
return;
|
||||
}
|
||||
string baseTypeName = currentType.BaseType.Name;
|
||||
if (baseTypeName.Contains('`'))
|
||||
{
|
||||
baseTypeName = baseTypeName[..baseTypeName.LastIndexOf('`')];
|
||||
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.WriteLine($"struct {currentTypeName}:public {baseTypeName}");
|
||||
stream.WriteLine("{");
|
||||
}
|
||||
stream.Write($"#include \"{baseTypeName}.helper.h\"\n\n");
|
||||
}
|
||||
|
||||
private static void WriteCPPStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
|
||||
@@ -96,7 +123,13 @@ e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateHelperFiles(string dir, ProjectDefaultFileStyle style = ProjectDefaultFileStyle.CPP)
|
||||
private static void WriteCPPClassEnd(StreamWriter stream, Type currentType)
|
||||
{
|
||||
stream.WriteLine("};");
|
||||
}
|
||||
|
||||
|
||||
public static void CreateHelperFiles(string dir, ProjectDefaultFileStyle style = ProjectDefaultFileStyle.CPP)
|
||||
{
|
||||
var toolDir = new ToolFile(dir);
|
||||
if (toolDir.IsDir() == false)
|
||||
@@ -115,12 +148,8 @@ e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
|
||||
where info is MethodInfo
|
||||
where info.GetCustomAttribute<ScriptableCallAttribute>(false) != null
|
||||
select info as MethodInfo).ToList();
|
||||
var typeName = type.Name;
|
||||
if (typeName.Contains('`'))
|
||||
{
|
||||
typeName = typeName[..typeName.LastIndexOf('`')];
|
||||
}
|
||||
string fileHeader = $"{typeName}.helper" + style switch
|
||||
var typeName = GetTypename(type);
|
||||
string fileHeader = $"{typeName}.helper" + style switch
|
||||
{
|
||||
ProjectDefaultFileStyle.PY => ",py",
|
||||
_ => ".h"
|
||||
@@ -146,8 +175,16 @@ e.g: LoadSubScript(SplineCore, ""SplineCore.h"") with(r = 1, g = 1, b = 1);
|
||||
WriteCPPStyleFunction(fs, methodInfo.Name, from param in methodInfo.GetParameters() select param.Name, data.Description);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (style)
|
||||
{
|
||||
case ProjectDefaultFileStyle.CPP:
|
||||
WriteCPPClassEnd(fs, type);
|
||||
break;
|
||||
case ProjectDefaultFileStyle.PY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Enums
|
||||
if (typeof(Enum).IsAssignableFrom(type)&& type.GetCustomAttribute<ScriptableCallAttribute>(false) != null)
|
||||
{
|
||||
|
||||
@@ -853,6 +853,10 @@ namespace Demo
|
||||
{ "this", 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);
|
||||
}
|
||||
|
||||
|
||||
Submodule Assets/Scripts/Framework/[RScript] updated: 7b48066aaf...58f3d1067c
Reference in New Issue
Block a user