void ShowAddSubLayer(StateLayer parent, Rect rect) { layerTypesName[0] = "Add"; if (Selection.gameObjects.Length <= 1) { rect.x = Screen.width - 72 - EditorGUI.indentLevel * 16; rect.y += 1; rect.width = 36 + EditorGUI.indentLevel * 16; EditorGUI.BeginDisabledGroup(Application.isPlaying); GUIStyle style = new GUIStyle("MiniToolbarPopup"); style.fontStyle = FontStyle.Bold; style.alignment = TextAnchor.MiddleCenter; int layerTypeIndex = EditorGUI.Popup(rect, layerTypes.IndexOf(selectedLayerType) + 1, layerTypesName.ToArray(), style) - 1; selectedLayerType = layerTypeIndex == -1 ? null : layerTypes[Mathf.Clamp(layerTypeIndex, 0, layerTypes.Count - 1)]; if (selectedLayerType != null) { StateMachineUtility.AddLayer(machine, selectedLayerType, parent); selectedLayerType = null; } EditorGUI.EndDisabledGroup(); } }
void ShowAddLayer() { layerTypes = new List <Type>(); layerTypesName = new List <string> { "Add Layer" }; foreach (Type layerType in StateMachineUtility.LayerStateDict.Keys) { if (Array.TrueForAll(existingLayers, layer => layer.GetType() != layerType)) { layerTypes.Add(layerType); layerTypesName.Add(StateMachineUtility.LayerTypeNameDict[layerType]); } } if (Selection.gameObjects.Length <= 1) { EditorGUI.BeginDisabledGroup(Application.isPlaying); GUIStyle style = new GUIStyle("popup"); style.fontStyle = FontStyle.Bold; style.alignment = TextAnchor.MiddleCenter; int layerTypeIndex = EditorGUILayout.Popup(layerTypes.IndexOf(selectedLayerType) + 1, layerTypesName.ToArray(), style) - 1; selectedLayerType = layerTypeIndex == -1 ? null : layerTypes[Mathf.Clamp(layerTypeIndex, 0, layerTypes.Count - 1)]; EditorGUI.EndDisabledGroup(); if (selectedLayerType != null) { StateMachineUtility.AddLayer(machine, selectedLayerType, machine); selectedLayerType = null; } } else { GUI.Box(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), "Multi-editing is not supported.", new GUIStyle(EditorStyles.helpBox)); } }