using System;
namespace UnityEditor.Rendering
{
/// Used in editor drawer part to store the state of expendable areas.
/// An enum to use to describe the state.
/// A type given to automatically compute the key.
public struct ExpandedState
where TState : struct, IConvertible
{
EditorPrefBoolFlags m_State;
/// Constructor will create the key to store in the EditorPref the state given generic type passed.
/// If key did not exist, it will be created with this value for initialization.
public ExpandedState(TState defaultValue, string prefix = "CoreRP")
{
String Key = string.Format("{0}:{1}:UI_State", prefix, typeof(TTarget).Name);
m_State = new EditorPrefBoolFlags(Key);
//register key if not already there
if (!EditorPrefs.HasKey(Key))
{
EditorPrefs.SetInt(Key, (int)(object)defaultValue);
}
}
/// Get or set the state given the mask.
public bool this[TState mask]
{
get { return m_State.HasFlag(mask); }
set { m_State.SetFlag(mask, value); }
}
/// Accessor to the expended state of this specific mask.
public bool GetExpandedAreas(TState mask)
{
return m_State.HasFlag(mask);
}
/// Setter to the expended state.
public void SetExpandedAreas(TState mask, bool value)
{
m_State.SetFlag(mask, value);
}
/// Utility to set all states to true
public void ExpandAll()
{
m_State.rawValue = ~(-1);
}
/// Utility to set all states to false
public void CollapseAll()
{
m_State.rawValue = 0;
}
}
}