1
\$\begingroup\$

The problem I have is this. I have an editor script, at the end of OnInspectorGUI() I want to apply all the changes with the serialized object. The simplest way to show my problem is thus:

[SerializeField]
private bool _property;
public bool property
{
    get { return _property; }
    set
    {
        _property = value;
        //do some amazing stuff
    }
}

public override void OnInspectorGUI()
{
    serializedObject.Update();
    prop = serializedObject.FindProperty("_property");
    //blah blah blah
    serializedObject.ApplyModifiedProperties();
}

But in order to do my special amazing code represented by the comment 'do some amazing stuff', I have to copy and paste the code or do away with the gets & sets entirely, opting instead for some kind of post-update, all-in-one refresh function. Ideally, I want to tell SerializedObject, 'Hey, don't do _property = value, do property = value instead!' Pretty sure that's not possible though, so what should I do instead?

\$\endgroup\$
1
  • \$\begingroup\$ I'm not familiar with Unity serialization so I'll leave a comment instead of answer. You want custom (de)serialization which can be done by implementing ISerializable. If that interface is not supported in Unity, there's an ISerializationCallbackReceiver interface you can implement, but this is called after deserialization so you have less control on what custom actions are possible (but may work for your scenario). \$\endgroup\$
    – milk
    Commented Jun 18, 2016 at 1:48

0

You must log in to answer this question.

Browse other questions tagged .