diff --git a/Assets/Convention b/Assets/Convention index b643949..0b562b7 160000 --- a/Assets/Convention +++ b/Assets/Convention @@ -1 +1 @@ -Subproject commit b6439492df77064707f9a3085b7719e8abe8f3ef +Subproject commit 0b562b7f659d70304e88f6a90771095ee12bd526 diff --git a/Assets/Scripts/Anchor.cs b/Assets/Scripts/Anchor.cs index e55e277..a6f3048 100644 --- a/Assets/Scripts/Anchor.cs +++ b/Assets/Scripts/Anchor.cs @@ -6,6 +6,7 @@ namespace Demo.Game { public class Anchor : ScriptableObject { + protected override bool IsSelfEnableUpdate => false; public static Anchor Make() { var anchor = new GameObject().AddComponent(); diff --git a/Assets/Scripts/Framework/DDT.cs b/Assets/Scripts/Framework/DDT.cs index 7b94914..1ce13fd 100644 --- a/Assets/Scripts/Framework/DDT.cs +++ b/Assets/Scripts/Framework/DDT.cs @@ -8,6 +8,7 @@ namespace Demo.Game { public class DDT : ScriptableObject, IEnumerable { + protected override bool IsSelfEnableUpdate => false; public static DDT Make() { return new GameObject().AddComponent(); diff --git a/Assets/Scripts/Framework/GameContent/GameController.cs b/Assets/Scripts/Framework/GameContent/GameController.cs index 8436a55..9428b27 100644 --- a/Assets/Scripts/Framework/GameContent/GameController.cs +++ b/Assets/Scripts/Framework/GameContent/GameController.cs @@ -222,16 +222,16 @@ namespace Demo.Game rootGameObject.SetContent("SongLength", MainAudio.CurrentClip.length); yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText()); yield return rootGameObject.ApplyScript(); - IEnumerator DFS(ScriptableObject parent) + IEnumerator NDFS(ScriptableObject current) { - foreach (var child in parent.Childs) + foreach (var child in current.Childs) { - if (child.IsScriptApply == false) - yield return child.ApplyScript(); - yield return DFS(child); + yield return NDFS(child); } + if (current.IsScriptApply == false) + yield return current.ApplyScript(); } - yield return DFS(rootGameObject); + yield return NDFS(rootGameObject); } } finally diff --git a/Assets/Scripts/Framework/ScriptableObject.cs b/Assets/Scripts/Framework/ScriptableObject.cs index ba9e279..cc96a7b 100644 --- a/Assets/Scripts/Framework/ScriptableObject.cs +++ b/Assets/Scripts/Framework/ScriptableObject.cs @@ -203,7 +203,8 @@ namespace Demo public string ScriptName = ""; public ScriptableObject Parent; - public List Childs = new(); + public readonly List Childs = new(); + public readonly List UpdateChilds = new(); /// /// 获取根脚本对象 @@ -344,6 +345,8 @@ namespace Demo public static int AllScriptableObjectCounter = 0; public bool IsParseScript2Expr { get; private set; } = false; + protected virtual bool IsSelfEnableUpdate { get => true; } + public bool IsEnableUpdate { get; private set; } = true; #region LoadSubScript @@ -381,6 +384,7 @@ namespace Demo // Add Child Childs.Add(child); + UpdateChilds.Add(child); // Load Child Script ConventionUtility.StartCoroutine(child.ParseScript2Expr(file.LoadAsText())); @@ -413,6 +417,7 @@ namespace Demo // Add Child Childs.Add(child); + UpdateChilds.Add(child); return child; } @@ -495,9 +500,6 @@ namespace Demo IsParseScript2Expr = false; } - [Content] - public bool IsScriptApply { get; private set; } = false; - public enum TickType { Reset, @@ -519,18 +521,26 @@ namespace Demo if (tickType == TickType.Reset) { ResetEnterGameStatus(); + // Childs UpdateTicks + foreach (var child in Childs) + { + child.ScriptUpdate(currentTime, deltaTime, tickType); + } } - // UpdateTicks - if (UpdatePerFrame > 0) + else { - if (ScriptUpdateCounter % UpdatePerFrame == 0) - UpdateTicks(currentTime, deltaTime, tickType); - ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0; - } - // Childs UpdateTicks - foreach (var child in Childs) - { - child.ScriptUpdate(currentTime, deltaTime, tickType); + // UpdateTicks + if (UpdatePerFrame > 0) + { + if (ScriptUpdateCounter % UpdatePerFrame == 0) + UpdateTicks(currentTime, deltaTime, tickType); + ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0; + } + // Childs UpdateTicks + foreach (var child in UpdateChilds) + { + child.ScriptUpdate(currentTime, deltaTime, tickType); + } } } } @@ -558,6 +568,9 @@ namespace Demo yield break; } + [Content] + public bool IsScriptApply { get; private set; } = false; + [Convention.RScript.Variable.Attr.Method] public IEnumerator ApplyScript() { @@ -566,7 +579,7 @@ namespace Demo yield break; } // 等待自身脚本解析完毕 - while(this.IsParseScript2Expr) + while (this.IsParseScript2Expr) { yield return null; } @@ -576,6 +589,18 @@ namespace Demo AllScriptableObjectCounter++; AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}"; } + // 统计更新能力 + { + IsEnableUpdate = this.IsSelfEnableUpdate; + foreach (var child in this.Childs) + { + if (IsEnableUpdate) + break; + IsEnableUpdate |= child.IsEnableUpdate; + } + if (IsEnableUpdate == false && Parent != null) + Parent.UpdateChilds.Remove(this); + } IsScriptApply = true; } diff --git a/Assets/Scripts/MoreSpline/SplineNode.cs b/Assets/Scripts/MoreSpline/SplineNode.cs index a38eae7..22ba294 100644 --- a/Assets/Scripts/MoreSpline/SplineNode.cs +++ b/Assets/Scripts/MoreSpline/SplineNode.cs @@ -6,6 +6,8 @@ namespace Demo.Game { public class SplineNode : ScriptableObject { + protected override bool IsSelfEnableUpdate => false; + public static SplineNode Make() { return new GameObject("", typeof(Node)).AddComponent(); diff --git a/Convention-Unity-Demo.slnx b/Convention-Unity-Demo.slnx new file mode 100644 index 0000000..01b9f81 --- /dev/null +++ b/Convention-Unity-Demo.slnx @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +