using System.Collections.Generic;
using UnityEngine.UI.Collections;
namespace UnityEngine.UI
{
///
/// Registry class to keep track of all IClippers that exist in the scene
///
///
/// This is used during the CanvasUpdate loop to cull clippable elements. The clipping is called after layout, but before Graphic update.
///
public class ClipperRegistry
{
static ClipperRegistry s_Instance;
readonly IndexedSet m_Clippers = new IndexedSet();
protected ClipperRegistry()
{
// This is needed for AOT platforms. Without it the compile doesn't get the definition of the Dictionarys
#pragma warning disable 168
Dictionary emptyIClipperDic;
#pragma warning restore 168
}
///
/// The singleton instance of the clipper registry.
///
public static ClipperRegistry instance
{
get
{
if (s_Instance == null)
s_Instance = new ClipperRegistry();
return s_Instance;
}
}
///
/// Perform the clipping on all registered IClipper
///
public void Cull()
{
var clippersCount = m_Clippers.Count;
for (var i = 0; i < clippersCount; ++i)
{
m_Clippers[i].PerformClipping();
}
}
///
/// Register a unique IClipper element
///
/// The clipper element to add
public static void Register(IClipper c)
{
if (c == null)
return;
instance.m_Clippers.AddUnique(c);
}
///
/// UnRegister a IClipper element
///
/// The Element to try and remove.
public static void Unregister(IClipper c)
{
instance.m_Clippers.Remove(c);
}
///
/// Disable a IClipper element
///
/// The Element to try and disable.
public static void Disable(IClipper c)
{
instance.m_Clippers.DisableItem(c);
}
}
}