新增动态性能优化的开关
This commit is contained in:
Submodule Assets/Convention updated: b6439492df...0b562b7f65
@@ -6,6 +6,7 @@ namespace Demo.Game
|
|||||||
{
|
{
|
||||||
public class Anchor : ScriptableObject
|
public class Anchor : ScriptableObject
|
||||||
{
|
{
|
||||||
|
protected override bool IsSelfEnableUpdate => false;
|
||||||
public static Anchor Make()
|
public static Anchor Make()
|
||||||
{
|
{
|
||||||
var anchor = new GameObject().AddComponent<Anchor>();
|
var anchor = new GameObject().AddComponent<Anchor>();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Demo.Game
|
|||||||
{
|
{
|
||||||
public class DDT : ScriptableObject, IEnumerable<float>
|
public class DDT : ScriptableObject, IEnumerable<float>
|
||||||
{
|
{
|
||||||
|
protected override bool IsSelfEnableUpdate => false;
|
||||||
public static DDT Make()
|
public static DDT Make()
|
||||||
{
|
{
|
||||||
return new GameObject().AddComponent<DDT>();
|
return new GameObject().AddComponent<DDT>();
|
||||||
|
|||||||
@@ -222,16 +222,16 @@ namespace Demo.Game
|
|||||||
rootGameObject.SetContent("SongLength", MainAudio.CurrentClip.length);
|
rootGameObject.SetContent("SongLength", MainAudio.CurrentClip.length);
|
||||||
yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText());
|
yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText());
|
||||||
yield return rootGameObject.ApplyScript();
|
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 NDFS(child);
|
||||||
yield return child.ApplyScript();
|
|
||||||
yield return DFS(child);
|
|
||||||
}
|
}
|
||||||
|
if (current.IsScriptApply == false)
|
||||||
|
yield return current.ApplyScript();
|
||||||
}
|
}
|
||||||
yield return DFS(rootGameObject);
|
yield return NDFS(rootGameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -203,7 +203,8 @@ namespace Demo
|
|||||||
public string ScriptName = "";
|
public string ScriptName = "";
|
||||||
|
|
||||||
public ScriptableObject Parent;
|
public ScriptableObject Parent;
|
||||||
public List<ScriptableObject> Childs = new();
|
public readonly List<ScriptableObject> Childs = new();
|
||||||
|
public readonly List<ScriptableObject> UpdateChilds = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取根脚本对象
|
/// 获取根脚本对象
|
||||||
@@ -344,6 +345,8 @@ namespace Demo
|
|||||||
public static int AllScriptableObjectCounter = 0;
|
public static int AllScriptableObjectCounter = 0;
|
||||||
|
|
||||||
public bool IsParseScript2Expr { get; private set; } = false;
|
public bool IsParseScript2Expr { get; private set; } = false;
|
||||||
|
protected virtual bool IsSelfEnableUpdate { get => true; }
|
||||||
|
public bool IsEnableUpdate { get; private set; } = true;
|
||||||
|
|
||||||
#region LoadSubScript
|
#region LoadSubScript
|
||||||
|
|
||||||
@@ -381,6 +384,7 @@ namespace Demo
|
|||||||
|
|
||||||
// Add Child
|
// Add Child
|
||||||
Childs.Add(child);
|
Childs.Add(child);
|
||||||
|
UpdateChilds.Add(child);
|
||||||
|
|
||||||
// Load Child Script
|
// Load Child Script
|
||||||
ConventionUtility.StartCoroutine(child.ParseScript2Expr(file.LoadAsText()));
|
ConventionUtility.StartCoroutine(child.ParseScript2Expr(file.LoadAsText()));
|
||||||
@@ -413,6 +417,7 @@ namespace Demo
|
|||||||
|
|
||||||
// Add Child
|
// Add Child
|
||||||
Childs.Add(child);
|
Childs.Add(child);
|
||||||
|
UpdateChilds.Add(child);
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
@@ -495,9 +500,6 @@ namespace Demo
|
|||||||
IsParseScript2Expr = false;
|
IsParseScript2Expr = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Content]
|
|
||||||
public bool IsScriptApply { get; private set; } = false;
|
|
||||||
|
|
||||||
public enum TickType
|
public enum TickType
|
||||||
{
|
{
|
||||||
Reset,
|
Reset,
|
||||||
@@ -519,18 +521,26 @@ namespace Demo
|
|||||||
if (tickType == TickType.Reset)
|
if (tickType == TickType.Reset)
|
||||||
{
|
{
|
||||||
ResetEnterGameStatus();
|
ResetEnterGameStatus();
|
||||||
|
// Childs UpdateTicks
|
||||||
|
foreach (var child in Childs)
|
||||||
|
{
|
||||||
|
child.ScriptUpdate(currentTime, deltaTime, tickType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// UpdateTicks
|
else
|
||||||
if (UpdatePerFrame > 0)
|
|
||||||
{
|
{
|
||||||
if (ScriptUpdateCounter % UpdatePerFrame == 0)
|
// UpdateTicks
|
||||||
UpdateTicks(currentTime, deltaTime, tickType);
|
if (UpdatePerFrame > 0)
|
||||||
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
{
|
||||||
}
|
if (ScriptUpdateCounter % UpdatePerFrame == 0)
|
||||||
// Childs UpdateTicks
|
UpdateTicks(currentTime, deltaTime, tickType);
|
||||||
foreach (var child in Childs)
|
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
||||||
{
|
}
|
||||||
child.ScriptUpdate(currentTime, deltaTime, tickType);
|
// Childs UpdateTicks
|
||||||
|
foreach (var child in UpdateChilds)
|
||||||
|
{
|
||||||
|
child.ScriptUpdate(currentTime, deltaTime, tickType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -558,6 +568,9 @@ namespace Demo
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Content]
|
||||||
|
public bool IsScriptApply { get; private set; } = false;
|
||||||
|
|
||||||
[Convention.RScript.Variable.Attr.Method]
|
[Convention.RScript.Variable.Attr.Method]
|
||||||
public IEnumerator ApplyScript()
|
public IEnumerator ApplyScript()
|
||||||
{
|
{
|
||||||
@@ -566,7 +579,7 @@ namespace Demo
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
// 等待自身脚本解析完毕
|
// 等待自身脚本解析完毕
|
||||||
while(this.IsParseScript2Expr)
|
while (this.IsParseScript2Expr)
|
||||||
{
|
{
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
@@ -576,6 +589,18 @@ namespace Demo
|
|||||||
AllScriptableObjectCounter++;
|
AllScriptableObjectCounter++;
|
||||||
AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {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;
|
IsScriptApply = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ namespace Demo.Game
|
|||||||
{
|
{
|
||||||
public class SplineNode : ScriptableObject
|
public class SplineNode : ScriptableObject
|
||||||
{
|
{
|
||||||
|
protected override bool IsSelfEnableUpdate => false;
|
||||||
|
|
||||||
public static SplineNode Make()
|
public static SplineNode Make()
|
||||||
{
|
{
|
||||||
return new GameObject("", typeof(Node)).AddComponent<SplineNode>();
|
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