扁平化优化更新
This commit is contained in:
Submodule Assets/Convention updated: 5cc1d2aabc...172b2af3ea
@@ -11,7 +11,7 @@ namespace Demo.Game
|
|||||||
public class RootObject : ScriptableObject
|
public class RootObject : ScriptableObject
|
||||||
{
|
{
|
||||||
protected override bool IsSelfEnableUpdate => false;
|
protected override bool IsSelfEnableUpdate => false;
|
||||||
[Content] public List<ScriptableObject> UpdateChilds = new();
|
[Content] public Dictionary<Type, List<ScriptableObject>> UpdateChilds = new();
|
||||||
[Resources] public BasicAudioSystem audioSystem;
|
[Resources] public BasicAudioSystem audioSystem;
|
||||||
|
|
||||||
[Content] public GameController RootGameController;
|
[Content] public GameController RootGameController;
|
||||||
@@ -84,6 +84,8 @@ namespace Demo.Game
|
|||||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||||
{
|
{
|
||||||
if (RootGameController.IsMain)
|
if (RootGameController.IsMain)
|
||||||
|
{
|
||||||
|
void foo()
|
||||||
{
|
{
|
||||||
if (RootGameController.IsAutoPlay)
|
if (RootGameController.IsAutoPlay)
|
||||||
return;
|
return;
|
||||||
@@ -100,8 +102,12 @@ namespace Demo.Game
|
|||||||
InputCatch.Clear();
|
InputCatch.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var item in UpdateChilds)
|
foo();
|
||||||
|
}
|
||||||
|
foreach (var (type, items) in UpdateChilds)
|
||||||
{
|
{
|
||||||
|
using (Profiler.BeginZone($"{type.Name}.ScriptUpdate"))
|
||||||
|
foreach (var item in items)
|
||||||
item.ScriptUpdate(currentTime, deltaTime, tickType);
|
item.ScriptUpdate(currentTime, deltaTime, tickType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -531,35 +531,12 @@ namespace Demo
|
|||||||
Update
|
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;
|
[Content, SerializeField] private int ScriptUpdateCounter = 0;
|
||||||
public void ScriptUpdate(float currentTime, float deltaTime, TickType tickType)
|
public void ScriptUpdate(float currentTime, float deltaTime, TickType tickType)
|
||||||
{
|
{
|
||||||
if (IsScriptApply == false)
|
if (IsScriptApply == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
using (Profiler.BeginZone(ScriptUpdateZoneName))
|
|
||||||
{
|
|
||||||
if (tickType == TickType.Reset)
|
if (tickType == TickType.Reset)
|
||||||
{
|
{
|
||||||
ResetEnterGameStatus();
|
ResetEnterGameStatus();
|
||||||
@@ -576,7 +553,6 @@ namespace Demo
|
|||||||
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
protected virtual void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||||
{
|
{
|
||||||
@@ -637,7 +613,13 @@ namespace Demo
|
|||||||
// 统计更新能力
|
// 统计更新能力
|
||||||
{
|
{
|
||||||
if (this.IsSelfEnableUpdate)
|
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;
|
IsScriptApply = true;
|
||||||
}
|
}
|
||||||
@@ -862,7 +844,6 @@ namespace Demo
|
|||||||
{
|
{
|
||||||
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)
|
if (UIResizeOnTimelineCount > 0.1 || tickType != TickType.Update)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user