正在为RScript更新内容(已通过编译)

This commit is contained in:
2025-10-27 20:24:15 +08:00
parent b85f6699a0
commit 6dcf842e25
35 changed files with 598 additions and 1019 deletions

View File

@@ -31,7 +31,6 @@ namespace Demo.Editor
[Resources] public Text CurrentTimeText;
[Resources] public Text CurrentFPS;
[Setting] public const string SceneName = "GameScene";
[Setting] public ProjectDefaultFileStyle CurrentProjectDefaultFileStyle = default;
[Setting] public bool IsLowPerformance = false;
[Content] public string LastLoadProjectName = "";
@@ -330,7 +329,6 @@ namespace Demo.Editor
};
content.SetSongCurrentTime = InjectSetSongCurrentTime;
content.SongLoadOverCallback = InjectSongLoadOverCallback;
content.CurrentProjectDefaultFileStyle = CurrentProjectDefaultFileStyle;
SceneManager.LoadSceneAsync(SceneName, LoadSceneMode.Additive).completed += x =>
{
LastLoadProjectName = ProjectName;
@@ -382,7 +380,7 @@ namespace Demo.Editor
ToolFile helperHeaderDir = new ToolFile(PersistentHelperPath);
if (helperHeaderDir.Exists() == false)
{
ProjectCreateHelper.CreateHelperFiles(helperHeaderDir, CurrentProjectDefaultFileStyle);
//ProjectCreateHelper.CreateHelperFiles(helperHeaderDir);
}
// Reset

View File

@@ -1,197 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Convention;
using UnityEngine;
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");
stream.Write($"'''\n{description}\n'''\n...\n\n");
}
private static void WriteCPPClassBase(StreamWriter stream, Type currentType)
{
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 this");
// <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 = 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>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(@"
/*
<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.WriteLine($"struct {currentTypeName}:public {baseTypeName}");
stream.WriteLine("{");
}
}
private static void WriteCPPStyleFunction(StreamWriter stream, string name, IEnumerable<string> paramList, string description)
{
if (name == nameof(ScriptableObject.LoadSubScript))
{
stream.Write("/*\n" + description + "\n*/\n");
stream.Write($"#define {name}({string.Join(',', paramList)}) __build_in_pragma include {paramList.ToArray()[1]}\n\n");
//stream.Write($"#define {name}({string.Join(',', paramList)})\n\n");
}
else
{
stream.Write("/*\n" + description + "\n*/\n");
stream.Write($"#define {name}({string.Join(',', paramList)}) \n\n");
}
}
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)
{
throw new InvalidOperationException("Not a directory");
}
toolDir.MustExistsPath();
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in asm.GetTypes())
{
// Functions
if (typeof(ScriptableObject).IsAssignableFrom(type))
{
var scriptCalls = (from info in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
where info is MethodInfo
where info.GetCustomAttribute<ScriptableCallAttribute>(false) != null
select info as MethodInfo).ToList();
var typeName = GetTypename(type);
string fileHeader = $"{typeName}.helper" + style switch
{
ProjectDefaultFileStyle.PY => ",py",
_ => ".h"
};
using var fs = File.AppendText((toolDir | fileHeader).GetFullPath());
switch (style)
{
case ProjectDefaultFileStyle.CPP:
WriteCPPClassBase(fs, type);
break;
case ProjectDefaultFileStyle.PY:
break;
}
foreach (var methodInfo in scriptCalls)
{
var data = methodInfo.GetCustomAttribute<ScriptableCallAttribute>(false);
switch (style)
{
case ProjectDefaultFileStyle.PY:
WritePythonStyleFunction(fs, methodInfo.Name, from param in methodInfo.GetParameters() select param.Name, data.Description);
break;
default:
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)
{
// TODO
}
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 2a9363d15f50a79438995f507e7662a5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: