| using UnityEngine; | 
| using UnityEditor; | 
| using Snxxz.UI; | 
| using UnityEditorInternal; | 
|   | 
| [CustomEditor(typeof(WidgetBehavior), true)] | 
| public class WidgetBehaviorEditor : Editor | 
| { | 
|   | 
|     ReorderableList list; | 
|     void OnEnable() | 
|     { | 
|         var serProp = this.serializedObject.FindProperty("widgets"); | 
|         this.list = new ReorderableList(serProp.serializedObject, serProp, true, true, true, true); | 
|         this.list.drawHeaderCallback = this.OnDrawListHeader; | 
|         this.list.drawElementCallback = this.OnDrawListElement; | 
|         this.list.onAddCallback = this.OnAddCallback; | 
|     } | 
|     void OnDrawListHeader(Rect rect) | 
|     { | 
|         var spacing = 10f; | 
|         var arect = rect; | 
|         arect.height = EditorGUIUtility.singleLineHeight; | 
|         arect.x += 15; | 
|         arect.width = 200; | 
|         EditorGUI.LabelField(arect, "Name"); | 
|         arect.x += arect.width + spacing; | 
|         arect.width = 200; | 
|         EditorGUI.LabelField(arect, "GameObject"); | 
|     } | 
|   | 
|     void OnAddCallback(ReorderableList list) | 
|     { | 
|         if (list.serializedProperty != null) | 
|         { | 
|             list.serializedProperty.arraySize++; | 
|             list.index = list.serializedProperty.arraySize - 1; | 
|   | 
|             SerializedProperty itemData = list.serializedProperty.GetArrayElementAtIndex(list.index); | 
|             var namePop = itemData.FindPropertyRelative("name"); | 
|             namePop.stringValue = null; | 
|             var goPop = itemData.FindPropertyRelative("gameObject"); | 
|             goPop.objectReferenceValue = null; | 
|         } | 
|         else | 
|         { | 
|             ReorderableList.defaultBehaviours.DoAddButton(list); | 
|         } | 
|     } | 
|   | 
|     void OnDrawListElement(Rect rect, int index, bool isActive, bool isFocused) | 
|     { | 
|         var spacing = 10f; | 
|         var arect = rect; | 
|         var element = this.list.serializedProperty.GetArrayElementAtIndex(index); | 
|   | 
|         var nameProperty = element.FindPropertyRelative("name"); | 
|         var goProperty = element.FindPropertyRelative("gameObject"); | 
|   | 
|         arect.height = EditorGUIUtility.singleLineHeight; | 
|         arect.width = 200; | 
|         if (goProperty.objectReferenceValue != null && string.IsNullOrEmpty(nameProperty.stringValue)) | 
|             nameProperty.stringValue = EditorGUI.TextField(arect, goProperty.objectReferenceValue.name); | 
|         else | 
|             nameProperty.stringValue = EditorGUI.TextField(arect, nameProperty.stringValue); | 
|         arect.x += arect.width + spacing; | 
|         arect.width = 200; | 
|         EditorGUI.PropertyField(arect, goProperty, GUIContent.none); | 
|     } | 
|   | 
|     public override void OnInspectorGUI() | 
|     { | 
|         base.OnInspectorGUI(); | 
|         this.serializedObject.Update(); | 
|         var property = list.serializedProperty; | 
|         property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, property.displayName); | 
|         if (property.isExpanded) | 
|         { | 
|             this.list.DoLayoutList(); | 
|         } | 
|         this.serializedObject.ApplyModifiedProperties(); | 
|     } | 
|   | 
| } |