一些性能优化
This commit is contained in:
@@ -100,7 +100,8 @@ namespace Demo
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class ScriptableObject
|
public partial class ScriptableObject
|
||||||
{
|
{
|
||||||
[Content, SerializeField] private Vector3
|
[Content, SerializeField]
|
||||||
|
private Vector3
|
||||||
EnterGameLocalPosition = Vector3.zero,
|
EnterGameLocalPosition = Vector3.zero,
|
||||||
EnterGameEulerAngles = Vector3.zero,
|
EnterGameEulerAngles = Vector3.zero,
|
||||||
EnterGameLocalScaling = Vector3.one;
|
EnterGameLocalScaling = Vector3.one;
|
||||||
@@ -549,6 +550,7 @@ namespace Demo
|
|||||||
if (this.IsSelfEnableUpdate && UpdatePerFrame > 0)
|
if (this.IsSelfEnableUpdate && UpdatePerFrame > 0)
|
||||||
{
|
{
|
||||||
if (ScriptUpdateCounter % UpdatePerFrame == 0)
|
if (ScriptUpdateCounter % UpdatePerFrame == 0)
|
||||||
|
using (Profiler.BeginZone($"{this.ScriptName}.UpdateTicks"))
|
||||||
UpdateTicks(currentTime, deltaTime, tickType);
|
UpdateTicks(currentTime, deltaTime, tickType);
|
||||||
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
||||||
}
|
}
|
||||||
@@ -628,6 +630,15 @@ namespace Demo
|
|||||||
}
|
}
|
||||||
if (IsEnableUpdate == false && Parent != null)
|
if (IsEnableUpdate == false && Parent != null)
|
||||||
Parent.UpdateChilds.Remove(this);
|
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;
|
IsScriptApply = true;
|
||||||
}
|
}
|
||||||
@@ -830,7 +841,7 @@ namespace Demo
|
|||||||
{
|
{
|
||||||
yield return base.UnloadScript();
|
yield return base.UnloadScript();
|
||||||
// 这里的两处判空是因为如果抛出错误就会打断了逻辑, 所以这里需要判断
|
// 这里的两处判空是因为如果抛出错误就会打断了逻辑, 所以这里需要判断
|
||||||
if (MyTimelineItem)
|
if (MyTimelineItem != null)
|
||||||
{
|
{
|
||||||
MyTimelineItem.RawButton.onClick.RemoveAllListeners();
|
MyTimelineItem.RawButton.onClick.RemoveAllListeners();
|
||||||
MyTimelineItem = null;
|
MyTimelineItem = null;
|
||||||
@@ -847,12 +858,20 @@ namespace Demo
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float UIResizeOnTimelineCount = 0;
|
||||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||||
{
|
{
|
||||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||||
|
// 存在严重的性能开销, 在解决之前将不会允许其快速自动更新
|
||||||
|
using (Profiler.BeginZone($"{nameof(TimelineScriptObject)}.{nameof(MyTimelineItem.ResizeOnTimeline)}"))
|
||||||
{
|
{
|
||||||
|
if (UIResizeOnTimelineCount > 0.1 || tickType != TickType.Update)
|
||||||
|
{
|
||||||
|
UIResizeOnTimelineCount = 0;
|
||||||
MyTimelineItem.ResizeOnTimeline();
|
MyTimelineItem.ResizeOnTimeline();
|
||||||
}
|
}
|
||||||
|
UIResizeOnTimelineCount += deltaTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void SetupTimelineItem(Editor.UI.TimelineItem item);
|
protected abstract void SetupTimelineItem(Editor.UI.TimelineItem item);
|
||||||
|
|||||||
Reference in New Issue
Block a user