Ejemplo n.º 1
0
    public static void Show(SerializedProperty list,
	                        EditorListOption options = EditorListOption.Default)
    {
        if (!list.isArray) {
            EditorGUILayout.HelpBox(list.name + " is neither an array nor a list!", MessageType.Error);
            return;
        }
        bool showListLabel = (options & EditorListOption.ListLabel) != 0;
        bool showListSize  = (options & EditorListOption.ListSize)  != 0;
        if (showListLabel) {
            EditorGUILayout.PropertyField(list);
            EditorGUI.indentLevel += 1;
        }
        if (!showListLabel || list.isExpanded) {
            SerializedProperty size = list.FindPropertyRelative("Array.size");
            if (showListSize) {
                EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));
            }
            if (size.hasMultipleDifferentValues) {
                EditorGUILayout.HelpBox("Not showing lists with different sizes.", MessageType.Info);
            } else {
                ShowElements(list, options);
            }
        }
        if (showListLabel) {
            EditorGUI.indentLevel -= 1;
        }
    }
Ejemplo n.º 2
0
	private static void ShowElements (SerializedProperty list, EditorListOption options) {

		bool showButtons = (options & EditorListOption.Buttons) != 0;
		/*
		 * Loop through each element in the array
		 */
		for (int i = 0; i < list.arraySize; i++) {
				//Place the objects side by side
				EditorGUILayout.BeginHorizontal();
				//Create an Input Slot
				EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i));

				//Show both buttons plus and minus
				ShowButtons(list, i);
				EditorGUILayout.EndHorizontal();
				//Continue placing the objects below
		}
		if (showButtons && list.arraySize == 0 && GUILayout.Button(addButtonContent, EditorStyles.miniButton)) {
			list.arraySize += 1;
		}
	}
Ejemplo n.º 3
0
 static void ShowElements(SerializedProperty list, EditorListOption options)
 {
     bool showElementLabels = (options & EditorListOption.ElementLabels) != 0;
     bool showButtons       = (options & EditorListOption.Buttons)       != 0;
     for (int i = 0; i < list.arraySize; ++i) {
         if (showButtons) {
             EditorGUILayout.BeginHorizontal();
         }
         if (showElementLabels) {
             EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i));
         } else {
             EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), GUIContent.none);
         }
         if (showButtons) {
             ShowButtons(list, i);
             EditorGUILayout.EndHorizontal();
         }
     }
     if (showButtons && list.arraySize == 0 && GUILayout.Button(addButtonContent, EditorStyles.miniButton)) {
         list.arraySize += 1;
     }
 }
Ejemplo n.º 4
0
    // Function to ovveride and display custom object array in inspector
    public void ArrayGUI(string label, string name, EditorListOption options = EditorListOption.Default)
    {
        bool showListLabel = (options & EditorListOption.ListLabel) != 0;
        bool showListSize = (options & EditorListOption.ListSize) != 0;
        SerializedProperty list = serializedObject.FindProperty(name);

        if (showListLabel) {
            EditorGUILayout.PropertyField(list, new GUIContent(label));
            EditorGUI.indentLevel += 1;
        }
        if (!showListLabel || list.isExpanded) {
            if (showListSize) {
                EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));
            }
            for (int i = 0; i < list.arraySize; i++) {
                EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i));
            }
        }
        if (showListLabel) {
            EditorGUI.indentLevel -= 1;
        }
    }
Ejemplo n.º 5
0
	public static void Show (SerializedProperty list, string str_lbl, string tooltip, EditorListOption options = EditorListOption.Default) {

		bool showListLabel = (options & EditorListOption.ListLabel) != 0;
		bool showListSize = (options & EditorListOption.ListSize) != 0;
		if (showListLabel) {
			EditorGUILayout.PropertyField(list, new GUIContent(str_lbl, tooltip));
			EditorGUI.indentLevel += 1;
		}
		if (!showListLabel || list.isExpanded) {
			SerializedProperty size = list.FindPropertyRelative("Array.size");
			if (showListSize) {
				EditorGUILayout.PropertyField(size);
			}
			if (size.hasMultipleDifferentValues) {
				EditorGUILayout.HelpBox("Not showing lists with different sizes.", MessageType.Info);
			}
			else {
				ShowElements(list, options);
			}
		}
		if (showListLabel) {
			EditorGUI.indentLevel -= 1;
		}
	}