Unload优化
This commit is contained in:
@@ -351,6 +351,7 @@ namespace Demo
|
||||
|
||||
public PropertiesWindow.ItemEntry MyHierarchyItem;
|
||||
public static PropertiesWindow.ItemEntry AllScriptableObjectCounterHierarchyItem;
|
||||
public static PropertiesWindow.ItemEntry ScriptParseingHierarchyItem;
|
||||
|
||||
public bool EnsureEnableScript()
|
||||
{
|
||||
@@ -496,6 +497,7 @@ namespace Demo
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly object ParseScript2ExprObjectLocker = new();
|
||||
public IEnumerator ParseScript2Expr(string script)
|
||||
{
|
||||
IsParseScript2Expr = true;
|
||||
@@ -523,9 +525,16 @@ namespace Demo
|
||||
new() { data = PrivateType.IInteractionJudgementLevelInstance.instance, type = typeof(PrivateType.IInteractionJudgementLevelInstance) } }
|
||||
};
|
||||
|
||||
if (ScriptParseingHierarchyItem == null)
|
||||
{
|
||||
ScriptParseingHierarchyItem = HierarchyWindow.instance.CreateRootItemEntryWithBinders(ParseScript2ExprObjectLocker)[0];
|
||||
}
|
||||
|
||||
foreach (var ir in engine.RunAsync(script, importClass, variables).Yield())
|
||||
{
|
||||
yield return ir;
|
||||
if (engine.context.CurrentRuntimePointer < engine.context.Sentences.Length)
|
||||
ScriptParseingHierarchyItem.GetHierarchyItem().title = engine.context.CurrentSentence.ToString();
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -640,35 +649,30 @@ namespace Demo
|
||||
if (EnsureEnableScript())
|
||||
{
|
||||
this.name = "<Unloading>";
|
||||
try
|
||||
foreach (var child in Childs)
|
||||
{
|
||||
foreach (var child in Childs)
|
||||
{
|
||||
yield return child.UnloadScript();
|
||||
}
|
||||
ConventionUtility.StartCoroutine(child.UnloadScript());
|
||||
}
|
||||
finally
|
||||
if (IsScriptApply)
|
||||
{
|
||||
this.isEnableScript = false;
|
||||
this.Parent = null;
|
||||
this.name = "<Unload>";
|
||||
if (IsScriptApply)
|
||||
{
|
||||
// 清理各种状态
|
||||
IsScriptApply = false;
|
||||
// 清理Cache
|
||||
//
|
||||
// 减数
|
||||
AllScriptableObjectCounter--;
|
||||
AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}";
|
||||
}
|
||||
if (MyHierarchyItem != null)
|
||||
{
|
||||
// 卸载UI
|
||||
MyHierarchyItem.Release();
|
||||
MyHierarchyItem = null;
|
||||
}
|
||||
// 清理各种状态
|
||||
IsScriptApply = false;
|
||||
// 清理Cache
|
||||
//
|
||||
// 减数
|
||||
AllScriptableObjectCounter--;
|
||||
AllScriptableObjectCounterHierarchyItem.GetHierarchyItem().text = $"ScriptableObjectCount: {AllScriptableObjectCounter}";
|
||||
}
|
||||
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