/// <summary>
        /// Save current component
        /// </summary>
        /// <param name="self"></param>
        /// <param name="rootParent">null for saving, not null for export</param>
        /// <param name="previous">previous comp</param>
        /// <param name="autoAssignNextComponentOfPrevious">jadi result.previous.next akan diassign otomatis, jika component hasil dari percabangan (ex : branch, if) atur ke false untuk menonaktifkan automatisasi</param>
        public static DIVisualComponent _SaveComponent(this DIVisualComponent self, UnityEngine.Object rootParent, DIVisualComponent previous, bool autoAssignNextComponentOfPrevious = true)
        {
#if UNITY_EDITOR
            string debug = "";
            self.name  = string.IsNullOrEmpty(self.windowName) ? self.GetType().ToString() : self.windowName;
            self.name += " - " + DIVisualScriptingData.inspectRootField.Name;
            DIVisualComponent result = null;
            //export
            if (rootParent != null)
            {
                debug          += "Export ";
                result          = Object.Instantiate(self);
                result.previous = previous;
                if (autoAssignNextComponentOfPrevious)
                {
                    result.previous.next = result;
                }
                result.name = self.name;
                AssetDatabase.AddObjectToAsset(result, rootParent);
                debug += " - New";
            }
            //Save to scene
            else
            {
                if (UnityEditor.AssetDatabase.IsSubAsset(self) || UnityEditor.AssetDatabase.IsMainAsset(self))
                {
                    result      = Object.Instantiate(self);
                    result.name = self.name;
                    result.next = self.next;
                    if (previous != null)
                    {
                        result.previous = previous;
                        if (autoAssignNextComponentOfPrevious)
                        {
                            result.previous.next = result;
                        }
                    }
                    result.position = self.position;
                }
                else
                {
                    result = self;
                }
                debug += "Saved";
            }

            debug += " - " + self.name;

#if DI_DEBUG
            Debug.Log(debug);
#endif

            if (result.next != null)
            {
                result.next.SaveComponent(rootParent, result);
            }
            return(result);
#endif
        }
        /// <summary>
        /// Change the current component without delete existing
        /// </summary>
        public void changeThisComponent(DIVisualComponent withThis)
        {
            withThis.position = position;

            //Set next Component neighbor
            if (next != null)
            {
                withThis.next = next;
                next.previous = withThis;
            }

            //if previous not null, set the previous component next to new component
            if (previous != null)
            {
                withThis.previous = previous;
                if (previous.next == this)
                {
                    previous.next = withThis;
                }
                else
                {
                    //use refelection to get real field name, because on previous component not always connected to next, like DICompare, can connected to true event
                    foreach (FieldInfo info in previous.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic))
                    {
                        //looping with fieldinfo of previous component
                        //if fieldInfo is DIVisualComponent
                        if (info.FieldType == typeof(DIVisualComponent) || info.FieldType.IsSubclassOf(typeof(DIVisualComponent)))
                        {
                            //Cast as DIVC
                            DIVisualComponent target = info.GetValue(previous) as DIVisualComponent;
                            //Check if target is same with this component
                            if (target == this)
                            {
                                //true means FieldInfo connected with this
                                //so we need to set the field info with the newComp
                                info.SetValue(previous, withThis);
                                break;
                            }
                        }
                        else if (info.FieldType == typeof(List <DIVisualComponent>))
                        {
                            List <DIVisualComponent> comps = info.GetValue(previous) as List <DIVisualComponent>;
                            for (int i = 0; i < comps.Count; i++)
                            {
                                if (comps[i] == this)
                                {
                                    comps[i] = withThis;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
 void ComponentTypePopup()
 {
     _tempReplaceComp = this.ComponentChooser();
     if (_tempReplaceComp != null)
     {
         if (_tempReplaceComp.GetType() != GetType())
         {
             DIVisualScriptingData.atTheEnd += changeThisComponentWithDestroy;
         }
     }
 }
        //TO DO : Supported List / array

        /*
         * public static void DrawList(FieldInfo _field, DIVisualComponent comp)
         * {
         #if UNITY_EDITOR
         *      EditorGUILayout.LabelField(_field.Name, EditorStyles.boldLabel);
         *      var list = ((IList)_field.GetValue(comp));
         *      EGLBeginHorizontal();
         *      GUI.enabled = false;
         *      EditorGUILayout.IntField("Size", list.Count);
         *      GUI.enabled = true;
         *      if (GUILayout.Button("+"))
         *              list.Add(null);
         *      if (GUILayout.Button("-"))
         *              list.RemoveAt(list.Count - 1);
         *      EGLEndHorizontal();
         *      System.Type type = null;
         *      for (int i = 0; i < list.Count; i++) {
         *              if (type == null)
         *                      type = list[i].GetType();
         *              if (type == typeof(int))
         *                      DrawIntField(i.ToString(), (int)list[i]);
         *              else if (type == typeof(float))
         *                      DrawFloatField(i.ToString(), (float)list[i]);
         *              else if (type == typeof(string))
         *                      DrawStringField(i.ToString(), (string)list[i]);
         *              else if (type == typeof(bool))
         *                      DrawToggleField(i.ToString(), (bool)list[i]);
         *              else if (type == typeof(System.Enum))
         *                      DrawEnumPopup(i.ToString(), (System.Enum)list[i]);
         *              else if (type == typeof(GameObject))
         *                      DrawGameObjectField(i.ToString(), (GameObject)list[i]);
         *              else if (type == typeof(Object))
         *                      DrawObjectField(i.ToString(), (Object)list[i]);
         *              else {
         *                      EditorGUILayout.HelpBox("Type : " + type.ToString() + " not Supported!", MessageType.Warning);
         *              }
         *      }
         #endif
         * }
         *
         * public static int DrawIntField(string label, int value)
         * {
         #if UNITY_EDITOR
         *      return EditorGUILayout.IntField(label, value);
         #endif
         * }
         * public static string DrawStringField(string label, string value)
         * {
         #if UNITY_EDITOR
         *      return EditorGUILayout.TextField(label, value);
         #endif
         * }
         * public static float DrawFloatField(string label, float value)
         * {
         #if UNITY_EDITOR
         *      return EditorGUILayout.FloatField(label, value);
         #endif
         * }
         * public static System.Enum DrawEnumPopup(string label, System.Enum selected)
         * {
         #if UNITY_EDITOR
         *      return EditorGUILayout.EnumPopup(label, selected);
         #endif
         * }
         * public static bool DrawToggleField(string label, bool value)
         * {
         #if UNITY_EDITOR
         *      return EditorGUILayout.Toggle(label, value);
         #endif
         * }
         * public static GameObject DrawGameObjectField(string label, GameObject value)
         * {
         #if UNITY_EDITOR
         *      return EditorGUILayout.ObjectField(label, value, typeof(GameObject), true) as GameObject;
         #endif
         * }
         * public static Object DrawObjectField(string label, Object value)
         * {
         #if UNITY_EDITOR
         *      return EditorGUILayout.ObjectField(label, value, typeof(UnityEngine.Object), true) as UnityEngine.Object;
         #endif
         * }*/

        public static FieldInfo[] GatherFieldInfos(DIVisualComponent comp)
        {
            return(comp.GetType().GetFields(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance));
        }