public virtual void InspectorGUIOrderedListEmbedded <ListType>(string ListName, string ItemPrefix, ref List <ListType> CurrentList, ValueInspectorDelegate <ListType> ValueInspector, bool bReadOnly = false, bool bReadOnlyCount = true, bool bStartOpen = false) where ListType : XMLSerializable, new() { if (!InspectorArrayExpanded.ContainsKey(ListName)) { InspectorArrayExpanded.Add(ListName, bStartOpen); } bool bListExpanded = InspectorArrayExpanded[ListName]; bListExpanded = EditorGUILayout.Foldout(bListExpanded, ListName); InspectorArrayExpanded[ListName] = bListExpanded; if (bListExpanded) { EditorGUI.indentLevel += 1; int NewListCount = CurrentList.Count; int OldListCount = NewListCount; bool bCountActuallyChanged = false; if (bReadOnly || bReadOnlyCount) { EditorGUILayout.LabelField("Count", CurrentList.Count.ToString()); } else { bCountActuallyChanged = InspectorGUIIntWaitForEnter(ListName + "Count", "Count", OldListCount, out NewListCount); } if (bCountActuallyChanged && NewListCount != CurrentList.Count) { bInspectorHasChangedProperty = true; if (NewListCount > CurrentList.Count) { for (int CurrentElement = CurrentList.Count; CurrentElement < NewListCount; ++CurrentElement) { CurrentList.Add(new ListType()); } } else { for (int CurrentElement = NewListCount; CurrentElement < CurrentList.Count;) { CurrentList.RemoveAt(CurrentElement); } } } int MoveUpIndex = -1; int MoveDownIndex = -1; int SmallestSize = OldListCount > NewListCount ? NewListCount : OldListCount; for (int CurrentIndex = 0; CurrentIndex < SmallestSize; ++CurrentIndex) { if (ValueInspector != null) { EditorGUILayout.BeginVertical("box"); ListType TempRef = CurrentList[CurrentIndex]; bInspectorHasChangedProperty = ValueInspector(ref TempRef) || bInspectorHasChangedProperty; CurrentList[CurrentIndex] = TempRef; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Move up")) { MoveUpIndex = CurrentIndex; } if (GUILayout.Button("Move down")) { MoveDownIndex = CurrentIndex; } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } } if (MoveUpIndex > 0 && MoveUpIndex < SmallestSize) { ListType ItemToMove = CurrentList[MoveUpIndex]; List <ListType> NewList = new List <ListType>(); CurrentList.RemoveAt(MoveUpIndex); for (int NewItem = 0; NewItem < SmallestSize + 1; ++NewItem) { if (NewItem == MoveUpIndex - 1) { NewList.Add(ItemToMove); } else if (NewItem >= MoveUpIndex) { NewList.Add(CurrentList[NewItem - 1]); } else { NewList.Add(CurrentList[NewItem]); } } CurrentList = NewList; } if (MoveDownIndex > -1 && MoveDownIndex < SmallestSize - 1) { ListType ItemToMove = CurrentList[MoveDownIndex]; List <ListType> NewList = new List <ListType>(); CurrentList.RemoveAt(MoveDownIndex); for (int NewItem = 0; NewItem < SmallestSize + 1; ++NewItem) { if (NewItem == MoveDownIndex + 1) { NewList.Add(ItemToMove); } else if (NewItem > MoveDownIndex + 1) { NewList.Add(CurrentList[NewItem - 1]); } else { NewList.Add(CurrentList[NewItem]); } } CurrentList = NewList; } EditorGUI.indentLevel -= 1; } }
public virtual void InspectorGUIListEmbedded <ListType>(string ListName, string ItemPrefix, ref List <ListType> CurrentList, ValueInspectorDelegate <ListType> ValueInspector, bool bReadOnly = false, bool bReadOnlyCount = true, bool bStartOpen = false) where ListType : XMLSerializable, new() { if (!InspectorArrayExpanded.ContainsKey(ListName)) { InspectorArrayExpanded.Add(ListName, bStartOpen); } bool bListExpanded = InspectorArrayExpanded[ListName]; bListExpanded = EditorGUILayout.Foldout(bListExpanded, ListName); InspectorArrayExpanded[ListName] = bListExpanded; if (bListExpanded) { EditorGUI.indentLevel += 1; int NewListCount = CurrentList.Count; int OldListCount = NewListCount; bool bCountActuallyChanged = false; if (bReadOnly || bReadOnlyCount) { EditorGUILayout.LabelField("Count", CurrentList.Count.ToString()); } else { bCountActuallyChanged = InspectorGUIIntWaitForEnter(ListName + "Count", "Count", OldListCount, out NewListCount); } if (bCountActuallyChanged && NewListCount != CurrentList.Count) { bInspectorHasChangedProperty = true; if (NewListCount > CurrentList.Count) { for (int CurrentElement = CurrentList.Count; CurrentElement < NewListCount; ++CurrentElement) { CurrentList.Add(new ListType()); } } else { for (int CurrentElement = NewListCount; CurrentElement < CurrentList.Count;) { CurrentList.RemoveAt(CurrentElement); } } } int SmallestSize = OldListCount > NewListCount ? NewListCount : OldListCount; for (int CurrentIndex = 0; CurrentIndex < SmallestSize; ++CurrentIndex) { if (ValueInspector != null) { EditorGUILayout.BeginVertical("box"); ListType TempRef = CurrentList[CurrentIndex]; bInspectorHasChangedProperty = ValueInspector(ref TempRef) || bInspectorHasChangedProperty; CurrentList[CurrentIndex] = TempRef; EditorGUILayout.EndVertical(); } } EditorGUI.indentLevel -= 1; } }