From 1b7f1497b10980b3a53c706f0bfee9270c0482e3 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Mon, 1 Dec 2025 00:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=80=A7=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Framework/ScriptableObject.cs | 39 +++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/Framework/ScriptableObject.cs b/Assets/Scripts/Framework/ScriptableObject.cs index 6802e4d..8450dcf 100644 --- a/Assets/Scripts/Framework/ScriptableObject.cs +++ b/Assets/Scripts/Framework/ScriptableObject.cs @@ -100,7 +100,8 @@ namespace Demo /// public partial class ScriptableObject { - [Content, SerializeField] private Vector3 + [Content, SerializeField] + private Vector3 EnterGameLocalPosition = Vector3.zero, EnterGameEulerAngles = Vector3.zero, EnterGameLocalScaling = Vector3.one; @@ -455,12 +456,12 @@ namespace Demo public static class RandomTool { - public static float Random(float min,float max) + public static float Random(float min, float max) { - return UnityEngine.Random.Range(min,max); + return UnityEngine.Random.Range(min, max); } - public static float Random(double min,double max) + public static float Random(double min, double max) { return UnityEngine.Random.Range((float)min, (float)max); } @@ -549,7 +550,8 @@ namespace Demo if (this.IsSelfEnableUpdate && UpdatePerFrame > 0) { if (ScriptUpdateCounter % UpdatePerFrame == 0) - UpdateTicks(currentTime, deltaTime, tickType); + using (Profiler.BeginZone($"{this.ScriptName}.UpdateTicks")) + UpdateTicks(currentTime, deltaTime, tickType); ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0; } // Childs UpdateTicks @@ -628,6 +630,15 @@ namespace Demo } if (IsEnableUpdate == false && Parent != null) Parent.UpdateChilds.Remove(this); + // 当只存在一个需要更新的子物体并且自身不需要更新时, 直接简化调用 + if (this.IsSelfEnableUpdate == false && this.UpdateChilds.Count == 1) + { + Parent.UpdateChilds.Remove(this); + var child = this.UpdateChilds[0]; + this.UpdateChilds.Clear(); + Parent.UpdateChilds.Add(child); + IsEnableUpdate = false; + } } IsScriptApply = true; } @@ -685,7 +696,7 @@ namespace Demo } } -#endregion + #endregion public interface IAssetBundleLoader : IScriptableObject { @@ -804,7 +815,7 @@ namespace Demo protected override IEnumerator DoSomethingDuringApplyScript() { yield return base.DoSomethingDuringApplyScript(); - if(MyTimelineEntry==null) + if (MyTimelineEntry == null) { MyTimelineEntry = TimelineWindow.CreateRootItemEntries(1)[0]; MyTimelineItem = MyTimelineEntry.ref_value.GetComponent(); @@ -830,7 +841,7 @@ namespace Demo { yield return base.UnloadScript(); // 这里的两处判空是因为如果抛出错误就会打断了逻辑, 所以这里需要判断 - if (MyTimelineItem) + if (MyTimelineItem != null) { MyTimelineItem.RawButton.onClick.RemoveAllListeners(); MyTimelineItem = null; @@ -847,11 +858,19 @@ namespace Demo } + private float UIResizeOnTimelineCount = 0; protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType) { base.UpdateTicks(currentTime, deltaTime, tickType); + // 存在严重的性能开销, 在解决之前将不会允许其快速自动更新 + using (Profiler.BeginZone($"{nameof(TimelineScriptObject)}.{nameof(MyTimelineItem.ResizeOnTimeline)}")) { - MyTimelineItem.ResizeOnTimeline(); + if (UIResizeOnTimelineCount > 0.1 || tickType != TickType.Update) + { + UIResizeOnTimelineCount = 0; + MyTimelineItem.ResizeOnTimeline(); + } + UIResizeOnTimelineCount += deltaTime; } } @@ -861,7 +880,7 @@ namespace Demo { static float Foo(uint hash) { - float a= (hash % 10) * 0.1f; + float a = (hash % 10) * 0.1f; return a; }