private void DrawRootController() { AnimatorGroup animatorGroup = DrawGroupDropdown(); ActionSet actionSet = DrawActionSetDropdown(animatorGroup); if (null != actionSet) { foreach (CombinedAnimatorState state in actionSet.States) { GUILayout.Label(state.Layer.name); if (state.StateMachine != null) { DrawAnimatorStateMachine(state.StateMachine, false); } else if (state.AnimatorState != null) { DrawAnimatorState(state.AnimatorState, false); } } } }
private void Index() { m_AnimatorGroups.Clear(); if (m_AnimatorController != null) { foreach (AnimatorControllerLayer layer in m_AnimatorController.layers) { m_Layers[layer.name] = layer; CombinedAnimatorState layerState = AddState(layer.stateMachine, null, layer, null, false); foreach (ChildAnimatorStateMachine stateMachine in layerState.ChildStateMachines) { CombinedAnimatorState groupState = AddState(stateMachine.stateMachine, layerState, layer, null, false); AnimatorGroup group = CollectionUtil.GetOrAdd(m_AnimatorGroups, stateMachine.stateMachine.name); group.Name = stateMachine.stateMachine.name; group.AddLayer(layer); foreach (ChildAnimatorStateMachine actionMachine in stateMachine.stateMachine.stateMachines) { ActionSet actionSet = CollectionUtil.GetOrAdd(group.Actions, actionMachine.stateMachine.name); actionSet.Name = actionMachine.stateMachine.name; actionSet.Layers[layer.name] = layer; CombinedAnimatorState state = AddState(actionMachine.stateMachine, groupState, layer, actionSet); actionSet.States.Add(state); } foreach (ChildAnimatorState actionState in stateMachine.stateMachine.states) { ActionSet actionSet = CollectionUtil.GetOrAdd(group.Actions, actionState.state.name); actionSet.Name = actionState.state.name; actionSet.Layers[layer.name] = layer; CombinedAnimatorState state = AddState(actionState.state, groupState, layer, actionSet); actionSet.States.Add(state); m_States[actionState.state] = state; } } } } }
private ActionSet DrawActionSetDropdown(AnimatorGroup animatorGroup) { ActionSet actionSet = null; GUILayout.BeginHorizontal(); { GUILayout.Label("Action", GUILayout.Width(100)); string[] names = animatorGroup.Actions.Keys.ToArray(); selectedAction = Math.Max(0, selectedAction); if (names.Length == 0 || !animatorGroup.Actions.ContainsKey(names[selectedAction])) { GUILayout.Label("No actions created."); } else { selectedAction = EditorGUILayout.Popup(selectedAction, names); actionSet = animatorGroup.Actions[names[selectedAction]]; } if (m_AddActionHidden && GUILayout.Button("+", InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(16), GUILayout.Height(16))) { m_AddActionHidden = false; foreach (AnimatorControllerLayer layer in animatorGroup.Layers.Values) { string key = "add-action-toggle-" + layer.name; m_Toggles[key] = true; } } else if (!m_AddActionHidden && GUILayout.Button("-", InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(16), GUILayout.Height(16))) { m_AddActionHidden = true; } } GUILayout.EndHorizontal(); if (!m_AddActionHidden) { GUILayout.BeginHorizontal(); { GUILayout.Space(110); GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { GUILayout.Label("Action Name:", GUILayout.Width(75)); m_AddActionName = GUILayout.TextField(m_AddActionName); if (GUILayout.Button("Add", GUILayout.Width(60))) { foreach (AnimatorControllerLayer layer in m_AnimatorController.layers) { string key = "add-action-toggle-" + layer.name; bool toggle = CollectionUtil.GetOrAdd(m_Toggles, key, false); if (toggle) { AnimatorStateMachine stateMachine = AnimUtil.AddStateMachineToLayer(layer, animatorGroup.Name); AnimatorState state = AnimUtil.AddStateToStateMachine(stateMachine, m_AddActionName); state.motion = m_Motion; } } Index(); string[] actions = animatorGroup.Actions.Keys.ToArray(); selectedAction = Array.IndexOf(actions, m_AddActionName); m_AddActionHidden = true; m_AddGroupHidden = true; m_AddActionName = ""; } } GUILayout.EndHorizontal(); m_Motion = (Motion)EditorGUILayout.ObjectField("Motion", m_Motion, typeof(Motion)); foreach (AnimatorControllerLayer layer in m_AnimatorController.layers) { string key = "add-action-toggle-" + layer.name; bool toggle = CollectionUtil.GetOrAdd(m_Toggles, key, false); m_Toggles[key] = GUILayout.Toggle(toggle, layer.name); } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } return(actionSet); }