Hey
I have a script where I declare an array:
public float[] angles;
Then I have an editorscript linked to the first script where I have this:
serializedObject.Update();
EditorList.Show(serializedObject.FindProperty("angles"), EditorListOption.ListLabel | EditorListOption.Buttons);
serializedObject.ApplyModifiedProperties();
And then I have another script:
using UnityEditor;
using UnityEngine;
using System;
[Flags]
public enum EditorListOption {
None = 0,
ListSize = 1,
ListLabel = 2,
ElementLabels = 4,
Buttons = 8,
Default = ListSize | ListLabel | ElementLabels,
NoElementLabels = ListSize | ListLabel,
All = Default | Buttons
}
public static class EditorList {
private static GUIContent
MoveRotationBlockUp = new GUIContent("\u25B2", "Move Up"),
MoveRotationBlockDown = new GUIContent("\u25BC", "Move Down"),
duplicateButtonContent = new GUIContent("+", "Add Rotation Block"),
deleteButtonContent = new GUIContent("-", "Delete"),
AddRotationBlocks = new GUIContent("Add Rotation Blocks", "Add Rotation Blocks"),
RemoveAllBlocks = new GUIContent("Remove All Blocks", "Remove All Blocks");
private static GUILayoutOption miniButtonWidth = GUILayout.Width(20f);
public static void Show (SerializedProperty list, EditorListOption options = EditorListOption.Default)
{
bool
showListLabel = (options & EditorListOption.ListLabel) != 0,
showListSize = (options & EditorListOption.ListSize) != 0;
if(showListLabel)
{
EditorGUILayout.PropertyField(list);
EditorGUI.indentLevel++; //Indentlevel of the blocks themselves
}
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;
}
private static void ShowElements (SerializedProperty list, EditorListOption options)
{
bool
showElementLabels = (options & EditorListOption.ElementLabels) != 0,
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
GUI.color = Color.green;
if (showButtons && list.arraySize == 0 && GUILayout.Button(AddRotationBlocks))
{
list.arraySize++;
}
GUI.color = Color.red;
if(showButtons && list.arraySize != 0 && GUILayout.Button(RemoveAllBlocks))
{
list.arraySize = 0;
}
}
//BUTTONS
private static void ShowButtons (SerializedProperty list, int index)
{
//Move block up
if (GUILayout.Button(MoveRotationBlockUp, EditorStyles.miniButtonLeft, miniButtonWidth)) list.MoveArrayElement(index, index - 1);
//Move block down
if (GUILayout.Button(MoveRotationBlockDown, EditorStyles.miniButtonLeft, miniButtonWidth)) list.MoveArrayElement(index, index + 1);
//Add Block
if (GUILayout.Button(duplicateButtonContent, EditorStyles.miniButtonMid, miniButtonWidth)) list.InsertArrayElementAtIndex(index);
//RemoveBlock
if (GUILayout.Button(deleteButtonContent, EditorStyles.miniButtonRight, miniButtonWidth))
{
int oldSize = list.arraySize;
list.DeleteArrayElementAtIndex(index);
if (list.arraySize == oldSize) list.DeleteArrayElementAtIndex(index);
}
}
}
Now if I add the first script where I declare the array to a gameobject, I am able to fill in several floats.
Now my question is, how do I make it so that instead of having the ability to fill in one variable in each element of the list/array, I can declare multiple variables I have to fill in for each element of the list.
So for example, when I click the little plus icon and a new array element appears, I have 2 boxes where I can put variables in.
Any help would be truly great ![]()
