Ejemplo n.º 1
0
        protected void ArrayList(SerializedProperty property, string title, Runnable1<SerializedProperty> renderer)
        {
            if (Foldout(title, false)) {
            Indent(() => {
                if (property.arraySize == 0) {
                    GUILayout.Label("   Use 'Add' button to add items");
                } else {
                    int arrSize = property.arraySize;
                    Separator();
                    for (int i = 0; i < arrSize; ++i) {
                        var go = property.GetArrayElementAtIndex(i);
                        EditorGUILayout.BeginHorizontal();

                        EditorGUILayout.BeginVertical();
                        renderer(go);
                        EditorGUILayout.EndVertical();

                        GUI.color = Color.red;
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false))) {
                            property.DeleteArrayElementAtIndex(i);
                            arrSize--;
                        }
                        GUI.color = Color.white;
                        EditorGUILayout.EndHorizontal();

                        if (i + 1 < arrSize) {
                            EditorGUILayout.Space();
                        }
                        Separator();
                    }
                }

                GUI.color = Color.green;
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Add", GUILayout.ExpandWidth(false))) {
                    property.InsertArrayElementAtIndex(property.arraySize);

                    // when creating new array element like this, the color will be initialized with
                    // (0, 0, 0, 0) - zero aplha. This may be confusing for end user so this workaround looks
                    // for color fields and sets them to proper values
                    var element = property.GetArrayElementAtIndex(property.arraySize - 1);
                    var enumerator = element.GetEnumerator();
                    while (enumerator.MoveNext()) {
                        var el = enumerator.Current as SerializedProperty;
                        if (el.type == "ColorRGBA") {
                            el.colorValue = Color.white;
                        }
                    }
                }
                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();
            });
            }
        }
Ejemplo n.º 2
0
 protected void ArrayList(SerializedProperty property, string title, Runnable1<SerializedProperty> renderer) {
     if (Foldout(title, false)) {
         Indent(() => {
             if (property.arraySize == 0) {
                 GUILayout.Label("   Use 'Add' button to add items");
             } else {
                 int arrSize = property.arraySize;
                 Separator();
                 for (int i = 0; i < arrSize; ++i) {
                     var go = property.GetArrayElementAtIndex(i);
                     EditorGUILayout.BeginHorizontal();
                     
                     EditorGUILayout.BeginVertical();
                     renderer(go);
                     EditorGUILayout.EndVertical();
                     
                     GUI.color = Color.red;
                     if (GUILayout.Button("X", GUILayout.ExpandWidth(false))) {
                         property.DeleteArrayElementAtIndex(i);
                         arrSize--;
                     }
                     GUI.color = Color.white;
                     EditorGUILayout.EndHorizontal();
                     
                     if (i + 1 < arrSize) {
                         EditorGUILayout.Space();
                     }
                     Separator();
                 }
             }
             
             GUI.color = Color.green;
             EditorGUILayout.BeginHorizontal();
             GUILayout.FlexibleSpace();
             if (GUILayout.Button("Add", GUILayout.ExpandWidth(false))) {
                 property.InsertArrayElementAtIndex(property.arraySize);
   
                 // when creating new array element like this, the color will be initialized with
                 // (0, 0, 0, 0) - zero aplha. This may be confusing for end user so this workaround looks
                 // for color fields and sets them to proper values                  
                 var element = property.GetArrayElementAtIndex(property.arraySize - 1);                  
                 var enumerator = element.GetEnumerator();
                 while (enumerator.MoveNext()) {
                     var el = enumerator.Current as SerializedProperty;
                     if (el.type == "ColorRGBA") {
                         el.colorValue = Color.white;
                     }
                 }
             }
             GUI.color = Color.white;
             EditorGUILayout.EndHorizontal();
         });
     }
 }