You can use C# setters & getters instead of functions

Examples:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace RPG.Dialogue
{
    public class DialogueNode : ScriptableObject
    {
        [SerializeField]
        private string _text;
        [SerializeField]
        private List<string> _children = new();
        [SerializeField]
        private Rect _rect = new(45, 2000, 200, 100);

#if UNITY_EDITOR
        public string Text
        {
            get { return this._text; }
            set
            {
                if (value != this._text)
                {
                    Undo.RecordObject(this, "Update Dialogue Text");
                    this._text = value;
                }
            }
        }

        public List<string> Children
        {
            get { return this._children; }
            set
            {
                this._children = value;
            }
        }

        public void AddChild(string childID)
        {
            Undo.RecordObject(this, "Add Dialogue Link");
            this._children.Add(childID);
        }

        public void RemoveChild(string childID)
        {
            Undo.RecordObject(this, "Remove Dialogue Link");
            this._children.Remove(childID);
        }

        public Rect Rect
        {
            get { return this._rect; }
            set
            {
                Undo.RecordObject(this, "Move Dialogue Node");
                this._rect = value;
            }
        }

        public Vector2 Position
        {
            get { return this._rect.position; }
            set
            {
                Undo.RecordObject(this, "Move Dialogue Node");
                this._rect.position = value;
            }
        }
#endif
    }
}

This will allow you to use node.rect = newRect and still execute the cutom code in your setter :slight_smile:

3 Likes

Privacy & Terms