question

jessed avatar image
0 Likes"
jessed asked

How do I reset OnVariableChanged?

I'm using properties and delegates as below.

 public event Action<int> OnVariableChanged = delegate { };
   public int X 
   {
      get
      {
         return x;
      }
      set
      {
         int oldValue = x;
         int newValue = value;
         //Here you can find out difference
         x = value;
         OnVariableChanged.Invoke(value);
      }
   }

I'm finding that I need to keep track when a variable is used, for example, is changing in the set block, which doesn't make for an elegant solution.

 private void Awake()
 {
    OnVariableChanged += OnVariableChangeHandler;
 }
 private void OnVariableChangeHandler(int value)
 {
    //Do something when variable change
 }

Could this also be a bug in the underlying libraries?

default
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.