Version 3.0.0.2

PropertyContextContainer class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
public sealed class PropertyContextContainer

Contains a context for an InspectorProperty, which offers the ability to address persistent values by key across several editor GUI frames.

Use this in drawers to store contextual editor-only values such as the state of a foldout.

Inheritance
  • System.Object
  • PropertyContextContainer

Constructors

PropertyContextContainer(InspectorProperty)
Initializes a new instance of the PropertyContextContainer class.
public PropertyContextContainer(InspectorProperty property)
Parameters
InspectorProperty property

The property.

Exceptions
System.ArgumentNullException

property

Methods

GetGlobal<T>(String)

Gets a global context value for a given key, and creates a new instance of as a default value if the context doesn't already exist.

Global contexts are not associated with any one specific drawer, and so are shared across all drawers for this property.

public PropertyContext<T> GetGlobal<T>(string key)
    where T : new()
Parameters
System.String key

The key of the context value to get.

Returns
PropertyContext<T>

The found context.

Type Parameters
T

The type of the context value to get.

GetGlobal<T>(String, T)

Gets a global context value for a given key, using a given default value if the context doesn't already exist.

Global contexts are not associated with any one specific drawer, and so are shared across all drawers for this property.

public PropertyContext<T> GetGlobal<T>(string key, T defaultValue)
Parameters
System.String key

The key of the context value to get.

T defaultValue

The default value to set if the context value doesn't exist yet.

Returns
PropertyContext<T>

The found context.

Type Parameters
T

The type of the context value to get.

GetGlobal<T>(String, Func<T>)

Gets a global context value for a given key, using a given delegate to generate a default value if the context doesn't already exist.

Global contexts are not associated with any one specific drawer, and so are shared across all drawers for this property.

public PropertyContext<T> GetGlobal<T>(string key, Func<T> getDefaultValue)
Parameters
System.String key

The key of the context value to get.

System.Func<T> getDefaultValue

A delegate for generating a default value.

Returns
PropertyContext<T>

The found context.

Type Parameters
T

The type of the context value to get.

GetPersistent<TValue>(OdinDrawer, String, TValue)
Gets a GlobalPersistentContext<T> object and creates a LocalPersistentContext<T> object for it.
public LocalPersistentContext<TValue> GetPersistent<TValue>(OdinDrawer drawer, string key, TValue defaultValue)
Parameters
OdinDrawer drawer

The instance of the drawer.

System.String key

The key for the context.

TValue defaultValue

The default value for the context.

Returns
LocalPersistentContext<TValue>

Type Parameters
TValue

The type of the value of the context.

GetPersistent<TValue>(OdinDrawer, String, out LocalPersistentContext<TValue>)
Gets a GlobalPersistentContext<T> object and creates a LocalPersistentContext<T> object for it. Returns true when the GlobalPersistentContext<T> is first created. Otherwise false.
public bool GetPersistent<TValue>(OdinDrawer drawer, string key, out LocalPersistentContext<TValue> context)
Parameters
OdinDrawer drawer

The instance of the drawer.

System.String key

The key for the context.

LocalPersistentContext<TValue> context

The LocalPersistentContext<T> object.

Returns
System.Boolean

Returns true when the GlobalPersistentContext<T> is first created. Otherwise false.

Type Parameters
TValue

The type of the value of the context.

SwapContext(PropertyContextContainer)
Swaps context values with a given PropertyContextContainer.
public void SwapContext(PropertyContextContainer otherContext)
Parameters
PropertyContextContainer otherContext

The context to swap with.