A powerful set of utilities for custom editor scripting, reflection, and enum manipulation in Unity. This package simplifies working with nested serialized fields, dynamic reflection, and enum values for complex Unity workflows.
Working with nested structs and serialized fields in Unity can be challenging, especially when updating properties inside deeply nested structures. Unity's SerializedProperty system lacks robust tools for recursive struct serialization and direct field manipulation. This library bridges that gap by:
- Leveraging reflection for dynamic field access (via dot-separated paths).
- Adding support for boxed value manipulation.
- Providing enum handling utilities based on order indices instead of raw integer values.
- Dynamic Value Retrieval/Assignment: Provides methods to get or set values in serialized properties.
- Type Information: Retrieve
System.Typeof serialized fields. - Boxed Value Handling: Update and manipulate
SerializedProperty.boxedValuefor nested struct serialization.
- Advanced Field Reflection: Access nested fields or array elements using dot-separated paths.
- Field Mapping: Retrieve field stacks for dynamic traversal.
- Collection Parsing: Handle array or IList elements for reflection.
- Direct Value Assignment: Set values inside structs or arrays with path-based navigation.
- Index-based Enums: Retrieve enums dynamically using their order index.
- Unified Enum Handling: Resolve enums for fields across different structures.
- Add the package via Git URL or local folder.
using PsigenVision.Utilities;and/orusing PsigenVision.Utilities.Editor- Start using extensions as seen in examples!
Easily manipulate or update fields using dot-separated field paths and reflection.
// Example: Updating fields using boxedValue
object boxedObj = property.boxedValue;
string path = "innerStruct.booleanValue";
// Set the value via path
if (!boxedObj.TrSetValueViaPath(property.GetSystemType(), path, true))
Debug.Log("Failed to update boxed object with new value);
else
{
// Assign back to the property if the value was successfully set
property.boxedValue = boxedObj;
property.serializedObject.ApplyModifiedProperties();
}
Use reflection to map nested field stacks, supporting fields like arrays or lists.
object[] objectStack = null;
System.Type[] typeStack = null;
string[] fieldNames = null;
if (myObject.GetFieldMapsViaPath(typeof(MyClass), "nestedField.listField[3].value",
ref objectStack, ref typeStack, ref fieldNames)) {
Debug.Log($"Resolved field: {fieldNames.Last()}");
}Retrieve enums dynamically using order-based indices instead of raw integer values.
int index = 2;
if (index.TryGetEnumByIndex(out MyEnum result)) {
Debug.Log($"Enum found: {result}");
}You can also retrieve an enum dynamically from an object, providing the field name for its enum instance member.
if (containingObject.TryGetEnumByIndex("valueType", 3, out object result)) {
Debug.Log($"Retrieved enum: {result}");
} else {
Debug.Log("Could not obtain enum version of the third index for the valueType enum field in the containing object");
}SetBoxedValue(SerializedProperty property, ...)- Update nested values in serialized properties.GetValue()/SetValue(object value)- Read/write values using reflection.GetSystemType()- Get the type of a serialized property.
GetFieldViaPath(string path)- ResolveFieldInfodynamically.SetValueViaPath(string path, object value)- Set values in nested fields and collections.GetFieldMapsViaPath(...)- Traverse object hierarchies for advanced scenarios.
TryGetEnumByIndex<T>(int index)- Get an enum value by its index in the definition order.
- Custom Property Drawers: Simplify serialization and property field updates for nested structs or dynamic objects using reflection and boxed values.
- Dynamic Enums: Dynamically handle enums in property fields based on user selection indices.
- Complex Data Hierarchies: Easily traverse, debug, or modify deeply nested serialized data structures.
- Array/List access in reflection requires implementing
IList. - Field paths must follow the dot-separated format (supports collections like
array[3]).
Feel free to submit issues or propose improvements. Contributions are welcome!
This package is distributed under the MIT license. See LICENSE for details.