private static void InsertMappings() { for (int nJoystickIndex = 0; nJoystickIndex < 12; ++nJoystickIndex) { // build the joystick index string szJoystick = JoystickHeader; if (nJoystickIndex > 0) { szJoystick += nJoystickIndex.ToString(); } for (int nAxisIndex = 0; nAxisIndex < 28; ++nAxisIndex) { // build the axis index string szAxis = AxisHeader + nAxisIndex.ToString(); string szFinal = szJoystick + szAxis; InputAxis newAxis = new InputAxis(); newAxis.name = szFinal; newAxis.type = AxisType.JoystickAxis; newAxis.joyNum = nJoystickIndex; newAxis.axis = nAxisIndex + 1; newAxis.gravity = 0; newAxis.dead = 0.19f; newAxis.sensitivity = 1.0f; AxisList.Add(newAxis); } } }
private static void AddAxis(InputAxis axis) { if (AxisDefined(axis.name)) { return; } SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]); SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes"); axesProperty.arraySize++; serializedObject.ApplyModifiedProperties(); SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1); GetChildProperty(axisProperty, "m_Name").stringValue = axis.name; GetChildProperty(axisProperty, "descriptiveName").stringValue = axis.descriptiveName; GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName; GetChildProperty(axisProperty, "negativeButton").stringValue = axis.negativeButton; GetChildProperty(axisProperty, "positiveButton").stringValue = axis.positiveButton; GetChildProperty(axisProperty, "altNegativeButton").stringValue = axis.altNegativeButton; GetChildProperty(axisProperty, "altPositiveButton").stringValue = axis.altPositiveButton; GetChildProperty(axisProperty, "gravity").floatValue = axis.gravity; GetChildProperty(axisProperty, "dead").floatValue = axis.dead; GetChildProperty(axisProperty, "sensitivity").floatValue = axis.sensitivity; GetChildProperty(axisProperty, "snap").boolValue = axis.snap; GetChildProperty(axisProperty, "invert").boolValue = axis.invert; GetChildProperty(axisProperty, "type").intValue = (int)axis.type; GetChildProperty(axisProperty, "axis").intValue = axis.axis - 1; GetChildProperty(axisProperty, "joyNum").intValue = axis.joyNum; serializedObject.ApplyModifiedProperties(); }
/// <summary> /// プレイヤーごとの入力設定を追加する /// </summary> /// <param name="inputManagerGenerator">Input manager generator.</param> /// <param name="playerIndex">Player index.</param> private static void AddPlayerInputSettings(InputManagerGenerator inputManagerGenerator, int playerIndex) { if (playerIndex < 0 || playerIndex > 3) { Debug.LogError("プレイヤーインデックスの値が不正です。"); } string upKey = "", downKey = "", leftKey = "", rightKey = "", attackKey = ""; GetAxisKey(out upKey, out downKey, out leftKey, out rightKey, out attackKey, playerIndex); int joystickNum = playerIndex + 1; // 横方向 { var name = string.Format("Player{0} Horizontal", playerIndex); inputManagerGenerator.AddAxis(InputAxis.CreatePadAxis(name, joystickNum, 1)); inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, leftKey, rightKey, "", "")); } // 縦方向 { var name = string.Format("Player{0} Vertical", playerIndex); inputManagerGenerator.AddAxis(InputAxis.CreatePadAxis(name, joystickNum, 2)); inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, downKey, upKey, "", "")); } // 攻撃 { var axis = new InputAxis(); var name = string.Format("Player{0} Attack", playerIndex); var button = string.Format("joystick {0} button 0", joystickNum); inputManagerGenerator.AddAxis(InputAxis.CreateButton(name, button, attackKey)); } }
public void ChangeInput(int gravityDirectionValue) { GravityDirection gravityDirection = (GravityDirection)gravityDirectionValue; switch (gravityDirection) { case GravityDirection.Up: _inputAxis = InputAxis.Horizontal; _directionMultiplier = -1; break; case GravityDirection.Down: _inputAxis = InputAxis.Horizontal; _directionMultiplier = 1; break; case GravityDirection.Right: _inputAxis = InputAxis.Vertical; _directionMultiplier = -1; break; case GravityDirection.Left: _inputAxis = InputAxis.Vertical; _directionMultiplier = 1; break; default: break; } }
public static string GetActionName(this InputAxis axis, AxisDirection direction) { switch (axis) { case InputAxis.Horizontal: switch (direction) { case AxisDirection.Positive: return("gameplay_right"); case AxisDirection.Negative: return("gameplay_left"); default: throw new NotImplementedException("Missing AxisDirection " + direction.ToString()); } case InputAxis.Vertical: switch (direction) { case AxisDirection.Positive: return("gameplay_down"); case AxisDirection.Negative: return("gameplay_up"); default: throw new NotImplementedException("Missing AxisDirection " + direction.ToString()); } default: throw new NotImplementedException("Missing InputAxis " + axis.ToString()); } }
private void updateSelectedIndex() { int prevIndex = this.selectedIndex; for (int i = 0; i < this.inventoryCapacity; i++) { InputAxis slotInput = this.inventorySlots[i]; if (slotInput.positiveDown()) { this.selectedIndex = i; break; } } if (this.inventory[this.selectedIndex] == null) { if (this.inventory[prevIndex] != null) { this.selectedIndex = prevIndex; } else { this.selectedIndex = 0; } } }
private void Update() { UpdateEvent?.Invoke(); // ButtonPresses if (Input.GetKeyDown(KeyCode.LeftShift)) { ClickShift?.Invoke(); } if (Input.GetKeyDown(KeyCode.Escape)) { ClickEsc?.Invoke(); } if (Input.GetKeyDown(KeyCode.F10)) { ClickF10?.Invoke(); } // Axis input var horizontalAxis = Input.GetAxisRaw("Horizontal"); var verticalAxis = Input.GetAxisRaw("Vertical"); Vector2 axis = new Vector2(horizontalAxis, verticalAxis); if (horizontalAxis != 0f || verticalAxis != 0f) { InputAxis?.Invoke(axis); } else if (horizontalAxis == 0f && verticalAxis == 0f && (previousInputAxis.x != 0f || previousInputAxis.y != 0f)) { InputAxisRelease?.Invoke(); } previousInputAxis = axis; }
public override float GetAxis(XRNodeState node, InputAxis axis) { var controller = GetController(node); OVRPlugin.ControllerState4 state = OVRPlugin.GetControllerState4((uint)controller); switch (axis) { case InputAxis.LeftClick: return(controller == OVRInput.Controller.LTouch ? state.LIndexTrigger : state.RIndexTrigger); case InputAxis.RightClick: return(controller == OVRInput.Controller.LTouch ? state.LHandTrigger : state.RHandTrigger); case InputAxis.MiddleClick: { var buttonId = controller == OVRInput.Controller.LTouch ? 0x00000400 : 0x00000004; //see enum ovrButton_ in OVR_CAPI.h return((state.Buttons & buttonId) != 0 ? 1 : 0); } case InputAxis.JoyStickX: case InputAxis.JoyStickY: { var joy = controller == OVRInput.Controller.LTouch ? state.LThumbstick : state.RThumbstick; return(axis == InputAxis.JoyStickX ? joy.x : joy.y); } default: return(0); } }
public static void AddAxis(InputAxis axis) { if (AxisDefined(axis.name, axis.positiveButton)) { return; } var inputsDatabase = GetInputsDatabase(); var axesProperty = GetAllInputs(inputsDatabase); axesProperty.arraySize++; inputsDatabase.ApplyModifiedProperties(); SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1); GetChildProperty(axisProperty, "m_Name").stringValue = axis.name; GetChildProperty(axisProperty, "descriptiveName").stringValue = axis.descriptiveName; GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName; GetChildProperty(axisProperty, "negativeButton").stringValue = axis.negativeButton; GetChildProperty(axisProperty, "positiveButton").stringValue = axis.positiveButton; GetChildProperty(axisProperty, "altNegativeButton").stringValue = axis.altNegativeButton; GetChildProperty(axisProperty, "altPositiveButton").stringValue = axis.altPositiveButton; GetChildProperty(axisProperty, "gravity").floatValue = axis.gravity; GetChildProperty(axisProperty, "dead").floatValue = axis.dead; GetChildProperty(axisProperty, "sensitivity").floatValue = axis.sensitivity; GetChildProperty(axisProperty, "snap").boolValue = axis.snap; GetChildProperty(axisProperty, "invert").boolValue = axis.invert; GetChildProperty(axisProperty, "type").intValue = (int)axis.type; GetChildProperty(axisProperty, "axis").intValue = axis.axis - 1; GetChildProperty(axisProperty, "joyNum").intValue = axis.joyNum; inputsDatabase.ApplyModifiedProperties(); }
protected override float GetAxisValue(XRNodeState node, InputAxis axis) { var controller = GetController(node); OVRPlugin.ControllerState4 state = OVRPlugin.GetControllerState4((uint)controller); switch (axis) { case InputAxis.MainTrigger: return(controller == OVRInput.Controller.LTouch ? state.LIndexTrigger : state.RIndexTrigger); case InputAxis.Grip: return(controller == OVRInput.Controller.LTouch ? state.LHandTrigger : state.RHandTrigger); case InputAxis.JoypadX: case InputAxis.JoypadY: { var joy = controller == OVRInput.Controller.LTouch ? state.LThumbstick : state.RThumbstick; return(axis == InputAxis.JoypadX ? joy.x : joy.y); } case InputAxis.Joypad: { var buttonId = controller == OVRInput.Controller.LTouch ? 0x00000400 : 0x00000004; //see enum ovrButton_ in OVER_CAPI.h return((state.Buttons & buttonId) != 0 ? 1 : 0); } default: return(0); } }
public float this[InputAxis axis] { get { switch (axis) { case InputAxis.Horizontal: return(Horizontal); case InputAxis.Vertical: return(Vertical); default: throw new System.NotImplementedException("Missing InputAxis " + axis.ToString()); } } private set { switch (axis) { case InputAxis.Horizontal: Horizontal = value; break; case InputAxis.Vertical: Vertical = value; break; default: throw new System.NotImplementedException("Missing InputAxis " + axis.ToString()); } } }
private void DrawInput(InputAxis input) { //Horizontal Scope ////An Indented way of using Unitys Scopes using (new GUILayout.HorizontalScope(GUI.skin.box)) { if (input.Axis == input.UnityAxis) { EditorGUILayout.LabelField(string.Format("Axis: {0}{1}", input.Axis, string.Format(input.ValueInverted? " (Inverted)" : ""))); } else { EditorGUILayout.LabelField(string.Format("Axis: {0}", input.Axis)); EditorGUILayout.LabelField(string.Format("Unity Axis: {0}", input.UnityAxis)); EditorGUILayout.LabelField(string.Format("Inverted: {0}", input.ValueInverted)); } var barSize = EditorGUILayout.BeginHorizontal(); GUILayout.Space(32); //Vertical Scope ////An Indented way of using Unitys Scopes using (new GUILayout.VerticalScope(GUI.skin.box)) { GUILayout.Space(16); EditorGUI.ProgressBar(barSize, (input.Value + 1) * 0.5f, string.Format("Value: {0}", input.Value)); } EditorGUILayout.EndHorizontal(); } }
public PlayerMicrobeInput() { forwardBackAxis = new InputAxis(new List <(InputBool input, int associatedValue)> { (forward, -1), (backwards, 1), }); leftRightAxis = new InputAxis(new List <(InputBool input, int associatedValue)> { (left, -1), (right, 1), }); inputs = new InputGroup(new List <IInputReceiver> { forwardBackAxis, leftRightAxis, autoMove, toggleEngulf, fireToxin, cheatEditor, cheatGlucose, cheatAmmonia, cheatPhosphates, }); }
private void initializeControls() { // Attempt to load from saved preferences file this.controls = this.loadControlLayout(); // If we return with an empty control layout, then we add instead the default values if(this.controls.Count == 0) { Debug.Log("No control scheme (or keys) was found saved, so we are defaulting to the default control scheme"); // Default movement controls this.controls["Forward"] = KeyCode.W; this.controls["Backward"] = KeyCode.S; this.controls["Left"] = KeyCode.A; this.controls["Right"] = KeyCode.D; // Alternative movement controls this.controls["alt_Forward"] = KeyCode.UpArrow; this.controls["alt_Backward"] = KeyCode.DownArrow; this.controls["alt_Left"] = KeyCode.LeftArrow; this.controls["alt_Right"] = KeyCode.RightArrow; // Interaction controls this.controls["Interact"] = KeyCode.F; // Save the default controls this.saveKeyLayout(); } // TODO: Initialize movement input axis this.horizontal = new InputAxis(this.controls["Right"], this.controls["Left"], this.controls["alt_Right"], this.controls["alt_Left"]); this.vertical = new InputAxis(this.controls["Forward"], this.controls["Backward"], this.controls["alt_Forward"], this.controls["alt_Backward"]); }
public INPUTINFO ( string name, string descriptiveName, string descriptiveNegativeName, string positiveButton, string negativeButton, string altPositiveButton, string altNegativeButton, int axis, int joyNum, bool snap = false, bool invert = false ) { KeyInfo = new InputAxis() { name = name, descriptiveName = descriptiveName, descriptiveNegativeName = descriptiveNegativeName, negativeButton = negativeButton, positiveButton = positiveButton, altNegativeButton = altNegativeButton, altPositiveButton = altPositiveButton, axis = axis, joyNum = joyNum, snap = snap, invert = invert }; InputData.ADD(KeyInfo); }
/// <summary> /// グローバルな入力設定を追加する(OK、キャンセルなど) /// </summary> /// <param name="inputManagerGenerator">Input manager generator.</param> private static void AddGlobalInputSettings(InputManagerGenerator inputManagerGenerator) { // 横方向 { var name = "Horizontal"; inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, "a", "d", "left", "right")); } // 縦方向 { var name = "Vertical"; inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, "s", "w", "down", "up")); } // 決定 { var name = "Submit"; inputManagerGenerator.AddAxis(InputAxis.CreateButton(name, "z", "joystick button 0")); } // キャンセル { var name = "Cancel"; inputManagerGenerator.AddAxis(InputAxis.CreateButton(name, "x", "joystick button 1")); } }
public void AddAxis(InputAxis axis) { if (axis.axis < 1) { Debug.LogError("Axisは1以上に設定してください。"); } SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes"); axesProperty.arraySize++; serializedObject.ApplyModifiedProperties(); SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1); GetChildProperty(axisProperty, "m_Name").stringValue = axis.name; GetChildProperty(axisProperty, "descriptiveName").stringValue = axis.descriptiveName; GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName; GetChildProperty(axisProperty, "negativeButton").stringValue = axis.negativeButton; GetChildProperty(axisProperty, "positiveButton").stringValue = axis.positiveButton; GetChildProperty(axisProperty, "altNegativeButton").stringValue = axis.altNegativeButton; GetChildProperty(axisProperty, "altPositiveButton").stringValue = axis.altPositiveButton; GetChildProperty(axisProperty, "gravity").floatValue = axis.gravity; GetChildProperty(axisProperty, "dead").floatValue = axis.dead; GetChildProperty(axisProperty, "sensitivity").floatValue = axis.sensitivity; GetChildProperty(axisProperty, "snap").boolValue = axis.snap; GetChildProperty(axisProperty, "invert").boolValue = axis.invert; GetChildProperty(axisProperty, "type").intValue = (int)axis.type; GetChildProperty(axisProperty, "axis").intValue = axis.axis - 1; GetChildProperty(axisProperty, "joyNum").intValue = axis.joyNum; serializedObject.ApplyModifiedProperties(); }
private InputAxis MakeInputAxis(string name, int axis) { var result = new InputAxis(); result.name = name; result.axis = axis; // Any positive or negative values that are less than this number will register as zero. Useful for joysticks. result.dead = 0.001f; // For keyboard input, a larger value will result in faster response time. // A lower value will be more smooth. // For Mouse delta the value will scale the actual mouse delta. result.sensitivity = 3; // How fast will the input recenter. Only used when the Type is key / mouse button. result.gravity = 3; result.snap = true; result.type = AxisType.JoystickAxis; result.joyNum = 1; return(result); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); InputManager manager = target as InputManager; if (GUILayout.Button("反映")) { generator = new InputManagerGenerator(); generator.Clear(); var inputList = manager.GetInputSettingList(); for (int i = 0; i < inputList.Length; i++) { var data = inputList[i]; generator.AddAxis(InputAxis.CreateKeyAxis(data.name, data.negative, data.positive, data.altNegative, data.altPositive)); if (data.isJoyPadAxisCreate) { generator.AddAxis(InputAxis.CreatePadAxis(data.name, data.joyStickNum, data.axisNum)); } } Debug.Log("反映成功"); } }
/// <summary> Returns the value of the virtual axis with the smoothing filtering applied. </summary> public static float GetAxis(InputAxis axis) { switch (axis) { case InputAxis.Horizontal: if (instance != null) { return(instance.movementAxisValues.x); } else { return(0f); } case InputAxis.Vertical: if (instance != null) { return(instance.movementAxisValues.y); } else { return(0f); } case InputAxis.MouseX: return(Input.GetAxis("Mouse X")); case InputAxis.MouseY: return(Input.GetAxis("Mouse Y")); default: return(0f); } }
public static void EnableSteeringContoller() { InputManagerGenerator inputManagerGenerator = new InputManagerGenerator(); // 現在の設定をクリア inputManagerGenerator.Clear(); // ハンドル入力を登録 { var name = "HANDLE"; inputManagerGenerator.AddAxis(InputAxis.CreatePadAxis(name, 0, 1)); inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, "a", "d", "left", "right")); } // ボタン入力を登録 foreach (var button in buttons) { var buttonName = button.Key; var inputName = button.Value; inputManagerGenerator.AddAxis(InputAxis.CreateButton(buttonName, inputName, inputName)); } // デフォルト { inputManagerGenerator.AddAxis(InputAxis.CreatePadAxis("Horizontal", 0, 1)); inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis("Horizontal", "a", "d", "left", "right")); inputManagerGenerator.AddAxis(InputAxis.CreatePadAxis("Vertical", 0, 2)); inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis("Vertical", "s", "w", "down", "up")); inputManagerGenerator.AddAxis(InputAxis.CreateButton("Submit", "enter", "joystick button 0")); inputManagerGenerator.AddAxis(InputAxis.CreateButton("Cancel", "escape", "joystick button 1")); } // 完了 Debug.Log("ProjectSetting/InputにSteeringControllerを設定しました。"); }
void Awake() { player = this; this.vertical = GameInput.input.getAxis("Vertical"); this.horizontal = GameInput.input.getAxis("Horizontal"); this.lockAim = GameInput.input.getAxis("LockAim"); }
protected override float GetAxisValue(XRNodeState node, InputAxis axis) { ReadState(node); switch (axis) { case InputAxis.TouchPad: return((lastState.ulButtonTouched & 1ul << (int)EVRButtonId.k_EButton_SteamVR_Touchpad) != 0 ? 1 : 0); case InputAxis.MainTrigger: return(lastState.rAxis1.x); case InputAxis.Grip: return((lastState.ulButtonPressed & (1ul << (int)EVRButtonId.k_EButton_Grip)) != 0 ? 1 : 0); case InputAxis.JoypadX: return(lastState.rAxis0.x); case InputAxis.JoypadY: return(lastState.rAxis0.y); case InputAxis.Joypad: return((lastState.ulButtonPressed & (1ul << (int)EVRButtonId.k_EButton_SteamVR_Touchpad)) != 0 ? 1 : 0); case InputAxis.Application: return((lastState.ulButtonPressed & (1ul << (int)EVRButtonId.k_EButton_ApplicationMenu)) != 0 ? 1 : 0); default: throw new ArgumentOutOfRangeException("axis", axis, null); } }
// Update is called once per frame void Update() { var characterPresenter = characterListPresenter.GetOwnCharacterPresenter(); InputAxis axis = InputAxis.GetInputAxis(); characterPresenter.SetDirection(new Vector3(axis.I.x, 0, axis.I.y)); characterPresenter.Move(axis.F.x, axis.F.y); }
public ControllerAxisEditor(InputAxis axis) { Axis = axis as ControllerAxis; FindIndex(); DeviceManager.OnDeviceAdded += (SDL.SDL_Event e) => FindIndex(); DeviceManager.OnDeviceRemoved += (SDL.SDL_Event e) => FindIndex(); }
internal void EditAxis(InputAxis axis, SelectAxisDelegate selectAxis = null) { Callback = selectAxis; WindowName = "Edit " + axis.Name; SaveName = axis.Name; Axis = axis; Axis.editor.Open(); }
public static void ADD(InputAxis i) { if (axis == null) { axis = new List <InputAxis>(); } axis.Add(i); }
/// <summary> /// If the controller is capable, returns if (and sometimes how closely) the player is touching /// the given control. /// </summary> /// <param name="node"></param> /// <param name="axis"></param> /// <returns></returns> public static float GetTouch(XRNodeState node, InputAxis axis) { if (impl == null) { impl = GetImpl(); } return(impl.GetTouchValue(node, axis)); }
public float GetAxis(InputAxis k) { if (AxisMaps.ContainsKey(k)) { return(Input.GetAxis(AxisMaps[k])); } return(0f); }
public InputMapContentAxisTreeItem(InputAxis axis, int id) { Debug.Assert(axis != null, "Axis cannot be null"); Axis = axis; displayName = Axis.axisName; this.id = id; depth = -1; }
public void SetControl() { if( PlayerPrefs.HasKey( CONTROL_AXIS_ID ) ) { string controlAxisID = PlayerPrefs.GetString( CONTROL_AXIS_ID ); controlAxis = axisManager.GetAxis( controlAxisID, controlAxisType ); Debug.Log( "Calibration: Setting " + controlAxisType.ToString() + " control axis " + controlAxisID ); PlayerPrefs.SetString( motionAxisID + MOTION_AXIS_VARIABLE_SUFFIX, controlAxisID ); } }
/// <summary> /// Registers a new virtual axis. /// </summary> /// <param name="name">Unique name used to access the virtual axis.</param> /// <param name="type">Type of physical axis to map to.</param> /// <param name="deadZone">Value below which to ignore axis value and consider it 0.</param> /// <param name="sensitivity">Higher sensitivity means the axis will more easily reach its maximum values.</param> /// <param name="invert">Should axis values be inverted.</param> public void RegisterAxis(String name, InputAxis type, float deadZone = 0.0001f, float sensitivity = 1.0f, bool invert = false) { Internal_RegisterAxis(mCachedPtr, name, type, deadZone, sensitivity, invert); }
private static extern float Internal_GetAxisValue(InputAxis axis, int deviceIdx);
/// <summary> /// Returns value of the specified input axis. /// </summary> /// <param name="axis">Type of axis to query.</param> /// <param name="deviceIdx">Index of the device in case more than one is hooked up (0 - primary).</param> /// <returns>Value of the axis in range [-1.0, 1.0]. Canan be outside the range for devices with unbound axes /// (for example mouse).</returns> public static float GetAxisValue(InputAxis axis, int deviceIdx = 0) { return Internal_GetAxisValue(axis, deviceIdx); }
private static extern void Internal_RegisterAxis(IntPtr thisPtr, String name, InputAxis type, float deadZone, float sensitivity, bool invert);
private static void AddAxis(InputAxis axis) { SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]); SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes"); axesProperty.arraySize++; serializedObject.ApplyModifiedProperties(); SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1); GetChildProperty(axisProperty, "m_Name").stringValue = axis.name; GetChildProperty(axisProperty, "descriptiveName").stringValue = axis.descriptiveName; GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName; GetChildProperty(axisProperty, "negativeButton").stringValue = axis.negativeButton; GetChildProperty(axisProperty, "positiveButton").stringValue = axis.positiveButton; GetChildProperty(axisProperty, "altNegativeButton").stringValue = axis.altNegativeButton; GetChildProperty(axisProperty, "altPositiveButton").stringValue = axis.altPositiveButton; GetChildProperty(axisProperty, "gravity").floatValue = axis.gravity; GetChildProperty(axisProperty, "dead").floatValue = axis.dead; GetChildProperty(axisProperty, "sensitivity").floatValue = axis.sensitivity; GetChildProperty(axisProperty, "snap").boolValue = axis.snap; GetChildProperty(axisProperty, "invert").boolValue = axis.invert; GetChildProperty(axisProperty, "type").intValue = (int)axis.type; GetChildProperty(axisProperty, "axis").intValue = (int)(axis.axis - 1); GetChildProperty(axisProperty, "joyNum").intValue = axis.joyNum; serializedObject.ApplyModifiedProperties(); }
public int GetAxis(InputAxis Axis) { if (controller != null && controller.IsConnected) { var state = controller.GetState(); switch (Axis) { case InputAxis.LeftStickX: return state.Gamepad.LeftThumbX / 256; case InputAxis.LeftStickY: return -state.Gamepad.LeftThumbY / 256; case InputAxis.RightStickX: return state.Gamepad.RightThumbX / 256; case InputAxis.RightStickY: return -state.Gamepad.RightThumbY / 256; case InputAxis.LeftTrigger: return state.Gamepad.LeftTrigger; case InputAxis.RightTrigger: return state.Gamepad.RightTrigger; } } return 0; }
/// <summary> /// Method that checks to see if the trigger was down in the last frame and up in /// the current frame. Used to check to see if a trigger has been pressed and /// released /// </summary> /// <param name="axis"> /// The InputAxis that needs to be checked /// </param> /// <returns> /// true if the trigger was down in the last frame and up in the current frame /// returns false otherwise /// </returns> public static bool CheckTriggerPress(InputAxis axis) { return AxisMapDictionary[axis].CheckTriggerPress(); }
/// <summary> /// Method to return if a trigger was up in the last frame /// </summary> /// <param name="axis"> /// The InputAxis that needs to be checked /// </param> /// <returns> /// true if the trigger was up, false otherwise /// </returns> public static bool IsLastTriggerUp(InputAxis axis) { return AxisMapDictionary[axis].IsLastTriggerUp(); }
/// <summary> /// Method to check to see if trigger is active /// </summary> /// <param name="axis"> /// The InputAxis that needs to be checked /// </param> /// <returns> /// true if trigger is down, false otherwise /// </returns> public static bool IsTriggerDown(InputAxis axis) { return AxisMapDictionary[axis].IsTriggerDown(); }
/// <summary> /// Returns the scalar value for the given axis. Typically these values are used as velocities. /// </summary> /// <param name="axis">The axis for which the value is to be returned.</param> /// <returns> /// The current deflection of the given axis. /// </returns> public float GetAxis(InputAxis axis) { return _axes[(int) axis]; }
// Use this for initialization static void Start () { UpdateControlMapping(m_ControllerType); //check the input manager and see what axis we have from there SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]); SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes"); if(axesProperty.arraySize == 0 ) { m_Controls = new InputAxis[1]; m_Controls[0] = new InputAxis(){name = "0"}; AddAxis(m_Controls[0]); } else { int numAxis = 0; int maxPlayers = 1; for(int i = 0; i < axesProperty.arraySize; i++) { SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(i); if(GetChildProperty(axisProperty, "joyNum").intValue > maxPlayers) { maxPlayers = GetChildProperty(axisProperty, "joyNum").intValue; } if(GetChildProperty(axisProperty, "joyNum").intValue != 1) continue; numAxis++; } m_MaxPlayers = maxPlayers; m_Controls = new InputAxis[numAxis]; m_NumAxis = numAxis; for(int i = 0; i < m_NumAxis; i++) { SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(i); if(GetChildProperty(axisProperty, "joyNum").intValue != 1) continue; InputAxis axis = new InputAxis(); axis.name = GetChildProperty(axisProperty, "m_Name").stringValue; axis.name = axis.name.Remove(0, 5); axis.descriptiveName = GetChildProperty(axisProperty, "descriptiveName").stringValue; axis.descriptiveNegativeName = GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue; axis.negativeButton = GetChildProperty(axisProperty, "negativeButton").stringValue; axis.positiveButton = GetChildProperty(axisProperty, "positiveButton").stringValue; if(axis.positiveButton.Contains("joystick")) { for(int codes = 0; codes < m_ControllerButtonsMap.Length; codes++) { if(axis.positiveButton.Contains(m_ControllerButtonsMap[codes])) { axis.positiveJoyButton = (JoyButtonCode)(codes+1); break; } } } if(axis.negativeButton.Contains("joystick")) { for(int codes = 0; codes < m_ControllerButtonsMap.Length; codes++) { if(axis.negativeButton.Contains(m_ControllerButtonsMap[codes])) { axis.negativeJoyButton = (JoyButtonCode)(codes+1); break; } } } axis.altNegativeButton = GetChildProperty(axisProperty, "altNegativeButton").stringValue; axis.altPositiveButton = GetChildProperty(axisProperty, "altPositiveButton").stringValue; axis.gravity = GetChildProperty(axisProperty, "gravity").floatValue; axis.dead = GetChildProperty(axisProperty, "dead").floatValue; axis.sensitivity = GetChildProperty(axisProperty, "sensitivity").floatValue; axis.snap = GetChildProperty(axisProperty, "snap").boolValue; axis.invert = GetChildProperty(axisProperty, "invert").boolValue; axis.type = (AxisType)GetChildProperty(axisProperty, "type").intValue; axis.axis = (AxisCode)GetChildProperty(axisProperty, "axis").intValue; if(axis.type == AxisType.MouseMovement) { axis.axis = (AxisCode)(axis.axis + 1); } else if(axis.type == AxisType.JoystickAxis) { for(int a = 0; a < m_ControllerAxisMapping.Length; a++) { if((int)axis.axis == m_ControllerAxisMapping[a]) axis.joyAxis = (JoyAxisCode)(a+1); } } axis.joyNum = GetChildProperty(axisProperty, "joyNum").intValue; m_Controls[i] = axis; Debug.Log("Added axis for "+axis.joyNum); } } }
public static void AddAxisPlayer(int player, InputAxis axis) { SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]); SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes"); axesProperty.arraySize++; serializedObject.ApplyModifiedProperties(); SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1); GetChildProperty(axisProperty, "m_Name").stringValue = "Joy"+player+" "+axis.name; GetChildProperty(axisProperty, "descriptiveName").stringValue = axis.descriptiveName; GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName; if(axis.positiveJoyButton != JoyButtonCode.none) { GetChildProperty(axisProperty, "positiveButton").stringValue = "joystick "+(player+1)+" "+m_ControllerButtonsMap[(int)axis.positiveJoyButton-1]; } else { GetChildProperty(axisProperty, "positiveButton").stringValue = ""; } if(axis.negativeJoyButton != JoyButtonCode.none) { GetChildProperty(axisProperty, "negativeButton").stringValue = "joystick "+(player+1)+" "+m_ControllerButtonsMap[(int)axis.negativeJoyButton-1]; } else { GetChildProperty(axisProperty, "negativeButton").stringValue = ""; } GetChildProperty(axisProperty, "altNegativeButton").stringValue = (player > 0 && (axis.altNegativeButton.Length == 1 || axis.altNegativeButton.Contains("mouse"))) ? "" : axis.altNegativeButton; GetChildProperty(axisProperty, "altPositiveButton").stringValue = (player > 0 && (axis.altPositiveButton.Length == 1 || axis.altPositiveButton.Contains("mouse"))) ? "" : axis.altPositiveButton; GetChildProperty(axisProperty, "gravity").floatValue = axis.gravity; GetChildProperty(axisProperty, "dead").floatValue = axis.dead; GetChildProperty(axisProperty, "sensitivity").floatValue = axis.sensitivity; GetChildProperty(axisProperty, "snap").boolValue = axis.snap; GetChildProperty(axisProperty, "invert").boolValue = axis.invert; GetChildProperty(axisProperty, "type").intValue = (int)axis.type; if(axis.joyAxis != JoyAxisCode.none) GetChildProperty(axisProperty, "axis").intValue = m_ControllerAxisMapping[(int)axis.joyAxis-1]; else GetChildProperty(axisProperty, "axis").intValue = (int)(axis.axis - 1); GetChildProperty(axisProperty, "joyNum").intValue = player+1; serializedObject.ApplyModifiedProperties(); }
public int GetAxis(InputAxis Axis) { if (Connected) switch (Axis) { case InputAxis.LeftStickX: return Controller.GetStickPoint(DS4Stick.Left).X; case InputAxis.LeftStickY: return Controller.GetStickPoint(DS4Stick.Left).Y; case InputAxis.RightStickX: return Controller.GetStickPoint(DS4Stick.Right).X; case InputAxis.RightStickY: return Controller.GetStickPoint(DS4Stick.Right).Y; case InputAxis.LeftTrigger: return (int)(Controller.GetTriggerState(DS4Trigger.L2) * 255); case InputAxis.RightTrigger: return (int)(Controller.GetTriggerState(DS4Trigger.R2) * 255); } return 0; }
void OnGUI() { m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos, false, true); if(GUILayout.Button("Save Changes")) { //commit changes ClearInputSettings(); for(int n = 0; n < m_MaxPlayers; n++) { for(int i = 0; i < m_NumAxis; i++) { m_Controls[i].joyNum = n+1; if((m_Controls[i].type == AxisType.MouseMovement || ((m_Controls[i].altNegativeButton.Length == 1 || m_Controls[i].altPositiveButton.Length == 1) && m_Controls[i].positiveJoyButton == JoyButtonCode.none && m_Controls[i].negativeJoyButton == JoyButtonCode.none)) && n > 0) { } else { AddAxisPlayer(n,m_Controls[i]); } } } } EditorGUI.BeginChangeCheck (); m_ControllerType = (ControllerType)EditorGUILayout.EnumPopup("Default Controller Type",m_ControllerType); if (EditorGUI.EndChangeCheck ()) { if(GUI.changed) { UpdateControlMapping(m_ControllerType); } } m_MaxPlayers = EditorGUILayout.IntField("Max Controllers", m_MaxPlayers); EditorGUI.BeginChangeCheck (); m_NumAxis = EditorGUILayout.IntField("Num Axes", m_NumAxis); if (EditorGUI.EndChangeCheck ()) { if(GUI.changed && m_NumAxis > 0) { Debug.Log(m_NumAxis); InputAxis[] oldControls = m_Controls; m_Controls = new InputAxis[m_NumAxis]; for(int i = 0; i < m_NumAxis; i++) { if(i < oldControls.Length) m_Controls[i] = oldControls[i]; else m_Controls[i] = new InputAxis(){name = " "+i}; } } } GUILayout.Label ("Axis Definitions \n(Note: Use the generic joystick syntax for buttons e.g. joystick button 0)", EditorStyles.boldLabel); for(int i = 0; i < m_Controls.Length; i++) { m_Controls[i].show = EditorGUILayout.Foldout(m_Controls[i].show,m_Controls[i].name); if(!m_Controls[i].show) continue; m_Controls[i].name = EditorGUILayout.TextField("Name", m_Controls[i].name); m_Controls[i].descriptiveName = EditorGUILayout.TextField("Descriptive Name", m_Controls[i].descriptiveName); m_Controls[i].descriptiveNegativeName = EditorGUILayout.TextField("Descriptive Negative Name", m_Controls[i].descriptiveNegativeName); m_Controls[i].type = (AxisType)EditorGUILayout.EnumPopup("Type", m_Controls[i].type ); if(m_Controls[i].type == AxisType.KeyOrMouseButton) { m_Controls[i].positiveJoyButton = (JoyButtonCode)EditorGUILayout.EnumPopup("Joy Button +", m_Controls[i].positiveJoyButton); m_Controls[i].negativeJoyButton = (JoyButtonCode)EditorGUILayout.EnumPopup("Joy Button -", m_Controls[i].negativeJoyButton); //We do not read these in because they are set by the joy button type //m_Controls[i].negativeButton = EditorGUILayout.TextField("Negative Button", m_Controls[i].negativeButton); //m_Controls[i].positiveButton = EditorGUILayout.TextField("Positive Button", m_Controls[i].positiveButton); m_Controls[i].altPositiveButton = EditorGUILayout.TextField("Alt Button +", m_Controls[i].altPositiveButton); m_Controls[i].altNegativeButton = EditorGUILayout.TextField("Alt Button -", m_Controls[i].altNegativeButton); } m_Controls[i].gravity = EditorGUILayout.FloatField("Gravity", m_Controls[i].gravity); m_Controls[i].snap = EditorGUILayout.Toggle("Snap", m_Controls[i].snap ); m_Controls[i].sensitivity = EditorGUILayout.FloatField("Sensitivity", m_Controls[i].sensitivity ); m_Controls[i].invert = EditorGUILayout.Toggle("Invert", m_Controls[i].invert ); if(m_Controls[i].type == AxisType.MouseMovement) { m_Controls[i].dead = EditorGUILayout.FloatField("Dead", m_Controls[i].dead); m_Controls[i].axis = (AxisCode)EditorGUILayout.EnumPopup("Mouse Axis", m_Controls[i].axis); } if(m_Controls[i].type == AxisType.JoystickAxis) { m_Controls[i].dead = EditorGUILayout.FloatField("Dead", m_Controls[i].dead); m_Controls[i].joyAxis = (JoyAxisCode)EditorGUILayout.EnumPopup("Joystick Axis", m_Controls[i].joyAxis); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); if(GUILayout.Button("Remove")) { InputAxis[] newControls = new InputAxis[m_Controls.Length-1]; int count = 0; for(int n = 0; n < m_Controls.Length; n++) { if(n != i) { newControls[count] = m_Controls[n]; count++; } } m_Controls = newControls; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); }
private static void UpdateAxis(InputAxis axis) { SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]); SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes"); //for(var }