加载性能优化, 暂时放弃异步加载
This commit is contained in:
@@ -111,7 +111,7 @@ namespace Demo
|
||||
/// </summary>
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
public Dictionary<string, float> ScriptableObjectContents = new();
|
||||
public readonly Dictionary<string, float> ScriptableObjectContents = new();
|
||||
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public float GetContent(string key)
|
||||
@@ -120,10 +120,6 @@ namespace Demo
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (Parent != null)
|
||||
{
|
||||
return Parent.GetContent(key);
|
||||
}
|
||||
throw new InvalidOperationException($"Key {key} is not find in contnet");
|
||||
}
|
||||
|
||||
@@ -254,6 +250,8 @@ namespace Demo
|
||||
return;
|
||||
}
|
||||
this.Parent = parent;
|
||||
if (parent != null)
|
||||
this.ScriptableObjectContents.AddRange(parent.ScriptableObjectContents);
|
||||
|
||||
this.name = ScriptName;
|
||||
|
||||
@@ -470,9 +468,21 @@ namespace Demo
|
||||
#endif
|
||||
IHierarchyItemClickEventListener
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
internal static readonly HashSet<ScriptableObject> s_DebugContainer = new();
|
||||
private void Awake()
|
||||
{
|
||||
s_DebugContainer.Add(this);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
s_DebugContainer.Remove(this);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected virtual IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
return null;
|
||||
yield break;
|
||||
}
|
||||
|
||||
[Content]
|
||||
@@ -497,16 +507,18 @@ namespace Demo
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
if (IsScriptApply)
|
||||
yield break;
|
||||
// 等待自身脚本解析完毕
|
||||
while (this.IsParseScript2Expr)
|
||||
{
|
||||
yield return null;
|
||||
while (LoadingTaskCoroutineCount < MaxLoadingCoroutine && WaitingTaskForLoadingCoroutine.Count > 0)
|
||||
{
|
||||
LoadingTaskCoroutineCount++;
|
||||
ConventionUtility.StartCoroutine(WaitingTaskForLoadingCoroutine.First.Value);
|
||||
WaitingTaskForLoadingCoroutine.RemoveFirst();
|
||||
}
|
||||
yield return this;
|
||||
}
|
||||
while (LoadingTaskCoroutineCount < MaxLoadingCoroutine && WaitingTaskForLoadingCoroutine.Count > 0)
|
||||
{
|
||||
LoadingTaskCoroutineCount++;
|
||||
ConventionUtility.StartCoroutine(WaitingTaskForLoadingCoroutine.First.Value);
|
||||
WaitingTaskForLoadingCoroutine.RemoveFirst();
|
||||
}
|
||||
yield return DoSomethingDuringApplyScript();
|
||||
// 增数
|
||||
@@ -525,36 +537,37 @@ namespace Demo
|
||||
GetRoot().UpdateChilds[type] = new() { this };
|
||||
}
|
||||
}
|
||||
// 释放资源
|
||||
{
|
||||
this.ScriptableObjectContents.Clear();
|
||||
}
|
||||
IsScriptApply = true;
|
||||
}
|
||||
|
||||
public virtual IEnumerator UnloadScript()
|
||||
{
|
||||
if (EnsureEnableScript())
|
||||
if (IsScriptApply)
|
||||
{
|
||||
this.name = "<Unloading>";
|
||||
foreach (var child in Childs)
|
||||
{
|
||||
ConventionUtility.StartCoroutine(child.UnloadScript());
|
||||
}
|
||||
if (IsScriptApply)
|
||||
{
|
||||
// 清理各种状态
|
||||
IsScriptApply = false;
|
||||
// 清理Cache
|
||||
//
|
||||
// 减数
|
||||
ApplyScriptableObjectCounter--;
|
||||
EnableScriptableObjectCounter++;
|
||||
AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"SOC: {ApplyScriptableObjectCounter}/{EnableScriptableObjectCounter}";
|
||||
}
|
||||
yield return new WaitUntil(() => Childs.Any(x => x.isEnableScript == false) == false);
|
||||
// 清理各种状态
|
||||
IsScriptApply = false;
|
||||
// 清理Cache
|
||||
//
|
||||
// 减数
|
||||
ApplyScriptableObjectCounter--;
|
||||
EnableScriptableObjectCounter--;
|
||||
AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"SOC: {ApplyScriptableObjectCounter}/{EnableScriptableObjectCounter}";
|
||||
if (MyHierarchyItem != null)
|
||||
{
|
||||
// 卸载UI
|
||||
MyHierarchyItem.Release();
|
||||
MyHierarchyItem = null;
|
||||
}
|
||||
yield return new WaitUntil(() => Childs.Any(x => x.isEnableScript == false) == false);
|
||||
this.isEnableScript = false;
|
||||
this.Parent = null;
|
||||
this.name = "<Unload>";
|
||||
|
||||
Reference in New Issue
Block a user