已确认问题存在于this.Apply的非法操作, 该语句不可运行

This commit is contained in:
2025-11-30 23:12:39 +08:00
parent 430209c948
commit e06f01e0f1

View File

@@ -468,7 +468,7 @@ namespace Demo
public class ConsoleTool public class ConsoleTool
{ {
GameObject gameObject; private GameObject gameObject;
public ConsoleTool(GameObject gameObject) public ConsoleTool(GameObject gameObject)
{ {
this.gameObject = gameObject; this.gameObject = gameObject;
@@ -476,39 +476,44 @@ namespace Demo
public void Log(object obj) public void Log(object obj)
{ {
Debug.Log(obj); Debug.Log(obj, gameObject);
} }
} }
public IEnumerator ParseScript2Expr(string script) public IEnumerator ParseScript2Expr(string script)
{ {
IsParseScript2Expr = true; IsParseScript2Expr = true;
RScriptEngine engine = new(); try
RScriptImportClass importClass = new()
{ {
typeof(Mathf), RScriptEngine engine = new();
typeof(RandomTool), RScriptImportClass importClass = new()
}; {
RScriptVariables variables = new() typeof(Mathf),
{ typeof(RandomTool),
{ "this", new() { data = this, type = this.GetType() } }, };
{ "self", new() { data = this, type = this.GetType() } }, RScriptVariables variables = new()
{ "console", new() { data = new ConsoleTool(gameObject), type = typeof(ConsoleTool) } }, {
{ nameof(MathExtension.EaseCurveType), new() { data = PrivateType.EaseCurveTypeInstance.instance, type = typeof(PrivateType.EaseCurveTypeInstance) } }, { "this", new() { data = this, type = this.GetType() } },
{ $"Spline{nameof(SplineComputer.SampleMode)}", { "self", new() { data = this, type = this.GetType() } },
new() { data = PrivateType.SplineComputerSampleModeInstance.instance, type = typeof(PrivateType.SplineComputerSampleModeInstance)} }, { "console", new() { data = new ConsoleTool(gameObject), type = typeof(ConsoleTool) } },
{ $"Spline{nameof(Spline.Type)}", { nameof(MathExtension.EaseCurveType), new() { data = PrivateType.EaseCurveTypeInstance.instance, type = typeof(PrivateType.EaseCurveTypeInstance) } },
new() { data = PrivateType.SplineTypeInstance.instance, type = typeof(PrivateType.SplineTypeInstance)} }, { $"Spline{nameof(SplineComputer.SampleMode)}",
{ nameof(IEffectHookObject.InteractiveEffectType), new() { data = PrivateType.SplineComputerSampleModeInstance.instance, type = typeof(PrivateType.SplineComputerSampleModeInstance)} },
new() { data = PrivateType.IEffectHookObjectInstance.instance, type = typeof(PrivateType.IEffectHookObjectInstance)} } { $"Spline{nameof(Spline.Type)}",
}; new() { data = PrivateType.SplineTypeInstance.instance, type = typeof(PrivateType.SplineTypeInstance)} },
{ nameof(IEffectHookObject.InteractiveEffectType),
new() { data = PrivateType.IEffectHookObjectInstance.instance, type = typeof(PrivateType.IEffectHookObjectInstance)} }
};
foreach (var ir in engine.RunAsync(script, importClass, variables).Yield()) foreach (var ir in engine.RunAsync(script, importClass, variables).Yield())
{ {
// using var _curr_sen = Profiler.BeginZone(engine.context.CurrentSentence.content); yield return ir;
yield return ir; }
}
finally
{
IsParseScript2Expr = false;
} }
IsParseScript2Expr = false;
} }
public enum TickType public enum TickType
@@ -576,12 +581,24 @@ namespace Demo
{ {
protected virtual IEnumerator DoSomethingDuringApplyScript() protected virtual IEnumerator DoSomethingDuringApplyScript()
{ {
yield break; return null;
} }
[Content] [Content]
public bool IsScriptApply { get; private set; } = false; public bool IsScriptApply { get; private set; } = false;
/// <summary>
/// 确认脚本已经完全执行完成, 允许其进入工作阶段
/// <b>注意不要使用this.ApplyScript</b>, 将会导致
/// <code>
/// while (this.IsParseScript2Expr)
/// {
/// yield return null;
/// }
/// </code>
/// 永远等待
/// </summary>
/// <returns></returns>
[Convention.RScript.Variable.Attr.Method] [Convention.RScript.Variable.Attr.Method]
public IEnumerator ApplyScript() public IEnumerator ApplyScript()
{ {