Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

ExecuteInEditMode Deciding when to update

Discussion in 'Scripting' started by Napivo, May 11, 2015.

  1. Napivo

    Napivo

    Joined:
    Feb 9, 2015
    Posts:
    39
    This is the first time I try to write a script that runs in Edit Mode

    What I can't wrap my head around is how to decide when to update without keeping a double for each flield like

    Code (csharp):
    1. private Int oldvalue;
    2. public int newvalue
    and Compare all my field values, which is very time consuming and overall inefficient.

    Usually I would use properties like this

    Code (CSharp):
    1.     private bool changed = false;
    2.     private int test = 0;
    3.     public int Test {
    4.         get
    5.         {
    6.             return test;
    7.         }
    8.         set
    9.         {
    10.             if (test != value)
    11.             {
    12.                 changed = true;
    13.                 test = value;
    14.             }
    15.         }
    16.     }
    but unity does not display properties in the UI for editing :(

    In the end I will need to destroy and recreate 100's if not 1000's of objects when an update is needed.

    Will any of you point me in the right direction on how to this fast and effectively?
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    You can edit properties if you write your own editor that draws them. then you could also let the editor perform the update, removing the need for execute in editor.
     
  3. Napivo

    Napivo

    Joined:
    Feb 9, 2015
    Posts:
    39
  4. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906