#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEngine.UI.Collections;
namespace UnityEngine.UI
{
///
/// EditorOnly class for tracking all Graphics.
/// Used when a source asset is reimported into the editor to ensure that Graphics are updated as intended.
///
public static class GraphicRebuildTracker
{
static IndexedSet m_Tracked = new IndexedSet();
static bool s_Initialized;
///
/// Add a Graphic to the list of tracked Graphics
///
/// The graphic to track
public static void TrackGraphic(Graphic g)
{
if (!s_Initialized)
{
CanvasRenderer.onRequestRebuild += OnRebuildRequested;
s_Initialized = true;
}
m_Tracked.AddUnique(g);
}
///
/// Remove a Graphic to the list of tracked Graphics
///
/// The graphic to remove from tracking.
public static void UnTrackGraphic(Graphic g)
{
m_Tracked.Remove(g);
}
///
/// Remove a Graphic to the list of tracked Graphics
///
/// The graphic to remove from tracking.
public static void DisableTrackGraphic(Graphic g)
{
m_Tracked.DisableItem(g);
}
static void OnRebuildRequested()
{
StencilMaterial.ClearAll();
for (int i = 0; i < m_Tracked.Count; i++)
{
m_Tracked[i].OnRebuildRequested();
}
}
}
}
#endif // if UNITY_EDITOR