From 716a23fad2597961d42440b3ff53622983dc26f1 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Tue, 2 Dec 2025 14:25:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=81=E5=B9=B3=E5=8C=96=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Convention | 2 +- Assets/Scripts/Framework/RootObject.cs | 36 +++++++------ Assets/Scripts/Framework/ScriptableObject.cs | 55 +++++++------------- 3 files changed, 40 insertions(+), 53 deletions(-) diff --git a/Assets/Convention b/Assets/Convention index 5cc1d2a..172b2af 160000 --- a/Assets/Convention +++ b/Assets/Convention @@ -1 +1 @@ -Subproject commit 5cc1d2aabcf9169524d8373fb5cf9bb7ff159ade +Subproject commit 172b2af3ea5b89cd359e27babba08a7a3a61b485 diff --git a/Assets/Scripts/Framework/RootObject.cs b/Assets/Scripts/Framework/RootObject.cs index c8310c8..e519877 100644 --- a/Assets/Scripts/Framework/RootObject.cs +++ b/Assets/Scripts/Framework/RootObject.cs @@ -11,7 +11,7 @@ namespace Demo.Game public class RootObject : ScriptableObject { protected override bool IsSelfEnableUpdate => false; - [Content] public List UpdateChilds = new(); + [Content] public Dictionary> UpdateChilds = new(); [Resources] public BasicAudioSystem audioSystem; [Content] public GameController RootGameController; @@ -85,24 +85,30 @@ namespace Demo.Game { if (RootGameController.IsMain) { - if (RootGameController.IsAutoPlay) - return; - if (RootGameController.MainAudio.IsPlaying() == false) - return; - // 更新缓存时间 - CurrentUpdateTickTimePoint = currentTime; - // 将距离当前更近的输入调整到更靠前的位置 - InputCatch.Sort((x, y) => Mathf.Abs(x.TimePoint - currentTime).CompareTo(y.TimePoint - currentTime)); - if (InputCatch.Count > 50) - InputCatch = InputCatch.GetRange(0, 50); - if (tickType == TickType.Start) + void foo() { - InputCatch.Clear(); + if (RootGameController.IsAutoPlay) + return; + if (RootGameController.MainAudio.IsPlaying() == false) + return; + // 更新缓存时间 + CurrentUpdateTickTimePoint = currentTime; + // 将距离当前更近的输入调整到更靠前的位置 + InputCatch.Sort((x, y) => Mathf.Abs(x.TimePoint - currentTime).CompareTo(y.TimePoint - currentTime)); + if (InputCatch.Count > 50) + InputCatch = InputCatch.GetRange(0, 50); + if (tickType == TickType.Start) + { + InputCatch.Clear(); + } } + foo(); } - foreach (var item in UpdateChilds) + foreach (var (type, items) in UpdateChilds) { - item.ScriptUpdate(currentTime, deltaTime, tickType); + using (Profiler.BeginZone($"{type.Name}.ScriptUpdate")) + foreach (var item in items) + item.ScriptUpdate(currentTime, deltaTime, tickType); } } } diff --git a/Assets/Scripts/Framework/ScriptableObject.cs b/Assets/Scripts/Framework/ScriptableObject.cs index 6c854b4..39999cc 100644 --- a/Assets/Scripts/Framework/ScriptableObject.cs +++ b/Assets/Scripts/Framework/ScriptableObject.cs @@ -531,51 +531,27 @@ namespace Demo Update } - private string s_ScriptUpdateZoneName = null; - private string s_UpdateTicksZoneName = null; - public string ScriptUpdateZoneName - { - get - { - if (s_ScriptUpdateZoneName == null) - s_ScriptUpdateZoneName = $"{m_ScriptType}.ScriptUpdate"; - return s_ScriptUpdateZoneName; - } - } - public string UpdateTicksZoneName - { - get - { - if (s_UpdateTicksZoneName == null) - s_UpdateTicksZoneName = $"{m_ScriptType}.UpdateTicks"; - return s_UpdateTicksZoneName; - } - } - [Content, SerializeField] private int ScriptUpdateCounter = 0; public void ScriptUpdate(float currentTime, float deltaTime, TickType tickType) { if (IsScriptApply == false) return; - using (Profiler.BeginZone(ScriptUpdateZoneName)) + if (tickType == TickType.Reset) { - if (tickType == TickType.Reset) + ResetEnterGameStatus(); + foreach (var child in Childs) { - ResetEnterGameStatus(); - foreach (var child in Childs) - { - child.ScriptUpdate(currentTime, deltaTime, tickType); - } - } - else - { - // UpdateTicks - if (ScriptUpdateCounter % UpdatePerFrame == 0) - UpdateTicks(currentTime, deltaTime, tickType); - ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0; + child.ScriptUpdate(currentTime, deltaTime, tickType); } } + else + { + // UpdateTicks + if (ScriptUpdateCounter % UpdatePerFrame == 0) + UpdateTicks(currentTime, deltaTime, tickType); + ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0; + } } protected virtual void UpdateTicks(float currentTime, float deltaTime, TickType tickType) @@ -637,7 +613,13 @@ namespace Demo // 统计更新能力 { if (this.IsSelfEnableUpdate) - GetRoot().UpdateChilds.Add(this); + { + var type = this.GetType(); + if (GetRoot().UpdateChilds.TryGetValue(type, out var scriptables)) + scriptables.Add(this); + else + GetRoot().UpdateChilds[type] = new() { this }; + } } IsScriptApply = true; } @@ -862,7 +844,6 @@ namespace Demo { base.UpdateTicks(currentTime, deltaTime, tickType); // 存在严重的性能开销, 在解决之前将不会允许其快速自动更新 - using (Profiler.BeginZone($"{nameof(TimelineScriptObject)}.{nameof(MyTimelineItem.ResizeOnTimeline)}")) { if (UIResizeOnTimelineCount > 0.1 || tickType != TickType.Update) {