正在为RScript更新内容(已通过编译)
This commit is contained in:
@@ -17,257 +17,8 @@ using UnityEngine;
|
||||
|
||||
namespace Demo
|
||||
{
|
||||
public enum ProjectDefaultFileStyle
|
||||
public static class ScriptUtility
|
||||
{
|
||||
CPP,
|
||||
PY
|
||||
}
|
||||
|
||||
[System.AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
|
||||
public sealed class ScriptableCallAttribute : Attribute
|
||||
{
|
||||
public string Description;
|
||||
public ScriptableCallAttribute(string description)
|
||||
{
|
||||
this.Description = description;
|
||||
}
|
||||
}
|
||||
|
||||
[System.AttributeUsage(AttributeTargets.Enum, Inherited = true, AllowMultiple = false)]
|
||||
public sealed class ScriptableEnumAttribute : Attribute
|
||||
{
|
||||
public string Description;
|
||||
public ScriptableEnumAttribute(string description)
|
||||
{
|
||||
this.Description = description;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ScriptCallUtility
|
||||
{
|
||||
// 解析函数调用的方法,支持 with 子句
|
||||
public static (string functionName, string[] arguments, Dictionary<string, string> withVariables) ParseFunctionCall(string input)
|
||||
{
|
||||
// 匹配函数名和参数部分,以及可选的 with 子句
|
||||
Match match = Regex.Match(input, @"^(\w+)\s*\(\s*(.*?)\s*\)\s*(?:\s+with\s*\(\s*(.*?)\s*\))?\s*;?$");
|
||||
|
||||
if (!match.Success)
|
||||
return (null, new string[0], new Dictionary<string, string>());
|
||||
|
||||
string functionName = match.Groups[1].Value;
|
||||
string argumentsString = match.Groups[2].Value;
|
||||
string withString = match.Groups[3].Value;
|
||||
|
||||
// 解析参数数组
|
||||
string[] arguments = ParseArguments(argumentsString);
|
||||
|
||||
// 解析 with 子句的变量
|
||||
Dictionary<string, string> withVariables = new Dictionary<string, string>();
|
||||
if (!string.IsNullOrWhiteSpace(withString))
|
||||
{
|
||||
withVariables = ParseWithClause(withString);
|
||||
}
|
||||
|
||||
return (functionName, arguments, withVariables);
|
||||
}
|
||||
|
||||
// 解析 with 子句的方法
|
||||
private static Dictionary<string, string> ParseWithClause(string withString)
|
||||
{
|
||||
var variables = new Dictionary<string, string>();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(withString))
|
||||
return variables;
|
||||
|
||||
int i = 0;
|
||||
while (i < withString.Length)
|
||||
{
|
||||
// 跳过空白字符
|
||||
while (i < withString.Length && char.IsWhiteSpace(withString[i]))
|
||||
i++;
|
||||
|
||||
if (i >= withString.Length)
|
||||
break;
|
||||
|
||||
// 解析变量名
|
||||
int nameStart = i;
|
||||
while (i < withString.Length && (char.IsLetterOrDigit(withString[i]) || withString[i] == '_'))
|
||||
i++;
|
||||
|
||||
if (i == nameStart)
|
||||
break; // 没有找到有效的变量名
|
||||
|
||||
string varName = withString.Substring(nameStart, i - nameStart);
|
||||
|
||||
// 跳过空白字符
|
||||
while (i < withString.Length && char.IsWhiteSpace(withString[i]))
|
||||
i++;
|
||||
|
||||
// 检查等号
|
||||
if (i >= withString.Length || withString[i] != '=')
|
||||
break; // 没有找到等号
|
||||
i++; // 跳过等号
|
||||
|
||||
// 跳过空白字符
|
||||
while (i < withString.Length && char.IsWhiteSpace(withString[i]))
|
||||
i++;
|
||||
|
||||
// 解析变量值
|
||||
string varValue = ExtractArgument(withString, ref i);
|
||||
variables[varName] = varValue.Trim();
|
||||
|
||||
// 跳过空白字符
|
||||
while (i < withString.Length && char.IsWhiteSpace(withString[i]))
|
||||
i++;
|
||||
|
||||
// 检查逗号
|
||||
if (i < withString.Length && withString[i] == ',')
|
||||
{
|
||||
i++; // 跳过逗号
|
||||
}
|
||||
else if (i < withString.Length)
|
||||
{
|
||||
break; // 期望逗号但找到了其他字符
|
||||
}
|
||||
}
|
||||
|
||||
return variables;
|
||||
}
|
||||
|
||||
// 解析参数的方法
|
||||
private static string[] ParseArguments(string argumentsString)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(argumentsString))
|
||||
return new string[0];
|
||||
|
||||
var arguments = new List<string>();
|
||||
int i = 0;
|
||||
|
||||
while (i < argumentsString.Length)
|
||||
{
|
||||
// 跳过空白字符
|
||||
while (i < argumentsString.Length && char.IsWhiteSpace(argumentsString[i]))
|
||||
i++;
|
||||
|
||||
// 越界检查
|
||||
if (i >= argumentsString.Length)
|
||||
break;
|
||||
|
||||
string argument = ExtractArgument(argumentsString, ref i);
|
||||
if (!string.IsNullOrEmpty(argument))
|
||||
arguments.Add(argument.Trim());
|
||||
|
||||
// 跳过空白字符
|
||||
while (i < argumentsString.Length && char.IsWhiteSpace(argumentsString[i]))
|
||||
i++;
|
||||
|
||||
// 越界检查
|
||||
if (i >= argumentsString.Length)
|
||||
break;
|
||||
|
||||
// 必定是逗号, 否则异常情况
|
||||
if (argumentsString[i] != ',')
|
||||
throw new InvalidOperationException("Parser is invalid logic");
|
||||
i++;
|
||||
}
|
||||
|
||||
return arguments.ToArray();
|
||||
}
|
||||
|
||||
// 提取单个参数的方法,支持花括号和字符串字面量
|
||||
private static string ExtractArgument(string input, ref int index)
|
||||
{
|
||||
int start = index;
|
||||
|
||||
if (input[index] == '"')
|
||||
{
|
||||
// 处理字符串字面量
|
||||
index++; // 跳过开始的引号
|
||||
while (index < input.Length)
|
||||
{
|
||||
if (input[index] == '"' && (index == 0 || input[index - 1] != '\\'))
|
||||
{
|
||||
index++; // 跳过结束的引号
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
else if (input[index] == '{')
|
||||
{
|
||||
// 处理花括号内的内容
|
||||
int braceCount = 0;
|
||||
while (index < input.Length)
|
||||
{
|
||||
if (input[index] == '{')
|
||||
braceCount++;
|
||||
else if (input[index] == '}')
|
||||
braceCount--;
|
||||
|
||||
index++;
|
||||
|
||||
if (braceCount == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理普通参数(直到遇到逗号)
|
||||
while (index < input.Length && input[index] != ',')
|
||||
index++;
|
||||
}
|
||||
|
||||
return input[start..index];
|
||||
}
|
||||
}
|
||||
|
||||
[System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class DefaultScriptAttribute : Attribute
|
||||
{
|
||||
public string DefaultScript;
|
||||
public DefaultScriptAttribute(string script)
|
||||
{
|
||||
this.DefaultScript = script;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DefaultScriptUtility
|
||||
{
|
||||
public static void WriteStyleMethodHelper(StreamWriter stream,MethodInfo methodInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void WriteDefaultScript(StreamWriter fs, Type type)
|
||||
{
|
||||
if (typeof(ScriptableObject).IsAssignableFrom(type) == false)
|
||||
throw new InvalidOperationException($"{type.FullName} is not inherited from {typeof(ScriptableObject).FullName}");
|
||||
var attr = type.GetCustomAttribute<DefaultScriptAttribute>();
|
||||
var typeName = type.Name;
|
||||
if (typeName.Contains('`'))
|
||||
{
|
||||
typeName = typeName[..typeName.LastIndexOf('`')];
|
||||
}
|
||||
switch (Editor.EditorController.instance.MainGameController.CurrentProjectDefaultFileStyle)
|
||||
{
|
||||
case ProjectDefaultFileStyle.CPP:
|
||||
{
|
||||
fs.WriteLine($"#include \"{typeName}.helper.h\"");
|
||||
if (attr != null)
|
||||
{
|
||||
var text = attr.DefaultScript;
|
||||
fs.Write(text);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ProjectDefaultFileStyle.PY:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenScriptFile(ScriptableObject so)
|
||||
{
|
||||
string path = so.ScriptPath;
|
||||
@@ -312,14 +63,7 @@ namespace Demo
|
||||
/// <param name="id">时间线ID,若不存在则创建</param>
|
||||
/// <param name="delta">当每次调用NextTimePoint函数时使用的单位值</param>
|
||||
/// <param name="value">初始化时间</param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
重设指定时间线
|
||||
</summary>
|
||||
<param name=""id"">时间线ID,若不存在则创建</param>
|
||||
<param name=""delta"">当每次调用NextTimePoint函数时使用的单位值</param>
|
||||
<param name=""value"">初始化时间</param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void ResetTimePoint(string id, string delta, string value)
|
||||
{
|
||||
TimePointDelta[id] = float.Parse(delta);
|
||||
@@ -331,13 +75,7 @@ namespace Demo
|
||||
/// </summary>
|
||||
/// <param name="id">时间线ID</param>
|
||||
/// <param name="times">前进次数,最终时间的增量为前进次数乘该时间线的单位值</param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
推动时间线前进
|
||||
</summary>
|
||||
<param name=""id"">时间线ID</param>
|
||||
<param name=""times"">前进次数,最终时间的增量为前进次数乘该时间线的单位值</param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void NextTimePoint(string id, string times)
|
||||
{
|
||||
TimePoints[id] += TimePointDelta[id] * float.Parse(times);
|
||||
@@ -348,13 +86,7 @@ namespace Demo
|
||||
/// </summary>
|
||||
/// <param name="id">时间线ID</param>
|
||||
/// <param name="value">次数,时间线的值将被设置为次数乘该时间线的单位值</param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
设置时间线的值
|
||||
</summary>
|
||||
<param name=""id"">时间线ID</param>
|
||||
<param name=""value"">次数,时间线的值将被设置为次数乘该时间线的单位值</param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetTimePoint(string id, string value)
|
||||
{
|
||||
TimePoints[id] = TimePointDelta[id] * float.Parse(value);
|
||||
@@ -397,13 +129,7 @@ namespace Demo
|
||||
/// </summary>
|
||||
/// <param name="name">字符串</param>
|
||||
/// <param name="value">浮点数</param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
设置局部上下文变量,将会传递给子物体使用
|
||||
</summary>
|
||||
<param name=""name"">字符串</param>
|
||||
<param name=""value"">浮点数</param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetContext(string name, string value)
|
||||
{
|
||||
ScriptContextSpace[name] = Parse(value);
|
||||
@@ -440,18 +166,7 @@ namespace Demo
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
从字符串解析为浮点数
|
||||
从时间点列表中获取
|
||||
或是从上下文变量中获取
|
||||
或是从数据驱动对象中获取
|
||||
或是通过计算表达式值获取
|
||||
或是直接调用float.Parse(string)
|
||||
</summary>
|
||||
<param name=""value""></param>
|
||||
<returns></returns>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public float Parse(string value)
|
||||
{
|
||||
value = value.Trim();
|
||||
@@ -535,14 +250,7 @@ namespace Demo
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="z"></param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
设置坐标
|
||||
</summary>
|
||||
<param name=""result""></param>
|
||||
<param name=""y""></param>
|
||||
<param name=""z""></param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetLocalPosition(string x, string y, string z)
|
||||
{
|
||||
EnterGameLocalPosition = new(Parse(x), Parse(y), Parse(z));
|
||||
@@ -553,14 +261,7 @@ namespace Demo
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="z"></param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
设置欧拉角
|
||||
</summary>
|
||||
<param name=""result""></param>
|
||||
<param name=""y""></param>
|
||||
<param name=""z""></param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetLocalEulerAngles(string x, string y, string z)
|
||||
{
|
||||
EnterGameEulerAngles = new(Parse(x), Parse(y), Parse(z));
|
||||
@@ -571,14 +272,7 @@ namespace Demo
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="z"></param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
设置缩放
|
||||
</summary>
|
||||
<param name=""result""></param>
|
||||
<param name=""y""></param>
|
||||
<param name=""z""></param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetLocalScaling(string x, string y, string z)
|
||||
{
|
||||
EnterGameLocalScaling = new(Parse(x), Parse(y), Parse(z));
|
||||
@@ -588,12 +282,7 @@ namespace Demo
|
||||
/// 关闭该物体,
|
||||
/// 在面对如多Game场景时关闭某些GameWorld中默认存在的全局灯光等场景时非常有用
|
||||
/// </summary>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
关闭该物体,
|
||||
在面对如多Game场景时关闭某些GameWorld中默认存在的全局灯光等场景时非常有用
|
||||
</summary>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetObjectDisable()
|
||||
{
|
||||
IsSetObjectDisable = true;
|
||||
@@ -623,13 +312,7 @@ namespace Demo
|
||||
/// 属于性能优化的高级选项
|
||||
/// </summary>
|
||||
/// <param name="frame">每frame帧更新一次, 等于0代表不会在<see cref="TickType.Update"/>状态运行</param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
指定多少个Update状态的UpdateTicks执行一次更新,不会影响到子物体
|
||||
属于性能优化的高级选项
|
||||
</summary>
|
||||
<param name=""frame"">每frame帧更新一次, 等于0代表不会在Update状态运行</param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetUpdatePerFrame(string frame)
|
||||
{
|
||||
UpdatePerFrame = Mathf.Max(1, int.Parse(frame));
|
||||
@@ -763,13 +446,7 @@ namespace Demo
|
||||
/// </summary>
|
||||
/// <param name="type">指定类型</param>
|
||||
/// <param name="path">指定脚本,可用决定路径或与当前脚本目录的相对路径</param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
加载子脚本
|
||||
</summary>
|
||||
<param name=""type"">指定类型</param>
|
||||
<param name=""path"">指定脚本,可用决定路径或与当前脚本目录的相对路径</param>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public IEnumerator LoadSubScript([In] string type, [In] string path)
|
||||
{
|
||||
return DoLoadSubScriptAsync(type, path, null);
|
||||
@@ -779,12 +456,7 @@ namespace Demo
|
||||
/// 获取已加载的脚本对象
|
||||
/// </summary>
|
||||
/// <returns>无法找到时将返回空</returns>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
获取已加载的脚本对象
|
||||
</summary>
|
||||
<returns>无法找到时将返回空</returns>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public ScriptableObject GetLoadedObject(string path)
|
||||
{
|
||||
return FindWithPath(path, false);
|
||||
@@ -794,12 +466,7 @@ namespace Demo
|
||||
/// 获取父脚本对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
获取父脚本对象
|
||||
</summary>
|
||||
<returns></returns>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public ScriptableObject GetParentObject()
|
||||
{
|
||||
return Parent;
|
||||
@@ -809,36 +476,12 @@ namespace Demo
|
||||
/// 获取上一个加载的脚本对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
获取上一个加载的脚本对象
|
||||
</summary>
|
||||
<returns></returns>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public ScriptableObject GetLastLoadedScriptableObject()
|
||||
{
|
||||
return LastLoadedScriptableObject;
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 异步加载子脚本
|
||||
/// </summary>
|
||||
/// <param name="type">指定类型</param>
|
||||
/// <param name="path">指定脚本,可用决定路径或与当前脚本目录的相对路径</param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
异步加载子脚本
|
||||
</summary>
|
||||
<param name=""type"">指定类型</param>
|
||||
<param name=""path"">指定脚本,可用决定路径或与当前脚本目录的相对路径</param>
|
||||
")]
|
||||
public void LoadSubScriptAsync([In] string type, [In] string path)
|
||||
{
|
||||
StartCoroutine(DoLoadSubScriptAsync(type, path, null));
|
||||
}
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
private IEnumerator ParseScript2Expr(string script)
|
||||
@@ -922,12 +565,7 @@ namespace Demo
|
||||
/// 获取根脚本对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
获取根脚本对象
|
||||
</summary>
|
||||
<returns></returns>
|
||||
")]
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public RootObject GetRoot()
|
||||
{
|
||||
if (Parent == null)
|
||||
@@ -1220,19 +858,12 @@ namespace Demo
|
||||
// 暂时的逻辑是总是展示的
|
||||
{
|
||||
TimelineScriptObjectWhichOnShow.Add(this);
|
||||
//IsTimelineItemShow = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnHierarchyItemClick(HierarchyItem item)
|
||||
{
|
||||
//foreach (var tso in TimelineScriptObjectWhichOnShow)
|
||||
//{
|
||||
// tso.IsTimelineItemShow = false;
|
||||
// tso.MyTimelineItem.RawButton.gameObject.SetActive(false);
|
||||
//}
|
||||
//TimelineScriptObjectWhichOnShow.Clear();
|
||||
//ShowTimelineItemWithChilds();
|
||||
|
||||
}
|
||||
|
||||
//protected virtual void ShowTimelineItemWithChilds()
|
||||
@@ -1255,10 +886,9 @@ namespace Demo
|
||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
{
|
||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||
//if (IsTimelineItemShow)
|
||||
//{
|
||||
{
|
||||
MyTimelineItem.ResizeOnTimeline();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void SetupTimelineItem(Editor.UI.TimelineItem item);
|
||||
|
||||
Reference in New Issue
Block a user