Sandbox.SerializedObject/PropertyPreChangeDelegate OnPropertyPreChange { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The OnPropertyPreChange property of the SerializedObject class is a delegate that is invoked before a property of the serialized object is changed. This allows you to perform any necessary actions or validations before the property value is actually modified.

Usage

To use the OnPropertyPreChange delegate, you need to assign a method that matches the PropertyPreChangeDelegate signature. This method will be called whenever a property is about to change, allowing you to handle pre-change logic such as validation or logging.

Example

// Example of using OnPropertyPreChange

// Define a method that matches the PropertyPreChangeDelegate signature
void OnPreChange(SerializedProperty property)
{
    // Perform actions before the property changes
    if (property.Name == "SomeProperty")
    {
        // Validate or log the change
        // For example, prevent change if certain conditions are not met
        if (!IsValidChange(property))
        {
            throw new InvalidOperationException("Change is not valid.");
        }
    }
}

// Assign the method to the OnPropertyPreChange delegate
SerializedObject serializedObject = new SerializedObject();
serializedObject.OnPropertyPreChange += OnPreChange;

// Now, whenever a property is about to change, OnPreChange will be called first.