新增动态性能优化的开关
This commit is contained in:
Submodule Assets/Convention updated: b6439492df...0b562b7f65
@@ -6,6 +6,7 @@ namespace Demo.Game
|
||||
{
|
||||
public class Anchor : ScriptableObject
|
||||
{
|
||||
protected override bool IsSelfEnableUpdate => false;
|
||||
public static Anchor Make()
|
||||
{
|
||||
var anchor = new GameObject().AddComponent<Anchor>();
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Demo.Game
|
||||
{
|
||||
public class DDT : ScriptableObject, IEnumerable<float>
|
||||
{
|
||||
protected override bool IsSelfEnableUpdate => false;
|
||||
public static DDT Make()
|
||||
{
|
||||
return new GameObject().AddComponent<DDT>();
|
||||
|
||||
@@ -222,16 +222,16 @@ namespace Demo.Game
|
||||
rootGameObject.SetContent("SongLength", MainAudio.CurrentClip.length);
|
||||
yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText());
|
||||
yield return rootGameObject.ApplyScript();
|
||||
IEnumerator DFS(ScriptableObject parent)
|
||||
IEnumerator NDFS(ScriptableObject current)
|
||||
{
|
||||
foreach (var child in parent.Childs)
|
||||
foreach (var child in current.Childs)
|
||||
{
|
||||
if (child.IsScriptApply == false)
|
||||
yield return child.ApplyScript();
|
||||
yield return DFS(child);
|
||||
yield return NDFS(child);
|
||||
}
|
||||
if (current.IsScriptApply == false)
|
||||
yield return current.ApplyScript();
|
||||
}
|
||||
yield return DFS(rootGameObject);
|
||||
yield return NDFS(rootGameObject);
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace Demo.Game
|
||||
{
|
||||
public class SplineNode : ScriptableObject
|
||||
{
|
||||
protected override bool IsSelfEnableUpdate => false;
|
||||
|
||||
public static SplineNode Make()
|
||||
{
|
||||
return new GameObject("", typeof(Node)).AddComponent<SplineNode>();
|
||||
|
||||
15
Convention-Unity-Demo.slnx
Normal file
15
Convention-Unity-Demo.slnx
Normal file
@@ -0,0 +1,15 @@
|
||||
<Solution>
|
||||
<Project Path="Assembly-CSharp.csproj" />
|
||||
<Project Path="Dreamteck.Splines.Editor.csproj" />
|
||||
<Project Path="Dreamteck.Splines.csproj" />
|
||||
<Project Path="EasySave3.csproj" />
|
||||
<Project Path="EasySave3Editor.csproj" />
|
||||
<Project Path="Assembly-CSharp-firstpass.csproj" />
|
||||
<Project Path="Assembly-CSharp-Editor.csproj" />
|
||||
<Project Path="Dreamteck.Utilities.csproj" />
|
||||
<Project Path="com.cqf.urpvolumetricfog.editor.csproj" />
|
||||
<Project Path="Dreamteck.Utilities.Editor.csproj" />
|
||||
<Project Path="com.cqf.urpvolumetricfog.runtime.csproj" />
|
||||
<Project Path="Unity.RenderPipelines.Universal.Config.Editor.Tests.csproj" />
|
||||
<Project Path="Unity.RenderPipelines.Universal.Config.Runtime.csproj" />
|
||||
</Solution>
|
||||
Reference in New Issue
Block a user