Example #1
0
        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);
        }
Example #2
0
        private AnimatorGroup DrawGroupDropdown()
        {
            AnimatorGroup animatorGroup;

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Group", GUILayout.Width(100));
                string[] names = m_AnimatorGroups.Keys.ToArray();
                selectedAnimatorGroup = Math.Min(names.Length - 1, selectedAnimatorGroup);
                selectedAnimatorGroup = EditorGUILayout.Popup(selectedAnimatorGroup, names);
                animatorGroup         = m_AnimatorGroups[names[selectedAnimatorGroup]];
                if (m_AddGroupHidden && GUILayout.Button("+", InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(16), GUILayout.Height(16)))
                {
                    m_AddGroupHidden = false;
                }
                else if (!m_AddGroupHidden && GUILayout.Button("-", InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(16), GUILayout.Height(16)))
                {
                    m_AddGroupHidden = true;
                }
            }
            GUILayout.EndHorizontal();

            if (!m_AddGroupHidden)
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(110);
                    GUILayout.BeginVertical();
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Label("Group Name:", GUILayout.Width(75));
                            m_AddGroupName = GUILayout.TextField(m_AddGroupName);
                            if (GUILayout.Button("Add", GUILayout.Width(60)))
                            {
                                foreach (AnimatorControllerLayer layer in m_AnimatorController.layers)
                                {
                                    string key    = "add-group-toggle-" + layer.name;
                                    bool   toggle = CollectionUtil.GetOrAdd(m_Toggles, key, false);
                                    if (toggle)
                                    {
                                        AnimUtil.AddStateMachineToLayer(layer, m_AddGroupName);
                                    }
                                }
                                Index();
                                string[] keys = m_AnimatorGroups.Keys.ToArray();
                                selectedAnimatorGroup = Array.IndexOf(keys, m_AddGroupName);
                                animatorGroup         = m_AnimatorGroups[m_AddGroupName];
                                m_AddGroupHidden      = true;
                                m_AddGroupName        = "";
                                m_AddActionHidden     = true;
                            }
                        }
                        GUILayout.EndHorizontal();

                        foreach (AnimatorControllerLayer layer in m_AnimatorController.layers)
                        {
                            string key    = "add-group-toggle-" + layer.name;
                            bool   toggle = CollectionUtil.GetOrAdd(m_Toggles, key, false);
                            m_Toggles[key] = GUILayout.Toggle(toggle, layer.name);
                        }
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }

            return(animatorGroup);
        }