mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
safer UIBehaviour instance updates, init method
This commit is contained in:
parent
a6ff9e02e2
commit
f89455549e
@ -15,26 +15,37 @@ namespace UnityExplorer.UI.Models
|
|||||||
if (!Instances.Any())
|
if (!Instances.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = Instances.Count - 1; i >= 0; i--)
|
try
|
||||||
{
|
{
|
||||||
var instance = Instances[i];
|
for (int i = Instances.Count - 1; i >= 0; i--)
|
||||||
if (!instance.UIRoot)
|
{
|
||||||
Instances.RemoveAt(i);
|
var instance = Instances[i];
|
||||||
else if (instance.NeedsUpdate && instance.Visible)
|
if (instance == null || !instance.UIRoot)
|
||||||
instance.Update();
|
{
|
||||||
|
ExplorerCore.Log($"Instance {instance?.GetType().Name ?? "<null>"} has no UIRoot or it was destroyed!");
|
||||||
|
Instances.RemoveAt(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (instance.Visible)
|
||||||
|
instance.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ExplorerCore.Log(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Default false, if true then Update should be implemented.
|
|
||||||
/// </summary>
|
|
||||||
public virtual bool NeedsUpdate => false;
|
|
||||||
|
|
||||||
public UIBehaviourModel()
|
public UIBehaviourModel()
|
||||||
{
|
{
|
||||||
Instances.Add(this);
|
Instances.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default empty method, override and implement if NeedsUpdateTick is true.
|
/// Default empty method, override and implement if NeedsUpdateTick is true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user