// ---------------- 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); }
// --------------- 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(); } }
// ------------------- void OnGUI() { GUILayout.Box(GUIContent.none, CFEditorStyles.Inst.headerInstaller, GUILayout.ExpandWidth(true)); EditorGUILayout.Space(); GUILayout.Box("Welcome to <b>Control Freak 2</b>!", CFEditorStyles.Inst.centeredTextTranspBG, GUILayout.ExpandWidth(true)); //, GUILayout.ExpandHeight(true)); EditorGUILayout.Space(); CFGUI.BeginIndentedVertical(CFEditorStyles.Inst.transpSunkenBG); DrawFeatureBox(this.inputAxesPresent, "Input Axes Present!", "Input Axes are missing or are incomplete! (Click INSTALL)"); //DrawFeatureBox(this.defineSymbolsPresent, "Scripting Symbols Defined!", "Scripting Symbols are not defined for all platforms! (Click INSTALL)"); if (CFProjPrefs.Inst.isIsntalled) { this.platformOptionList.DrawForceMobileModeButton(); } CFGUI.EndIndentedVertical(); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Install", "Clicking this button will:\n\n" + "* Add default CF2 scripting define symbols.\n\n" + "* Setup \'Forced Mobile Mode\' on all mobile platforms.\n\n" + "* Add CF2 Input Axes to Unity Input Manager (without removing existing axes).\n"), CFEditorStyles.Inst.installerButton)) { this.Install(); this.Close(); } if (GUILayout.Button(new GUIContent("Uninstall", "Clicking this button will:\n\n" + "* Remove all CF2-related define symbols.\n\n" + "* Remove CF2 Axes from Unity Input Manager.\n"), CFEditorStyles.Inst.installerButton)) { this.Uninstall(); this.Close(); } GUILayout.Space(20); if (GUILayout.Button(new GUIContent("Install Add-Ons..."), CFEditorStyles.Inst.installerButton)) { this.ShowAddOnMenu(); } GUILayout.Space(20); if (GUILayout.Button("View Online Documentation.", CFEditorStyles.Inst.installerButton)) { Application.OpenURL(ONLINE_DOCS_URL); } if (GUILayout.Button("View Video Tutorials on YouTube.", CFEditorStyles.Inst.installerButton)) { Application.OpenURL(VIDEO_TUTORIALS_URL); } if (GUILayout.Button("View Our Website.", CFEditorStyles.Inst.installerButton)) { Application.OpenURL(WEBSITE_URL); } }
// ----------------------- void OnGUI() { const float BUTTON_HEIGHT = 30; const float TOOLBAR_HEIGHT = 34; const float PROP_BOX_BUTTON_HEIGHT = 20; const float MAX_PROP_BOX_HEIGHT = 300; const float ENTRY_LIST_REL_HEIGHT = 0.55f; float entryListHeight = (this.position.height - TOOLBAR_HEIGHT) - PROP_BOX_BUTTON_HEIGHT - 100; float propBoxHeight = Mathf.Min((MAX_PROP_BOX_HEIGHT), (entryListHeight * (1.0f - ENTRY_LIST_REL_HEIGHT))); GUILayout.Box(GUIContent.none, CFEditorStyles.Inst.headerAssistant, GUILayout.ExpandWidth(true)); EditorGUILayout.BeginHorizontal(CFEditorStyles.Inst.toolbarBG); this.recordingOn = CFGUI.PushButton( new GUIContent("Capture in progress!", CFEditorStyles.Inst.greenDotTex, "Editor must be in Play mode to catch Input calls!"), new GUIContent("Stopped. Press to begin capture", CFEditorStyles.Inst.pauseTex, "Editor must be in Play mode to catch Input calls!"), this.recordingOn, CFEditorStyles.Inst.buttonStyle, GUILayout.Height(BUTTON_HEIGHT), GUILayout.ExpandWidth(true)); GUI.backgroundColor = (Color.white); if (GUILayout.Button("Clear", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(70))) { this.ClearEntries(); } EditorGUILayout.EndHorizontal(); if (this.selectedRig == null) { EditorGUILayout.HelpBox("No rig selected!! Select one to be able to easily create controls or bind commands!", MessageType.Warning); } else { EditorGUILayout.HelpBox("Rig: " + this.selectedRig.name, MessageType.None); } if (!CFUtils.editorStopped && (this.logEntries.Count > 0)) { EditorGUILayout.HelpBox("Remember to stop Editor before binding or creating controls!", MessageType.Warning); } this.scrollPos = EditorGUILayout.BeginScrollView(this.scrollPos, CFEditorStyles.Inst.transpSunkenBG, GUILayout.ExpandHeight(true)); //GUILayout.Height(entryListHeight)); if (this.logEntries.Count == 0) { GUILayout.Box("Nothing captured yet!" + (CFUtils.editorStopped ? "\nTo capture anything hit the PLAY button!" : ""), CFEditorStyles.Inst.centeredTextTranspBG); } else { for (int i = this.logEntries.Count - 1; i >= 0; --i) { //GUILayout.Label("[" + i + "] : " + this.logEntries[i].ToString()); this.logEntries[i].DrawListElemGUI(this); } } EditorGUILayout.EndScrollView(); if (this.selectedEntry != null) { this.propBoxOn = CFGUI.PushButton( new GUIContent("Hide Properties", CFEditorStyles.Inst.texMoveDown), new GUIContent("Show Properties", CFEditorStyles.Inst.texMoveUp), this.propBoxOn, CFEditorStyles.Inst.buttonStyle); if (this.propBoxOn) { this.propBoxScroll = EditorGUILayout.BeginScrollView(this.propBoxScroll, CFEditorStyles.Inst.transpSunkenBG, GUILayout.Height(propBoxHeight)); this.selectedEntry.DrawPropertiesGUI(); EditorGUILayout.EndScrollView(); } } }