예제 #1
0
        void DrawInputActionFields(Rect position, InputAction action)
        {
            bool  collectionChanged = false;
            float viewRectHeight    = CalculateInputActionViewRectHeight(action);
            float itemPosY          = 0.0f;
            float contentWidth      = position.width - 10.0f;
            Rect  viewRect          = new Rect(-5.0f, -5.0f, position.width - 10.0f, viewRectHeight - 10.0f);

            if (viewRect.width < MIN_MAIN_PANEL_WIDTH)
            {
                viewRect.width = MIN_MAIN_PANEL_WIDTH;
                contentWidth   = viewRect.width - 10.0f;
            }

            if (viewRectHeight - 10.0f > position.height)
            {
                viewRect.width -= SCROLL_BAR_WIDTH;
                contentWidth   -= SCROLL_BAR_WIDTH;
            }

            InputManagerWindow.m_mainPanelScrollPos = GUI.BeginScrollView(position, InputManagerWindow.m_mainPanelScrollPos, viewRect);
            Rect nameRect        = new Rect(0.0f, ValuePP(ref itemPosY, INPUT_FIELD_HEIGHT + FIELD_SPACING), contentWidth, INPUT_FIELD_HEIGHT);
            Rect displayNameRect = new Rect(0.0f, ValuePP(ref itemPosY, INPUT_FIELD_HEIGHT + FIELD_SPACING), contentWidth, INPUT_FIELD_HEIGHT);

            string name = EditorGUI.TextField(nameRect, "Name", action.Name);

            if (name != action.Name)
            {
                action.Name = name;                                             //	This prevents the warning at runtime
            }
            action.displayName = EditorGUI.TextField(displayNameRect, "Display Name", action.displayName);

            if (action.bindings.Count > 0)
            {
                itemPosY += INPUT_ACTION_SPACING;

                for (int i = 0; i < action.bindings.Count; i++)
                {
                    float bindingRectHeight = CalculateInputBindingViewRectHeight(action.bindings[i]);
                    Rect  bindingRect       = new Rect(-4.0f, ValuePP(ref itemPosY, bindingRectHeight + INPUT_BINDING_SPACING), contentWidth + 8.0f, bindingRectHeight);

                    var res = DrawInputBindingFields(bindingRect, "Binding " + (i + 1).ToString("D2"), action, i);
                    if (res == CollectionAction.Add)
                    {
                        InsertNewBinding(action, i + 1);
                        collectionChanged = true;
                    }
                    else if (res == CollectionAction.Remove)
                    {
                        int index = i--;

                        if (index >= 0 && index < action.bindings.Count)
                        {
                            action.bindings.RemoveAt(index);
                        }


                        collectionChanged = true;
                    }
                    else if (res == CollectionAction.MoveUp)
                    {
                        SwapBindings(action, i, i - 1);
                        collectionChanged = true;
                    }
                    else if (res == CollectionAction.MoveDown)
                    {
                        SwapBindings(action, i, i + 1);
                        collectionChanged = true;
                    }
                }
            }
            else
            {
                Rect buttonRect = new Rect(contentWidth / 2 - 125.0f, itemPosY + INPUT_ACTION_SPACING, 250.0f, BUTTON_HEIGHT);
                if (GUI.Button(buttonRect, "Add New Binding"))
                {
                    action.CreateNewBinding();
                    collectionChanged = true;
                }
            }

            GUI.EndScrollView();

            if (collectionChanged)
            {
                InputManagerWindow.instance.Repaint();
            }
        }