From e06f01e0f105eb0c46fba5316d9550841c0555d5 Mon Sep 17 00:00:00 2001
From: ninemine <1371605831@qq.com>
Date: Sun, 30 Nov 2025 23:12:39 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E7=A1=AE=E8=AE=A4=E9=97=AE=E9=A2=98?=
=?UTF-8?q?=E5=AD=98=E5=9C=A8=E4=BA=8Ethis.Apply=E7=9A=84=E9=9D=9E?=
=?UTF-8?q?=E6=B3=95=E6=93=8D=E4=BD=9C,=20=E8=AF=A5=E8=AF=AD=E5=8F=A5?=
=?UTF-8?q?=E4=B8=8D=E5=8F=AF=E8=BF=90=E8=A1=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Assets/Scripts/Framework/ScriptableObject.cs | 69 ++++++++++++--------
1 file changed, 43 insertions(+), 26 deletions(-)
diff --git a/Assets/Scripts/Framework/ScriptableObject.cs b/Assets/Scripts/Framework/ScriptableObject.cs
index 3bbb336..6802e4d 100644
--- a/Assets/Scripts/Framework/ScriptableObject.cs
+++ b/Assets/Scripts/Framework/ScriptableObject.cs
@@ -468,7 +468,7 @@ namespace Demo
public class ConsoleTool
{
- GameObject gameObject;
+ private GameObject gameObject;
public ConsoleTool(GameObject gameObject)
{
this.gameObject = gameObject;
@@ -476,39 +476,44 @@ namespace Demo
public void Log(object obj)
{
- Debug.Log(obj);
+ Debug.Log(obj, gameObject);
}
}
public IEnumerator ParseScript2Expr(string script)
{
IsParseScript2Expr = true;
- RScriptEngine engine = new();
- RScriptImportClass importClass = new()
+ try
{
- typeof(Mathf),
- typeof(RandomTool),
- };
- RScriptVariables variables = new()
- {
- { "this", new() { data = this, type = this.GetType() } },
- { "self", new() { data = this, type = this.GetType() } },
- { "console", new() { data = new ConsoleTool(gameObject), type = typeof(ConsoleTool) } },
- { nameof(MathExtension.EaseCurveType), new() { data = PrivateType.EaseCurveTypeInstance.instance, type = typeof(PrivateType.EaseCurveTypeInstance) } },
- { $"Spline{nameof(SplineComputer.SampleMode)}",
- new() { data = PrivateType.SplineComputerSampleModeInstance.instance, type = typeof(PrivateType.SplineComputerSampleModeInstance)} },
- { $"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)} }
- };
+ RScriptEngine engine = new();
+ RScriptImportClass importClass = new()
+ {
+ typeof(Mathf),
+ typeof(RandomTool),
+ };
+ RScriptVariables variables = new()
+ {
+ { "this", new() { data = this, type = this.GetType() } },
+ { "self", new() { data = this, type = this.GetType() } },
+ { "console", new() { data = new ConsoleTool(gameObject), type = typeof(ConsoleTool) } },
+ { nameof(MathExtension.EaseCurveType), new() { data = PrivateType.EaseCurveTypeInstance.instance, type = typeof(PrivateType.EaseCurveTypeInstance) } },
+ { $"Spline{nameof(SplineComputer.SampleMode)}",
+ new() { data = PrivateType.SplineComputerSampleModeInstance.instance, type = typeof(PrivateType.SplineComputerSampleModeInstance)} },
+ { $"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())
- {
- // using var _curr_sen = Profiler.BeginZone(engine.context.CurrentSentence.content);
- yield return ir;
+ foreach (var ir in engine.RunAsync(script, importClass, variables).Yield())
+ {
+ yield return ir;
+ }
+ }
+ finally
+ {
+ IsParseScript2Expr = false;
}
- IsParseScript2Expr = false;
}
public enum TickType
@@ -576,12 +581,24 @@ namespace Demo
{
protected virtual IEnumerator DoSomethingDuringApplyScript()
{
- yield break;
+ return null;
}
[Content]
public bool IsScriptApply { get; private set; } = false;
+ ///
+ /// 确认脚本已经完全执行完成, 允许其进入工作阶段
+ /// 注意不要使用this.ApplyScript, 将会导致
+ ///
+ /// while (this.IsParseScript2Expr)
+ /// {
+ /// yield return null;
+ /// }
+ ///
+ /// 永远等待
+ ///
+ ///
[Convention.RScript.Variable.Attr.Method]
public IEnumerator ApplyScript()
{