新增动态性能优化的开关
This commit is contained in:
@@ -203,7 +203,8 @@ namespace Demo
|
||||
public string ScriptName = "";
|
||||
|
||||
public ScriptableObject Parent;
|
||||
public List<ScriptableObject> Childs = new();
|
||||
public readonly List<ScriptableObject> Childs = new();
|
||||
public readonly List<ScriptableObject> UpdateChilds = new();
|
||||
|
||||
/// <summary>
|
||||
/// 获取根脚本对象
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user