Ejemplo n.º 1
0
        // ----------------
        private void AddAxesToRig()
        {
            // Check for already present axes...

            int    enabledAxisNum        = 0;
            int    alreadyPresentAxisNum = 0;
            string presentAxisNames      = "";

            for (int i = 0; i < this.axisList.Count; ++i)
            {
                if (!this.axisList[i].enabled)
                {
                    continue;
                }

                enabledAxisNum++;

                int axisId = 0;
                if (this.rig.IsAxisDefined(this.axisList[i].name, ref axisId))
                {
                    ++alreadyPresentAxisNum;

                    if (alreadyPresentAxisNum <= 10)
                    {
                        presentAxisNames += (((alreadyPresentAxisNum == 10) ? "..." : this.axisList[i].name) + "\n");
                    }
                }
            }

            bool overwriteAll      = false;
            bool igonrePresentAxes = false;

            if (alreadyPresentAxisNum > 0)
            {
                int overwriteMethod = EditorUtility.DisplayDialogComplex(DIALOG_TITLE, "" + alreadyPresentAxisNum + " out of " + enabledAxisNum +
                                                                         " selected axes are already present in selected Input Rig.\n\n" +
                                                                         presentAxisNames + "\n" + "What do you want to do with them?", "Overwrite All", "Ignore All", "Choose one by one");


                if (overwriteMethod == 1)
                {
                    igonrePresentAxes = true;
                }

                else if (overwriteMethod == 0)
                {
                    overwriteAll = true;
                }
            }


            // Apply...

            CFGUI.CreateUndo("Transfer axes from Input Manager to Input Rig", this.rig);

            for (int i = 0; i < this.axisList.Count; ++i)
            {
                AxisDescription axisDesc = this.axisList[i];
                if (!axisDesc.enabled)
                {
                    continue;
                }



                InputRig.AxisConfig axisConfig = this.rig.GetAxisConfig(axisDesc.name);

                if (axisConfig != null)
                {
                    if (igonrePresentAxes)
                    {
                        continue;
                    }

                    if (!overwriteAll && !EditorUtility.DisplayDialog(DIALOG_TITLE, "Transfer and overwrite [" + axisDesc.name + "] axis?", "Transfer", "Skip"))
                    {
                        continue;
                    }

                    axisConfig.axisType = axisDesc.targetAxisType;
                }
                else
                {
                    axisConfig = this.rig.axes.Add(axisDesc.name, axisDesc.targetAxisType, false);
                }


                axisConfig.keyboardNegative     = KeyCode.None;
                axisConfig.keyboardNegativeAlt0 = KeyCode.None;
                axisConfig.keyboardPositive     = KeyCode.None;
                axisConfig.keyboardPositiveAlt0 = KeyCode.None;

                axisConfig.scale = 1;
                axisConfig.digitalToAnalogDecelTime = 0;
                axisConfig.digitalToAnalogAccelTime = 0;
                axisConfig.smoothingTime            = 0;
                axisConfig.rawSmoothingTime         = 0;
                axisConfig.snap = false;

                for (int ai = 0; ai < axisDesc.inputAxes.Count; ++ai)
                {
                    UnityInputManagerUtils.InputAxis inputAxis = axisDesc.inputAxes[ai];

                    switch (inputAxis.type)
                    {
                    case UnityInputManagerUtils.AxisType.KeyOrMouseButton:
                        KeyCode
                            positiveCode    = InputRig.NameToKeyCode(!inputAxis.invert ? inputAxis.positiveButton : inputAxis.negativeButton),
                            positiveAltCode = InputRig.NameToKeyCode(!inputAxis.invert ? inputAxis.altPositiveButton : inputAxis.altNegativeButton),
                            negativeCode    = InputRig.NameToKeyCode(!inputAxis.invert ? inputAxis.negativeButton : inputAxis.positiveButton),
                            negativeAltCode = InputRig.NameToKeyCode(!inputAxis.invert ? inputAxis.altNegativeButton : inputAxis.altPositiveButton);

                        if ((positiveCode != KeyCode.None) && !UnityInputManagerUtils.IsJoystickKeyCode(positiveCode))
                        {
                            axisConfig.keyboardPositive    = positiveCode;
                            axisConfig.affectedKeyPositive = positiveCode;
                        }
                        if ((positiveAltCode != KeyCode.None) && !UnityInputManagerUtils.IsJoystickKeyCode(positiveAltCode))
                        {
                            axisConfig.keyboardPositiveAlt0 = positiveAltCode;
                        }

                        if ((negativeCode != KeyCode.None) && !UnityInputManagerUtils.IsJoystickKeyCode(negativeCode))
                        {
                            axisConfig.keyboardNegative    = negativeCode;
                            axisConfig.affectedKeyNegative = negativeCode;
                        }
                        if ((negativeAltCode != KeyCode.None) && !UnityInputManagerUtils.IsJoystickKeyCode(negativeAltCode))
                        {
                            axisConfig.keyboardNegativeAlt0 = negativeAltCode;
                        }


                        if (inputAxis.snap)
                        {
                            axisConfig.snap = true;
                        }

                        break;


                    case UnityInputManagerUtils.AxisType.JoystickAxis:
                        break;


                    case UnityInputManagerUtils.AxisType.MouseMovement:
                    {
                        // Mouse Delta...

                        if ((inputAxis.axis == UnityInputManagerUtils.MOUSE_X_AXIS_ID) ||
                            (inputAxis.axis == UnityInputManagerUtils.MOUSE_Y_AXIS_ID))
                        {
                            ControlFreak2.Internal.AxisBinding mouseDeltaBinding = (inputAxis.axis == UnityInputManagerUtils.MOUSE_X_AXIS_ID) ?
                                                                                   this.rig.mouseConfig.horzDeltaBinding : this.rig.mouseConfig.vertDeltaBinding;

                            mouseDeltaBinding.Clear();
                            mouseDeltaBinding.Enable();                                                   //.enabled = true;
                            mouseDeltaBinding.AddTarget().SetSingleAxis(axisDesc.name, inputAxis.invert); //, axisDesc.inputAxis.invert);

                            //mouseDeltaBinding.separateAxes = false;
                            //mouseDeltaBinding.singleAxis = axisDesc.name;

                            axisConfig.scale = inputAxis.sensitivity;
                        }

                        // Scroll wheel...

                        else if ((inputAxis.axis == UnityInputManagerUtils.SCROLL_PRIMARY_AXIS_ID) ||
                                 (inputAxis.axis == UnityInputManagerUtils.SCROLL_SECONDARY_AXIS_ID))
                        {
                            ControlFreak2.Internal.AxisBinding scrollBinding = (inputAxis.axis == UnityInputManagerUtils.SCROLL_PRIMARY_AXIS_ID) ?
                                                                               this.rig.scrollWheel.vertScrollDeltaBinding.deltaBinding : this.rig.scrollWheel.horzScrollDeltaBinding.deltaBinding;

                            scrollBinding.Clear();
                            scrollBinding.AddTarget().SetSingleAxis(axisDesc.name, inputAxis.invert);

                            //scrollBinding.enabled = true;
                            //scrollBinding.separateAxes = false;
                            //scrollBinding.singleAxis = axisDesc.name;
                        }
                    }
                    break;
                    }
                }

                // Set mouse delta scaling...

                if (axisDesc.targetAxisType == InputRig.AxisType.Delta)
                {
                    axisConfig.deltaMode = InputRig.DeltaTransformMode.EmulateMouse;
                    axisConfig.scale     = axisDesc.inputAxis.sensitivity;
                }

                // Convert gravity to smoothing time...

                else if ((axisDesc.targetAxisType == InputRig.AxisType.SignedAnalog) || (axisDesc.targetAxisType == InputRig.AxisType.UnsignedAnalog))
                {
                    float
                        gravity     = 0,
                        sensitivity = 0;

                    // Find biggest gravity and sensitivity...

                    for (int di = 0; di < axisDesc.inputAxes.Count; ++di)
                    {
                        if (axisDesc.inputAxes[di].type != UnityInputManagerUtils.AxisType.KeyOrMouseButton)
                        {
                            continue;
                        }

                        gravity     = Mathf.Max(gravity, axisDesc.inputAxes[di].gravity);
                        sensitivity = Mathf.Max(sensitivity, axisDesc.inputAxes[di].sensitivity);
                    }

                    // Convert graivty and sensitivity to digiAccel/Decel times...

                    axisConfig.digitalToAnalogDecelTime = ((gravity < 0.001f)               ? 0.2f : (1.0f / gravity));
                    axisConfig.digitalToAnalogAccelTime = ((sensitivity < 0.001f)   ? 0.2f : (1.0f / sensitivity));

                    axisConfig.smoothingTime    = 0;
                    axisConfig.rawSmoothingTime = 0;

                    //if (axisDesc.inputAxis.gravity > 0.1f)
                    //	axisConfig.smoothingTime = Mathf.Min(1.0f, (1.0f / axisDesc.inputAxis.gravity));
                }


                //if (axisDesc.inputAxis.invert)
                //	axisConfig.scale = -axisConfig.scale;
            }

            CFGUI.EndUndo(this.rig);
        }
Ejemplo n.º 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();
                }
            }