Version 2.1.0.0

PropertyTree class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
public abstract class PropertyTree : IDisposable

Represents a set of values of the same type as a tree of properties that can be drawn in the inspector, and provides an array of utilities for querying the tree of properties.

Inheritance
  • System.Object
  • PropertyTree

Constructors

PropertyTree()
Creates a new PropertyTree for all target values of a UnityEditor.SerializedObject.
public PropertyTree()

Properties

AttributeProcessorLocator
Gets or sets the OdinAttributeProcessorLocator for the PropertyTree.
public OdinAttributeProcessorLocator AttributeProcessorLocator { get; set; }
DrawerChainResolver
Gets or sets the DrawerChainResolver for the PropertyTree.
public DrawerChainResolver DrawerChainResolver { get; set; }
DrawMonoScriptObjectField
Gets a value indicating whether or not to draw the mono script object field at the top of the property tree.
public bool DrawMonoScriptObjectField { get; set; }
IsStatic
Gets a value indicating whether or not the PropertyTree is inspecting a static type.
public bool IsStatic { get; protected set; }
PrefabModificationHandler
The prefab modification handler of the tree.
public abstract PrefabModificationHandler PrefabModificationHandler { get; }
PropertyResolverLocator
Gets or sets the OdinPropertyResolverLocator for the PropertyTree.
public OdinPropertyResolverLocator PropertyResolverLocator { get; set; }
RootPropertyCount
The number of root properties in the tree.
public abstract int RootPropertyCount { get; }
SecretRootProperty
Gets the secret root property of the tree, which hosts the property resolver used to resolve the "actual" root properties of the tree.
public abstract InspectorProperty SecretRootProperty { get; }
TargetType
The type of the values that the property tree represents.
public abstract Type TargetType { get; }
UnitySerializedObject
The UnityEditor.SerializedObject that this tree represents, if the tree was created for a UnityEditor.SerializedObject.
public abstract SerializedObject UnitySerializedObject { get; }
UpdateID
The current update ID of the tree. This is incremented once, each update, and is used by Update(Boolean) to avoid updating multiple times in the same update round.
public abstract int UpdateID { get; }
WeakTargets
The actual values that the property tree represents.
public abstract ImmutableList<object> WeakTargets { get; }

Methods

ApplyChanges()
Applies all changes made with properties to the inspected target tree values, and marks all changed Unity objects dirty.
public abstract bool ApplyChanges()
Returns
System.Boolean

true if any values were changed, otherwise false

Create(IList)

Creates a new PropertyTree for a set of given target values.

Note that the targets all need to be of the same type.

public static PropertyTree Create(IList targets)
Parameters
System.Collections.IList targets

The targets to create a tree for.

Returns
PropertyTree

Create(IList, SerializedObject)

Creates a new PropertyTree for a set of given target values, represented by a given UnityEditor.SerializedObject.

Note that the targets all need to be of the same type.

public static PropertyTree Create(IList targets, SerializedObject serializedObject)
Parameters
System.Collections.IList targets

The targets to create a tree for.

UnityEditor.SerializedObject serializedObject

The serialized object to create a tree for. Note that the target values of the given UnityEditor.SerializedObject must be the same values given in the targets parameter.

Returns
PropertyTree

Create(Object)
Creates a new PropertyTree for a given target value.
public static PropertyTree Create(object target)
Parameters
System.Object target

The target to create a tree for.

Returns
PropertyTree

Exceptions
System.ArgumentNullException

target is null

Create(Object[])

Creates a new PropertyTree for a set of given target values.

Note that the targets all need to be of the same type.

public static PropertyTree Create(params object[] targets)
Parameters
System.Object[] targets

The targets to create a tree for.

Returns
PropertyTree

Exceptions
System.ArgumentNullException

targets is null

Create(SerializedObject)
Creates a new PropertyTree for all target values of a UnityEditor.SerializedObject.
public static PropertyTree Create(SerializedObject serializedObject)
Parameters
UnityEditor.SerializedObject serializedObject

The serialized object to create a tree for.

Returns
PropertyTree

Exceptions
System.ArgumentNullException

serializedObject is null

CreateStatic(Type)
Creates a PropertyTree to inspect the static values of the given type.
public static PropertyTree CreateStatic(Type type)
Parameters
System.Type type

The type to inspect.

Returns
PropertyTree

A PropertyTree instance for inspecting the type.

DelayAction(Action)
Schedules a delegate to be invoked at the end of the current GUI frame.
public abstract void DelayAction(Action action)
Parameters
System.Action action

The action delegate to be delayed.

DelayActionUntilRepaint(Action)
Schedules a delegate to be invoked at the end of the next Repaint GUI frame.
public abstract void DelayActionUntilRepaint(Action action)
Parameters
System.Action action

The action to be delayed.

Dispose()
public void Dispose()
Dispose(Boolean)
protected virtual void Dispose(bool finalizer)
Parameters
System.Boolean finalizer

Draw(Boolean)

Draw the property tree, and handles management of undo, as well as marking scenes and drawn assets dirty.

This is a shorthand for calling BeginDrawPropertyTree(PropertyTree, Boolean), DrawPropertiesInTree(PropertyTree) and . EndDrawPropertyTree(PropertyTree).

public void Draw(bool applyUndo = true)
Parameters
System.Boolean applyUndo

EnumerateTree(Boolean)
Enumerates over the properties of the tree.
public abstract IEnumerable<InspectorProperty> EnumerateTree(bool includeChildren)
Parameters
System.Boolean includeChildren

Whether to include children of the root properties or not. If set to true, every property in the entire tree will be enumerated.

Returns
System.Collections.Generic.IEnumerable<InspectorProperty>

Finalize()
protected void Finalize()
GetPropertyAtPath(String)
Gets the property at the given path. Note that this is the path found in Path, not the Unity path.
public abstract InspectorProperty GetPropertyAtPath(string path)
Parameters
System.String path

The path of the property to get.

GetPropertyAtPath(String, out InspectorProperty)
Gets the property at the given path. Note that this is the path found in Path, not the Unity path.
public abstract InspectorProperty GetPropertyAtPath(string path, out InspectorProperty closestProperty)
Parameters
System.String path

The path of the property to get.

InspectorProperty closestProperty

GetPropertyAtPrefabModificationPath(String)
Gets the property at the given Odin prefab modification path.
public abstract InspectorProperty GetPropertyAtPrefabModificationPath(string path)
Parameters
System.String path

The prefab modification path of the property to get.

GetPropertyAtPrefabModificationPath(String, out InspectorProperty)
Gets the property at the given Odin prefab modification path.
public abstract InspectorProperty GetPropertyAtPrefabModificationPath(string path, out InspectorProperty closestProperty)
Parameters
System.String path

The prefab modification path of the property to get.

InspectorProperty closestProperty

GetPropertyAtUnityPath(String)
Gets the property at the given Unity path.
public abstract InspectorProperty GetPropertyAtUnityPath(string path)
Parameters
System.String path

The Unity path of the property to get.

GetPropertyAtUnityPath(String, out InspectorProperty)
Gets the property at the given Unity path.
public abstract InspectorProperty GetPropertyAtUnityPath(string path, out InspectorProperty closestProperty)
Parameters
System.String path

The Unity path of the property to get.

InspectorProperty closestProperty

GetReferenceCount(Object)
Gets the number of references to a given object instance in this tree.
public abstract int GetReferenceCount(object reference)
Parameters
System.Object reference

Returns
System.Int32

GetRootProperty(Int32)
Gets the root tree property at a given index.
public abstract InspectorProperty GetRootProperty(int index)
Parameters
System.Int32 index

The index of the property to get.

GetUnityPropertyForPath(String)
Gets a Unity property for the given Odin or Unity path. If there is no UnityEditor.SerializedObject for this property tree, or no such property is found in the UnityEditor.SerializedObject, a property will be emitted using UnityPropertyEmitter.
public SerializedProperty GetUnityPropertyForPath(string path)
Parameters
System.String path

The Odin or Unity path to the property to get.

Returns
UnityEditor.SerializedProperty

GetUnityPropertyForPath(String, out FieldInfo)
Gets a Unity property for the given Odin or Unity path. If there is no UnityEditor.SerializedObject for this property tree, or no such property is found in the UnityEditor.SerializedObject, a property will be emitted using UnityPropertyEmitter.
public abstract SerializedProperty GetUnityPropertyForPath(string path, out FieldInfo backingField)
Parameters
System.String path

The Odin or Unity path to the property to get.

System.Reflection.FieldInfo backingField

The backing field of the Unity property.

Returns
UnityEditor.SerializedProperty

InvokeDelayedActions()
Invokes the actions that have been delayed using DelayAction(Action) and DelayActionUntilRepaint(Action).
public abstract void InvokeDelayedActions()
InvokeOnValidate()
Invokes the OnValidate method on the property tree's targets if they are derived from UnityEngine.Object and have the method defined.
public void InvokeOnValidate()
ObjectIsReferenced(Object, out String)
Checks whether a given object instance is referenced anywhere in the tree, and if it is, gives the path of the first time the object reference was encountered as an out parameter.
public abstract bool ObjectIsReferenced(object value, out string referencePath)
Parameters
System.Object value

The reference value to check.

System.String referencePath

The first found path of the object.

Returns
System.Boolean

RegisterPropertyDirty(InspectorProperty)
Registers that a given property is dirty and needs its changes to be applied at the end of the current frame.
public abstract void RegisterPropertyDirty(InspectorProperty property)
Parameters
InspectorProperty property

ReplaceAllReferences(Object, Object)
Replaces all occurrences of a value with another value, in the entire tree.
public abstract void ReplaceAllReferences(object from, object to)
Parameters
System.Object from

The value to find all instances of.

System.Object to

The value to replace the found values with.

UpdateTree()
Updates all properties in the entire tree, and validates the prefab state of the tree, if applicable.
public abstract void UpdateTree()

Events

OnPropertyValueChanged
This event is invoked whenever the value of any property in the entire property tree is changed through the property system.
public event PropertyTree.OnPropertyValueChangedDelegate OnPropertyValueChanged
OnUndoRedoPerformed
An event that is invoked whenever an undo or a redo is performed in the inspector. The advantage of using this event on a property tree instance instead of UnityEditor.Undo.undoRedoPerformed is that this event will be desubscribed from UnityEditor.Undo.undoRedoPerformed when the selection changes and the property tree is no longer being used, allowing the GC to collect the property tree.
public event Action OnUndoRedoPerformed
Derived Classes