void ShowLayer() { CleanUpStates(); SetLayerStates(); if (currentLayerProperty.isExpanded) { EditorGUI.indentLevel += 1; List<string> currentLayerStatesName = new List<string>{ "Empty" }; for (int i = 0; i < statesProperty.arraySize; i++) { currentLayerStatesName.Add(FormatStateType(statesProperty.GetArrayElementAtIndex(i).GetValue().GetType(), currentLayer)); } for (int i = 0; i < currentStatesProperty.arraySize; i++) { SerializedProperty stateProperty = currentStatesProperty.GetArrayElementAtIndex(i); Rect dragArea = EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); int stateIndex = EditorGUILayout.Popup(string.Format("Active State ({0})", i), stateProperty.objectReferenceValue == null ? 0 : statesProperty.IndexOf(stateProperty.objectReferenceValue) + 1, currentLayerStatesName.ToArray(), GUILayout.MinWidth(200)) - 1; stateProperty.SetValue(stateIndex == -1 ? null : statesProperty.GetArrayElementAtIndex(Mathf.Clamp(stateIndex, 0, statesProperty.arraySize - 1)).GetValue()); if (EditorGUI.EndChangeCheck() && Application.isPlaying) { currentLayer.SwitchState(stateProperty.objectReferenceValue == null ? typeof(EmptyState) : stateProperty.objectReferenceValue.GetType(), i); } if (i == 0) { SmallAddButton(currentStatesProperty); } else if (DeleteButton(currentStatesProperty, i)) { break; } EditorGUILayout.EndHorizontal(); Reorderable(currentStatesProperty, i, true, EditorGUI.IndentedRect(dragArea)); } Separator(); ShowLayerFields(); ShowStates(); if (statesProperty.arraySize > 0) Separator(); EditorGUI.indentLevel -= 1; } currentLayerSerialized.ApplyModifiedProperties(); }
void ShowLayer(SerializedProperty layersProperty, int index) { SerializedProperty layerProperty = layersProperty.GetArrayElementAtIndex(index); StateLayer layer = layerProperty.GetValue <StateLayer>(); SerializedObject layerSerialized = new SerializedObject(layer); SerializedProperty statesProperty = layerSerialized.FindProperty("stateReferences"); SerializedProperty activeStatesProperty = layerSerialized.FindProperty("activeStateReferences"); StateMachineUtility.AddMissingStates(machine, layer); BeginBox(GetBoxStyle(layer)); Rect rect = EditorGUILayout.BeginHorizontal(); ShowAddSubLayer(layer, rect); if (DeleteFoldOut(layersProperty, index, GetLayerLabel(layer), GetLayerStyle(layer))) { StateMachineUtility.RemoveLayer(layer); return; } EditorGUILayout.EndHorizontal(); CleanUpStates(statesProperty); if (layerProperty.isExpanded) { EditorGUI.indentLevel += 1; List <string> currentLayerStatesName = new List <string> { "Empty" }; foreach (IState state in statesProperty.GetValues <IState>()) { currentLayerStatesName.Add(state is IStateLayer ? state.GetType().Name.Split('.').Last() : StateMachineUtility.FormatState(state.GetType(), layer)); } for (int i = 0; i < activeStatesProperty.arraySize; i++) { SerializedProperty activeStateProperty = activeStatesProperty.GetArrayElementAtIndex(i); UnityEngine.Object activeState = activeStateProperty.objectReferenceValue; if (Selection.gameObjects.Length <= 1) { Rect dragArea = EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); int stateIndex = EditorGUILayout.Popup(string.Format("Active State ({0})", i), statesProperty.IndexOf(activeState) + 1, currentLayerStatesName.ToArray(), GUILayout.MinWidth(200)) - 1; activeState = stateIndex == -1 ? null : statesProperty.GetValue <UnityEngine.Object>(Mathf.Clamp(stateIndex, 0, statesProperty.arraySize - 1)); activeStateProperty.SetValue(activeState); if (EditorGUI.EndChangeCheck() && Application.isPlaying) { layer.SwitchState(activeState == null ? typeof(EmptyState) : activeState.GetType(), i); } if (i == 0) { SmallAddButton(activeStatesProperty); } else if (DeleteButton(activeStatesProperty, i)) { break; } EditorGUILayout.EndHorizontal(); Reorderable(activeStatesProperty, i, true, EditorGUI.IndentedRect(dragArea)); } else { GUI.Box(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), "Multi-editing is not supported.", new GUIStyle(EditorStyles.helpBox)); } } Separator(); ShowLayerFields(layerSerialized); bool stateSeparator = statesProperty.arraySize > 0; layerSerialized.ApplyModifiedProperties(); ShowStates(statesProperty, layer); if (stateSeparator) { Separator(); } EditorGUI.indentLevel -= 1; } EndBox(); }