c# - Custom editor resets list every frame -


i trying make reorderable list in unity storing list of custom classes:

using system; using unityengine;  [serializable] public struct onboardingitemdata {    [tooltip("the hint gameobject")]    public gameobject prefab;     [tooltip("the object hint highlighting")]    public gameobject target;  } 

this class in list:

using system;     using system.collections.generic;     using unityengine;       public class onboardingitemlist : monobehaviour     {     public list<onboardingitemdata> list = new list<onboardingitemdata>();      private void update()     {         debug.log("list count: " + list.count);     }      public void refresh()     {         (int i=0; < list.count; i++)         {             if (list[i].prefab != null)             {                 list[i].prefab.getcomponent<onboardingitemclickhandler>().id =                  i;             }         }     }      public virtual void show(int id)     {         debug.log(list.count);         list[id].prefab.setactive(true);     }      public virtual void hide(int id)     {         list[id].prefab.setactive(false);     }     } 

and list shown this:

using unityengine; using unityeditor; using unityeditorinternal;  [customeditor(typeof(onboardingitemlist))] public class onboardingeditor : editor { private reorderablelist list;  private void onenable() {     list = new reorderablelist(serializedobject,             serializedobject.findproperty("list"),             true, true, true, true);     list.drawelementcallback =         (rect rect, int index, bool isactive, bool isfocused) => {             var element =                        list.serializedproperty.getarrayelementatindex(index);             rect.y += 2;             editorgui.propertyfield(                 new rect(rect.x, rect.y, 200,                  editorguiutility.singlelineheight),                 element.findpropertyrelative("prefab"), guicontent.none);             editorgui.propertyfield(                 new rect(rect.x + 250, rect.y, 200,                  editorguiutility.singlelineheight),                 element.findpropertyrelative("target"), guicontent.none);         }; }  public override void oninspectorgui() {     list.dolayoutlist();     serializedobject.applymodifiedproperties();     onboardingitemlist myscript = (onboardingitemlist)target;     if (guilayout.button("apply"))     {         myscript.refresh();     } } } 

now, in scene, there ui elements calling show() , hide() functions on onboardingitemlist. problem out of range exception, put debug.log in update() , see count of list changing. 1 frame says 2, next frame 0 , keeps changing , forth. assume keeps resetting list new one, , editor keeps assigning values of custom editor it. how fixed?


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -