コード例 #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);
        }