How do I check if a bool value, int value, Rect, or List count is modified ?

Hey guys ,
I figured that this would be rather simple . All i needed to do was check the value of the bool against another bool, List count against an int,Int against an int etc…

but nope. I created these extension methods but then realized that tit makes no sense because the classes , functions and variables are all static.

Needless to say , it looks as if it works but it really does noting.

For our Rects
public static class RectExt
{

        private static Rect T;
        public static bool Changed(this Rect rect)
        {
            var result = false;
            if (rect != T) { result = true; T = rect; }

            return result;

        }
}


For our lists
public static class ListExt
{
        static int SetCount;
        public static bool Changed<T>(this List<T> list)
        {
            var result = false;
            if (SetCount != list.Count)
            {
                return true;
            }
            return result;
        }
}

I could do this , but I don’t want to have to do this in every class and for every rect , bool , or int I want to check

    public class Someclass
    {

        private Rect T;
        private Rect OtherRect;
        Boolean B;
        private bool Changed
        {
            get
            {
                return this.B;
            }
            set
            {
                this.B = (T != OtherRect)? true : false;
            }
        }

        

        void OnGUI()
        {
            if(Changed)
            {
                Debug.Log("WasChanged");
            }

        }

    }

Not entirely clear on what you’re trying to do, but extensions must always be static and can only be used by an instance of the type.
Like this:

public static class MyExtensions
{
    public static bool Compare(this Rect rect, Rect other)
    {
        return rect == other;
    }
    public static bool Compare<T>(this List<T> list, List<T> other)
    {
        return list.Count == other.Count;
    }
}

public class Test
{
    static void Main()
    {
        Rect a = new Rect();
        Rect b = new Rect();

        if (a.Compare(b))
        {
            // Do stuff
        }
    }
}

Of course, those are rather superfluous since you can just compare the values directly.

If you want something to happen when a field is changed, then you can use setter methods. Like so:

public class Test
{
    private Rect _rect;

    public void SetRect(Rect rect)
    {
        _rect = rect;
        // Rect was changed, so do other stuff.
    }
}

You can also do something like this:

public class Test
{
    public Rect Rect;

    public virtual void SetProperty(string property, object value)
    {
        if (GetType().GetField(property).FieldType == value.GetType())
        {
            GetType().GetField(property).SetValue(this, value);
            if (OnPropertyChanged != null)
            {
                OnPropertyChanged(this, property);
            }
        }
    }
    public event Action<Test, string> OnPropertyChanged;
}

public static class DoStuff
{
    public static void Main()
    {
        Test a = new Test();
        a.OnPropertyChanged += StuffChanged;
        a.SetProperty("Rect", new Rect(0, 0, 0, 0));
    }

    public static void StuffChanged(Test obj, string property)
    {
        // A property was changed.
    }
}

Try explaining a bit more about what you’re trying to accomplish.

You probably want to use C#'s Property design pattern. Unity3d uses this to handle modification of variables in its classes.

If you want a Property to show in the Inspector, you’ll need to write a custom inspector. http://wiki.unity3d.com/index.php?title=Expose_properties_in_inspector