Example #1
0
            // ------------------
            static private void AddAnalogBindingAxisSubMenu(GenericMenu menu, string axis, BindingDescription desc, System.Action onRefreshCallback)
            {
                AxisBinding bind = (AxisBinding)desc.binding;

                string menuPath = desc.menuPath + desc.nameFormatted + "/";

                for (int i = -1; i < bind.targetList.Count; ++i)
                {
                    string menuItemPath = "";

                    AxisBinding.TargetElem axisElem = bind.GetTarget(i);

                    if (i < 0)
                    {
                        menuItemPath = menuPath + "Add as new axis target/";
                    }
                    else
                    {
                        if (axisElem.separateAxes)
                        {
                            menuItemPath = menuPath + "Replace separated(+,-) " +
                                           (string.IsNullOrEmpty(axisElem.positiveAxis) ? "EMPTY" : ("\"" + axisElem.positiveAxis + "\"" +
                                                                                                     (axisElem.positiveAxisAsPositive ? "" : " (as negative)"))) +
                                           " : " +
                                           (string.IsNullOrEmpty(axisElem.negativeAxis) ? "EMPTY" : ("\"" + axisElem.negativeAxis + "\"" +
                                                                                                     (axisElem.negativeAxisAsPositive ? "(as positive)" : ""))) +
                                           " (" + i + ")/";
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(axisElem.singleAxis))
                            {
                                menuItemPath = menuPath + "Replace single EMPTY (" + i + ")/";
                            }
                            else
                            {
                                menuItemPath = menuPath + "Replace single \"" + axisElem.singleAxis + "\"" + (axisElem.reverseSingleAxis ? " (Flipped)" : "") + " (" + i + ")/";
                            }
                        }
                    }

                    for (int targetModeIndex = 0; targetModeIndex < 6; ++targetModeIndex)
                    {
                        UniversalBindingAssignment o = new UniversalBindingAssignment();

                        o.undoLabel         = "Bind " + axis + " axis to " + desc.name;
                        o.undoObject        = desc.undoObject;
                        o.binding           = desc.binding;
                        o.onRefreshCallback = onRefreshCallback;
                        o.analogAxisName    = axis;
                        o.analogElemId      = i;

                        string modeName = "";

                        switch (targetModeIndex)
                        {
                        case 0:
                            modeName         = "Single";
                            o.analogSeparate = false;
                            o.analogFlip     = false;
                            break;

                        case 1:
                            modeName         = "Single (Flipped)";
                            o.analogSeparate = false;
                            o.analogFlip     = true;
                            break;

                        case 2:
                            modeName             = "Separated, Positive Side";
                            o.analogSeparate     = true;
                            o.analogPositiveSide = true;
                            o.analogFlip         = false;
                            break;

                        case 3:
                            modeName             = "Separated, Positive Side (Flipped)";
                            o.analogSeparate     = true;
                            o.analogPositiveSide = true;
                            o.analogFlip         = true;
                            break;

                        case 4:
                            modeName             = "Separated, Negative Side";
                            o.analogSeparate     = true;
                            o.analogPositiveSide = false;
                            o.analogFlip         = false;
                            break;

                        case 5:
                            modeName             = "Separated, Negative Side (Flipped)";
                            o.analogSeparate     = true;
                            o.analogPositiveSide = false;
                            o.analogFlip         = true;
                            break;
                        }


                        menu.AddItem(new GUIContent(menuItemPath + modeName), false, o.Execute);

                        if ((targetModeIndex & 1) == 1)
                        {
                            menu.AddSeparator(menuItemPath);
                        }
                    }


                    if ((i < 0) && (bind.targetList.Count > 0))
                    {
                        menu.AddSeparator(menuPath);
                    }
                }
            }
Example #2
0
            // ---------------
            public void Execute()
            {
                if (this.binding == null)
                {
                    return;
                }

                CFGUI.CreateUndo(this.undoLabel, this.undoObject);

                DigitalBinding       digiBinding   = (this.binding as DigitalBinding);
                AxisBinding          analogBinding = (this.binding as AxisBinding);
                EmuTouchBinding      touchBinding  = (this.binding as EmuTouchBinding);
                MousePositionBinding mouseBinding  = (this.binding as MousePositionBinding);

                //JoystickNameBinding		joyNameBinding	= (this.binding as JoystickNameBinding);

                // Digi binding...

                if (digiBinding != null)
                {
                    if (this.digiKey != KeyCode.None)
                    {
                        digiBinding.Enable();

                        if (this.digiKeyElemId < 0)
                        {
                            digiBinding.AddKey(this.digiKey);
                        }
                        else
                        {
                            digiBinding.ReplaceKey(this.digiKeyElemId, this.digiKey);
                        }
                    }

                    if (!string.IsNullOrEmpty(this.digiAxisName))
                    {
                        digiBinding.Enable();

                        DigitalBinding.AxisElem elem = null;


                        if (this.digiAxisElemId < 0)
                        {
                            elem = digiBinding.AddAxis();
                        }
                        else
                        {
                            elem = digiBinding.GetAxisElem(this.digiAxisElemId);
                        }

                        if (elem != null)
                        {
                            elem.SetAxis(this.digiAxisName, this.digiBindToPositiveAxis);
                        }
                    }
                }


                // Analog Binding...

                else if (analogBinding != null)
                {
                    if (!string.IsNullOrEmpty(this.analogAxisName))
                    {
                        analogBinding.Enable();

                        AxisBinding.TargetElem elem = null;

                        if (this.analogElemId < 0)
                        {
                            elem = analogBinding.AddTarget();
                        }
                        else
                        {
                            elem = analogBinding.GetTarget(this.analogElemId);
                        }

                        if (elem != null)
                        {
                            if (this.analogSeparate)
                            {
                                elem.SetSeparateAxis(this.analogAxisName, this.analogPositiveSide, !this.analogFlip);
                            }
                            else
                            {
                                elem.SetSingleAxis(this.analogAxisName, this.analogFlip);
                            }
                        }
                    }
                }

                // Touch Binding...

                else if (touchBinding != null)
                {
                    touchBinding.Enable();
                }

                // Mouse Binding...

                else if (mouseBinding != null)
                {
                    mouseBinding.Enable();
                }


                CFGUI.EndUndo(this.undoObject);

                if (this.onRefreshCallback != null)
                {
                    this.onRefreshCallback();
                }
            }