Example #1
0
        // ---------------------
        void OnEnable()
        {
            this.Repaint();

            this.inputAxesPresent     = UnityInputManagerUtils.AreControlFreakAxesPresent();
            this.defineSymbolsPresent = ConfigManager.AreControlFreakSymbolsDefined();

            this.playmakerPresent =
                ((CFEditorUtils.FindClass("HutongGames.PlayMaker.FsmStateAction") != null));

            this.controlFreak1Present =
                ((CFEditorUtils.FindClass("TouchController") != null) &&
                 (CFEditorUtils.FindClass("TouchStick") != null) &&
                 (CFEditorUtils.FindClass("TouchZone") != null) &&
                 (CFEditorUtils.FindClass("CFInput") != null));

            //this.evpPresent	=
            //	((CFEditorUtils.FindClass("EVP.VehicleController") != null));

            this.opsiveTpcPresent =
                (CFEditorUtils.FindClass("Opsive.ThirdPersonController.Wrappers.RigidbodyCharacterController") != null) ||
                (CFEditorUtils.FindClass("Opsive.ThirdPersonController.RigidbodyCharacterController") != null);

            this.newUfePresent =
                ((CFEditorUtils.FindClass("UFEController") != null) &&
                 (CFEditorUtils.FindClass("InputTouchControllerBridge") != null));

            this.oldUfePresent =
                ((CFEditorUtils.FindClass("UFEController") != null) &&
                 (CFEditorUtils.FindClass("InputTouchControllerBridge") == null));


            this.platformOptionList.Refresh();
        }
Example #2
0
        // --------------------
        bool Install()
        {
            try
            {
                EditorUtility.DisplayProgressBar(DIALOG_TITLE, "Adding CF2 Input Manager axes...", 0.1f);
                UnityInputManagerUtils.AddControlFreakAxes();

                EditorUtility.DisplayProgressBar(DIALOG_TITLE, "Adding Define Symbols...", 0.6f);
                ConfigManager.AddDefaultControlFreakSymbols();


                // Save config...

                EditorUtility.DisplayProgressBar(DIALOG_TITLE, "Saving...", 0.8f);

                CFProjPrefs prefs = CFProjPrefs.Inst;

                prefs.wasShown     = true;
                prefs.installedVer = CF2_INSTALLER_VERSION;
                prefs.projectPath  = Application.dataPath;
                prefs.isIsntalled  = true;

                prefs.Save();

                //Debug.Log("Saved!");
                prefs = CFProjPrefs.Inst;
                //Debug.Log("reloaded : " + prefs.isIsntalled + " ver:" + prefs.installedVer);


                // Recompile scripts...

                AssetDatabase.Refresh();


                EditorUtility.ClearProgressBar();
            }
            catch (System.Exception e)
            {
                EditorUtility.ClearProgressBar();
                EditorUtility.DisplayDialog(DIALOG_TITLE, "Something went wrong during installation!\n" + e.Message, "OK");
                return(false);
            }

            return(true);
        }
Example #3
0
        // -------------------
        public void InitDialog(InputRig rig)
        {
            this.rig = rig;

            // Add axes...

            UnityInputManagerUtils.InputAxisList inputAxisList = UnityInputManagerUtils.LoadInputManagerAxes();

            for (int i = 0; i < inputAxisList.Count; ++i)
            {
                if (inputAxisList[i].name.StartsWith("cf"))
                {
                    continue;
                }

                UnityInputManagerUtils.InputAxis inputAxis = inputAxisList[i];

                AxisDescription axisDesc = this.FindDescription(inputAxis);

                if (axisDesc == null)
                {
                    axisDesc = new AxisDescription(inputAxis);

                    int axisId = 0;

                    axisDesc.enabled           = true;
                    axisDesc.wasAlreadyDefined = rig.IsAxisDefined(inputAxis.name, ref axisId);

                    if (inputAxis.name.Equals("Submit", System.StringComparison.OrdinalIgnoreCase) ||
                        inputAxis.name.Equals("Cancel", System.StringComparison.OrdinalIgnoreCase))
                    {
                        axisDesc.enabled = false;
                    }


                    this.axisList.Add(axisDesc);
                }
                else
                {
                    axisDesc.inputAxes.Add(inputAxis);
                }
            }
        }
Example #4
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);
        }