private void OnLock() { bool bSendEvent = false; List <string> mappedKeys = new List <string>(_BoundInputValues.Keys); foreach (string mapKey in mappedKeys) { _PrevBoundInputValues[mapKey] = _BoundInputValues[mapKey]; _BoundInputValues[mapKey] = UInput.GetAxis(mapKey); bSendEvent = bSendEvent || (_PrevBoundInputValues[mapKey] != _BoundInputValues[mapKey]); } if (bSendEvent) { RetroEvents.Chapter("Input_" + BoundInputID.ToString()).Set(new AxisInputEvent(_BoundInputValues, Time.deltaTime, false, BoundInputID)); } }
private void Update() { if (ShortcutEvent != null) { for (int i = 1; i <= 8; i++) { var shortcut = string.Format("Shortcut {0}", i); if (InputManager.IsDown(shortcut)) { ShortcutEvent(this, new InfoEventArgs <int>(i)); break; } } } if (UnityInput.GetKeyUp(KeyCode.Escape) && EscapeEvent != null) { EscapeEvent(this, new InfoEventArgs <object>(null)); } if ((UnityInput.GetAxis("Horizontal") != 0 || UnityInput.GetAxis("Vertical") != 0) && MoveEvent != null) { var vectorMovement = new Vector2(UnityInput.GetAxis("Horizontal"), UnityInput.GetAxis("Vertical")); MoveEvent(this, new InfoEventArgs <Vector2>(vectorMovement)); } if (UnityInput.GetAxis("Mouse ScrollWheel") != 0f && ScrollEvent != null) { ScrollEvent(this, new InfoEventArgs <float>(UnityInput.GetAxis("Mouse ScrollWheel"))); } if (InputManager.IsDown("Click") && ClickEvent != null) { RaycastHit raycastHitInfo; var ray = _camera.ScreenPointToRay(UnityInput.mousePosition); PointerEventData pointerData = new PointerEventData(EventSystem.current); pointerData.position = UnityInput.mousePosition; List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointerData, results); if (results.Count > 0 && results[0].gameObject.layer == LayerMask.NameToLayer("UI")) { results.Clear(); } else { if (Physics.Raycast(ray, out raycastHitInfo, Mathf.Infinity, LayerMask.GetMask("GameplayElement"))) { ClickEvent(this, new InfoEventArgs <GameObject>(raycastHitInfo.collider.gameObject)); } } } }
public static new float GetAxis(string axisName) { if (!Enabled) { return(0f); } return(UnityInput.GetAxis(axisName)); }
/// <summary> /// Update an Interaction Float data type from a SingleAxis (float) input /// </summary> /// <remarks> /// Raises a Float Input Changed event when the float data changes /// </remarks> /// <param name="interactionMapping"></param> protected void UpdateSingleAxisData(MixedRealityInteractionMapping interactionMapping) { Debug.Assert(interactionMapping.AxisType == AxisType.SingleAxis); var singleAxisValue = UInput.GetAxis(interactionMapping.AxisCodeX); switch (interactionMapping.InputType) { case DeviceInputType.TriggerPress: case DeviceInputType.ButtonPress: // Update the interaction data source interactionMapping.BoolData = singleAxisValue.Equals(1); break; case DeviceInputType.TriggerTouch: case DeviceInputType.TriggerNearTouch: case DeviceInputType.ThumbNearTouch: case DeviceInputType.IndexFingerNearTouch: case DeviceInputType.MiddleFingerNearTouch: case DeviceInputType.RingFingerNearTouch: case DeviceInputType.PinkyFingerNearTouch: // Update the interaction data source interactionMapping.BoolData = !singleAxisValue.Equals(0); break; case DeviceInputType.Trigger: // Update the interaction data source interactionMapping.FloatData = singleAxisValue; // If our value changed raise it. if (interactionMapping.Changed) { // Raise input system Event if it enabled InputSystem?.RaiseFloatInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionMapping.FloatData); } return; default: Debug.LogWarning("Unhandled Interaction"); return; } // If our value changed raise it. if (interactionMapping.Changed) { // Raise input system Event if it enabled if (interactionMapping.BoolData) { InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); } else { InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); } } }
public float GetAxis() { if (this.isKey) { return(this.key2axis()); } else { return(this.axisVal2axis(DefInput.GetAxis(this.input))); } }
private void OnNoLock() { List <string> mappedKeys = new List <string>(_BoundInputValues.Keys); foreach (string mapKey in mappedKeys) { _BoundInputValues[mapKey] = UInput.GetAxis(mapKey); } RetroEvents.Chapter("Input_" + BoundInputID.ToString()).Set(new AxisInputEvent(_BoundInputValues, Time.deltaTime, false, BoundInputID)); }
/// <summary> /// Perform keyboard panning /// </summary> protected void UpdateAxis() { MovemenAxisInfo axis = new MovemenAxisInfo() { MovemoveDir = MoveDirection.None, horizontalValue = UnityInput.GetAxis("Horizontal"), verticalValue = UnityInput.GetAxis("Vertical") }; basicAxisInfo = axis; if (axisMoved != null) { axisMoved(basicAxisInfo); } }
/// <summary> /// Update the Touchpad / Thumbstick input from the device (in OpenVR, touchpad and thumbstick are the same input control) /// </summary> /// <param name="interactionMapping"></param> protected void UpdateDualAxisData(MixedRealityInteractionMapping interactionMapping) { Debug.Assert(interactionMapping.AxisType == AxisType.DualAxis); dualAxisPosition.x = UInput.GetAxis(interactionMapping.AxisCodeX); dualAxisPosition.y = UInput.GetAxis(interactionMapping.AxisCodeY); // Update the interaction data source interactionMapping.Vector2Data = dualAxisPosition; // If our value changed raise it. if (interactionMapping.Changed) { // Raise input system Event if it enabled InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionMapping.Vector2Data); } }
private void Update() { if (Input.GetKeyDown(KeyCode.F)) { _flashIsOn = !_flashIsOn; SelectFlashLight(_flashIsOn); } _zoom = Input.GetAxis("Mouse ScrollWheel"); if (_zoom > 0 || _zoom < 0) { SelectWeapon(); } if (Input.GetKeyDown(KeyCode.R)) { } }
/// <summary> /// Detect which Axis is actively returning a value for the specified inputController. /// </summary> /// <param name="axisValue"></param> /// <param name="required"></param> /// <param name="restrictions"></param> /// <returns></returns> public static string DetectAxes(out float axisValue, string[] required, params string[] restrictions) { int length = axesNames.Length; KeyValuePair <string, float> highestValueAxis = new KeyValuePair <string, float>("", 0); int joystickCount = JoystickCount; axisValue = 0; for (int i = 0; i < length; i++) { if (axesNames[i].Contains("joy_")) { string[] splitName = axesNames[i].Split('_'); int joyNum; if (int.TryParse(splitName[1], out joyNum) && joyNum > joystickCount) { break; } } if (!restrictions.Any(x => axesNames[i].Contains(x)) && required.All(y => axesNames[i].Contains(y))) { axisValue = UInput.GetAxis(axesNames[i]); float magnitudeOfAxis = Mathf.Abs(UInput.GetAxis(axesNames[i])); if (magnitudeOfAxis > Mathf.Abs(highestValueAxis.Value) && magnitudeOfAxis >= (axesNames[i].Contains("mouse") ? 10 : 0.8f)) { highestValueAxis = new KeyValuePair <string, float>(axesNames[i], axisValue); } } } axisValue = highestValueAxis.Value; string finalAxisString = highestValueAxis.Key; for (int ii = 0; ii < required.Length; ii++) { finalAxisString = finalAxisString.Replace(required[ii], ""); } return(finalAxisString.ToLower()); }
private void MouseUpdate() { if (EditMouseUpdate == false) { return; } float scroll = UInput.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f) { Vector2 mousePos = UInput.mousePosition; Rect gameScreen = new Rect(0.0f, 0.0f, Screen.width, Screen.height); if (gameScreen.Contains(mousePos)) { MouseEvent mouseEvent = m_mouseTranslator.MouseWheel(mousePos, -scroll); if (CallBackMouseEvent != null && mouseEvent != MouseEvent.None) { CallBackMouseEvent(mouseEvent); } } } bool updateRaycast = false; for (int i = 0; i < 3; ++i) { if (UInput.GetMouseButton(i) || UInput.GetMouseButtonUp(i) || m_mouseDown) { updateRaycast = true; break; } } Vector3 mouseposition; if (updateRaycast) { mouseposition = UInput.mousePosition; } else { return; } MouseEvent.E_Buttons eventbutton = MouseEvent.E_Buttons.Left; for (int i = 0; i < 3; ++i) { bool pressed = UInput.GetMouseButtonDown(i); bool unpressed = UInput.GetMouseButtonUp(i); //bool pressing = Input.GetMouseButton(i); //E_MOUSE_EVENT dowingEvent = E_MOUSE_EVENT.LDOWNING; if (i == 0) { eventbutton = MouseEvent.E_Buttons.Left; //dowingEvent = E_MOUSE_EVENT.LDOWNING; } else if (i == 1) { eventbutton = MouseEvent.E_Buttons.Right; //dowingEvent = E_MOUSE_EVENT.RDOWNING; } else if (i == 2) { eventbutton = MouseEvent.E_Buttons.Middle; //dowingEvent = E_MOUSE_EVENT.MDOWNING; } if (pressed) { PushTouchesEventMsg(mouseposition, true, eventbutton); m_mouseDown = true; } if (unpressed) { PushTouchesEventMsg(mouseposition, false, eventbutton); m_mouseDown = false; } } bool Moved = UInput.GetAxis("Mouse X") != 0.0f || UInput.GetAxis("Mouse Y") != 0.0f; if (Moved) { PushTouchesEventMsg(mouseposition, false, eventbutton, true); } }
/// <summary> /// Update controller. /// </summary> public void Update() { if (!UInput.mousePresent) { return; } // Bail early if our mouse isn't in our game window. if (UInput.mousePosition.x < 0 || UInput.mousePosition.y < 0 || UInput.mousePosition.x > Screen.width || UInput.mousePosition.y > Screen.height) { return; } for (int i = 0; i < Interactions.Length; i++) { if (Interactions[i].InputType == DeviceInputType.SpatialPointer) { // add mouse delta as rotation var mouseDeltaRotation = Vector3.zero; mouseDeltaRotation.x += -UInput.GetAxis("Mouse Y"); mouseDeltaRotation.y += UInput.GetAxis("Mouse X"); if (MouseInputProfile != null) { mouseDeltaRotation *= MouseInputProfile.MouseSpeed; } MixedRealityPose controllerPose = MixedRealityPose.ZeroIdentity; controllerPose.Rotation = Quaternion.Euler(mouseDeltaRotation); Interactions[i].PoseData = controllerPose; if (Interactions[i].Changed) { InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } } if (Interactions[i].InputType == DeviceInputType.PointerPosition) { Vector2 mouseDelta; mouseDelta.x = -UInput.GetAxis("Mouse Y"); mouseDelta.y = UInput.GetAxis("Mouse X"); Interactions[i].Vector2Data = mouseDelta; if (Interactions[i].Changed) { InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data); } } if (Interactions[i].AxisType == AxisType.Digital) { var keyButton = UInput.GetKey(Interactions[i].KeyCode); // Update the interaction data source Interactions[i].BoolData = keyButton; // If our value changed raise it. if (Interactions[i].Changed) { // Raise input system Event if it enabled if (Interactions[i].BoolData) { InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } } if (Interactions[i].InputType == DeviceInputType.Scroll) { Interactions[i].Vector2Data = UInput.mouseScrollDelta; if (Interactions[i].Changed) { InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data); } } } }
/// <summary> /// returns a specified axis /// </summary> /// <param name="axis">One of the analogue sticks, or the dpad</param> /// <param name="rawID">The controller number</param> /// <param name="raw">if raw is false then the controlIndex will be returned with a deadspot</param> /// <returns></returns> public static Vector2 GetAxis(Axis axis, GPRawID rawID, bool raw = false) { IList <AxisName> axisNameList = new List <AxisName>(); string xName = "", yName = ""; switch (axis) { case Axis.Dpad: xName = "DPad_XAxis_" + (int)rawID; yName = "DPad_YAxis_" + (int)rawID; axisNameList.Add(new AxisName(xName, yName)); break; case Axis.LeftStick: xName = "L_XAxis_" + (int)rawID; yName = "L_YAxis_" + (int)rawID; axisNameList.Add(new AxisName(xName, yName)); break; case Axis.RightStick: xName = "R_XAxis_" + (int)rawID; yName = "R_YAxis_" + (int)rawID; axisNameList.Add(new AxisName(xName, yName)); break; case Axis.Any: xName = "DPad_XAxis_" + (int)rawID; yName = "DPad_YAxis_" + (int)rawID; axisNameList.Add(new AxisName(xName, yName)); xName = "L_XAxis_" + (int)rawID; yName = "L_YAxis_" + (int)rawID; axisNameList.Add(new AxisName(xName, yName)); xName = "R_XAxis_" + (int)rawID; yName = "R_YAxis_" + (int)rawID; axisNameList.Add(new AxisName(xName, yName)); break; } Vector2 axisXY = Vector3.zero; try { foreach (AxisName elem in axisNameList) { float x, y; if (raw == false) { x = UInput.GetAxis(elem.xName); y = UInput.GetAxis(elem.yName); } else { x = UInput.GetAxisRaw(elem.xName); y = UInput.GetAxisRaw(elem.yName); } Vector2 vec = new Vector2(x, y); float mag = vec.magnitude; if (mag > 0f) { axisXY.x = x; axisXY.y = y; } } } catch (System.Exception e) { Debug.LogError(e); Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input"); } return(axisXY); }
/// <summary> /// Perform logic to update mouse/pointing device /// </summary> void UpdateMouse() { basicMouseInfo.previousPosition = basicMouseInfo.currentPosition; basicMouseInfo.currentPosition = UnityInput.mousePosition; basicMouseInfo.delta = basicMouseInfo.currentPosition - basicMouseInfo.previousPosition; mouseMovedOnThisFrame = basicMouseInfo.delta.sqrMagnitude >= Mathf.Epsilon; mouseButtonPressedThisFrame = false; // Move event if (basicMouseInfo.delta.sqrMagnitude > Mathf.Epsilon) { if (mouseMoved != null) { mouseMoved(basicMouseInfo); } } // Button events for (int i = 0; i < trackMouseButtons; ++i) { MouseButtonInfo mouseButton = m_MouseInfo[i]; mouseButton.delta = basicMouseInfo.delta; mouseButton.previousPosition = basicMouseInfo.previousPosition; mouseButton.currentPosition = basicMouseInfo.currentPosition; if (UnityInput.GetMouseButton(i)) { if (!mouseButton.isDown) { // First press mouseButtonPressedThisFrame = true; mouseButton.isDown = true; mouseButton.startPosition = UnityInput.mousePosition; mouseButton.startTime = Time.realtimeSinceStartup; mouseButton.startedOverUI = EventSystem.current.IsPointerOverGameObject(-mouseButton.mouseButtonId - 1); // Reset some stuff mouseButton.totalMovement = 0; mouseButton.isDrag = false; mouseButton.wasHold = false; mouseButton.isHold = false; mouseButton.flickVelocity = Vector2.zero; if (pressed != null) { pressed(mouseButton); } } else { float moveDist = mouseButton.delta.magnitude; // Dragging? mouseButton.totalMovement += moveDist; if (mouseButton.totalMovement > dragThresholdMouse) { bool wasDrag = mouseButton.isDrag; mouseButton.isDrag = true; if (mouseButton.isHold) { mouseButton.wasHold = mouseButton.isHold; mouseButton.isHold = false; } // Did it just start now? if (!wasDrag) { if (startedDrag != null) { startedDrag(mouseButton); } } if (dragged != null) { dragged(mouseButton); } // Flick? if (moveDist > flickThreshold) { mouseButton.flickVelocity = (mouseButton.flickVelocity * (1 - k_FlickAccumulationFactor)) + (mouseButton.delta * k_FlickAccumulationFactor); } else { mouseButton.flickVelocity = Vector2.zero; } } else { // Stationary? if (!mouseButton.isHold && !mouseButton.isDrag && Time.realtimeSinceStartup - mouseButton.startTime >= holdTime) { mouseButton.isHold = true; if (startedHold != null) { startedHold(mouseButton); } } } } } else // Mouse button not up { if (mouseButton.isDown) // Released { mouseButton.isDown = false; // Quick enough (with no drift) to be a tap? if (!mouseButton.isDrag && Time.realtimeSinceStartup - mouseButton.startTime < tapTime) { if (tapped != null) { tapped(mouseButton); } } if (released != null) { released(mouseButton); } } } } // Mouse wheel if (Mathf.Abs(UnityInput.GetAxis("Mouse ScrollWheel")) > Mathf.Epsilon) { if (spunWheel != null) { spunWheel(new WheelInfo { scrollAmount = UnityInput.GetAxis("Mouse ScrollWheel") * mouseWheelSensitivity }); } } }
public float GetAxis(string name) => UnityInput.GetAxis(name);
private void Update() { m_jump = UnityInput.GetButtonDown("Jump"); m_crouch = UnityInput.GetButton("Crouch"); m_horizontalMove = UnityInput.GetAxis("Horizontal"); }
private void Update() { if (difficultyCooldown > 0) { difficultyCooldown -= Time.deltaTime; } LevelUpDuration -= Time.deltaTime; if (_openedMenu == OpenedMenuMode.Stats) { BookScrollAmountGoal = Mathf.Clamp(BookScrollAmountGoal + 500 * screenScale * Input.GetAxis("Mouse ScrollWheel"), -Screen.height * 10 * screenScale, 0); if (Input.GetKeyDown(KeyCode.RightArrow)) { ChangePage(guidePage + 1); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { ChangePage(guidePage - 1); } if (Input.GetKeyDown(KeyCode.DownArrow)) { BookScrollAmountGoal = Mathf.Clamp(BookScrollAmountGoal - 1000f * screenScale, -Screen.height * 10 * screenScale, 0); } if (Input.GetKeyDown(KeyCode.UpArrow)) { BookScrollAmountGoal = Mathf.Clamp(BookScrollAmountGoal + 1000f * screenScale, -Screen.height * 10 * screenScale, 0); } BookScrollAmount = Vector3.Slerp(new Vector3(BookScrollAmount, 0, 0), new Vector3(BookScrollAmountGoal, 0, 0), Time.deltaTime * 30f * screenScale).x; } else if (_openedMenu == OpenedMenuMode.Inventory) { if (Input.GetKeyDown(KeyCode.LeftAlt)) { drawTotal = !drawTotal; } } try { PingUpdate(); } catch (Exception exc) { ModAPI.Console.Write("ERROR with ping update\n" + exc.ToString()); } if (_openedMenu != OpenedMenuMode.Hud) { if (_openedMenu == OpenedMenuMode.Inventory) { if (Input.GetMouseButtonUp(1)) { if (consumedsomething) { consumedsomething = false; } } if (SelectedItem != -1 && Inventory.Instance.ItemSlots[SelectedItem] != null) { var item = Inventory.Instance.ItemSlots[SelectedItem]; if (Input.GetMouseButtonDown(0)) { if (Input.GetKey(KeyCode.LeftShift)) { //unequip if equipped if (SelectedItem < -1) { for (int i = 0; i < Inventory.SlotCount; i++) { if (Inventory.Instance.ItemSlots[i] == null) { DraggedItem = null; isDragging = false; CustomCrafting.ClearIndex(SelectedItem); CustomCrafting.ClearIndex(i); DraggedItemIndex = -1; Inventory.Instance.ItemSlots[i] = item; Inventory.Instance.ItemSlots[SelectedItem] = null; SelectedItem = -1; break; } } } else //move to its correct slot or swap if slot is not empty { int targetSlot = -1; switch (item.type) { case BaseItem.ItemType.Helmet: targetSlot = -2; break; case BaseItem.ItemType.ChestArmor: targetSlot = -3; break; case BaseItem.ItemType.Pants: targetSlot = -4; break; case BaseItem.ItemType.Boot: targetSlot = -5; break; case BaseItem.ItemType.ShoulderArmor: targetSlot = -6; break; case BaseItem.ItemType.Glove: targetSlot = -7; break; case BaseItem.ItemType.Amulet: targetSlot = -8; break; case BaseItem.ItemType.Bracer: targetSlot = -9; break; case BaseItem.ItemType.Ring: if (Inventory.Instance.ItemSlots[-10] == null) { targetSlot = -10; } else if (Inventory.Instance.ItemSlots[-11] == null) { targetSlot = -11; } else { targetSlot = -10; } break; case BaseItem.ItemType.Weapon: targetSlot = -12; break; case BaseItem.ItemType.Quiver: case BaseItem.ItemType.SpellScroll: case BaseItem.ItemType.Shield: targetSlot = -13; break; } if (targetSlot != -1) { if (Inventory.Instance.ItemSlots[targetSlot] == null) { DraggedItem = null; isDragging = false; DraggedItemIndex = -1; CustomCrafting.ClearIndex(SelectedItem); Inventory.Instance.ItemSlots[targetSlot] = item; Inventory.Instance.ItemSlots[SelectedItem] = null; SelectedItem = -1; } else { DraggedItem = null; isDragging = false; DraggedItemIndex = -1; CustomCrafting.ClearIndex(SelectedItem); Inventory.Instance.ItemSlots[SelectedItem] = Inventory.Instance.ItemSlots[targetSlot]; Inventory.Instance.ItemSlots[targetSlot] = item; SelectedItem = -1; } } } } else if (Input.GetKey(KeyCode.LeftControl)) { if (SelectedItem > -1 && CustomCrafting.instance.craftMode != CustomCrafting.CraftMode.None) { if (CustomCrafting.instance.changedItem.i == null) { CustomCrafting.instance.changedItem.Assign(SelectedItem, Inventory.Instance.ItemSlots[SelectedItem]); } else { int max = CustomCrafting.instance.CurrentCraftingMode.IngredientCount; for (int j = 0; j < max; j++) { if (CustomCrafting.Ingredients[j].i == null) { if (!(CustomCrafting.Ingredients.Any(x => x.i == item) || CustomCrafting.instance.changedItem.i == item)) { CustomCrafting.Ingredients[j].Assign(SelectedItem, item); DraggedItem = null; DraggedItemIndex = -1; isDragging = false; break; } } } } } } } } } else if (consumedsomething) { consumedsomething = false; } //LocalPlayer.FpCharacter.LockView(false); LevelsToGain = 0; if (Input.GetKeyDown(KeyCode.Escape)) { StartCoroutine(FadeMenuSwitch(OpenedMenuMode.Hud)); } } else { if (LevelsToGain > 0) { if (ProgressBarAmount < 1) { ProgressBarAmount = Mathf.MoveTowards(ProgressBarAmount, 1, Time.unscaledDeltaTime * 2); } else { LevelsToGain--; ProgressBarAmount = 0; } } else { if (ProgressBarAmount < (float)ModdedPlayer.instance.ExpCurrent / ModdedPlayer.instance.ExpGoal) { ProgressBarAmount = Mathf.MoveTowards(ProgressBarAmount, Convert.ToSingle((float)ModdedPlayer.instance.ExpCurrent / ModdedPlayer.instance.ExpGoal), Time.unscaledDeltaTime / 2); } else { ProgressBarAmount = Convert.ToSingle((float)ModdedPlayer.instance.ExpCurrent / ModdedPlayer.instance.ExpGoal); } } ProgressBarAmount = Mathf.Clamp01(ProgressBarAmount); } isCrouching = LocalPlayer.FpCharacter.crouching; if (ModAPI.Input.GetButtonDown("MenuToggle")) { MenuKeyPressAction(); } }
/// <summary> /// Update controller. /// </summary> public void Update() { if (!UInput.mousePresent) { return; } if (mouseDeviceManager == null) { // Get the instance of the mouse device manager. IMixedRealityDataProviderAccess dataProviderAccess = CoreServices.InputSystem as IMixedRealityDataProviderAccess; mouseDeviceManager = dataProviderAccess?.GetDataProvider <IMixedRealityMouseDeviceManager>(); } // Bail early if our mouse isn't in our game window. if (UInput.mousePosition.x < 0 || UInput.mousePosition.y < 0 || UInput.mousePosition.x > Screen.width || UInput.mousePosition.y > Screen.height) { return; } for (int i = 0; i < Interactions.Length; i++) { if ((Interactions[i].InputType == DeviceInputType.SpatialPointer) || (Interactions[i].InputType == DeviceInputType.PointerPosition)) { Vector3 mouseDelta = Vector3.zero; mouseDelta.x = -UInput.GetAxis("Mouse Y"); mouseDelta.y = UInput.GetAxis("Mouse X"); if (mouseDeviceManager != null) { // Apply cursor speed. mouseDelta *= mouseDeviceManager.CursorSpeed; } if (Interactions[i].InputType == DeviceInputType.SpatialPointer) { // Spatial pointer raises Pose events controllerPose = MixedRealityPose.ZeroIdentity; controllerPose.Rotation = Quaternion.Euler(mouseDelta); Interactions[i].PoseData = controllerPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } } else { // Pointer position raises position events Interactions[i].Vector2Data = mouseDelta; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data); } } } if (Interactions[i].AxisType == AxisType.Digital) { var keyButton = UInput.GetKey(Interactions[i].KeyCode); // Update the interaction data source Interactions[i].BoolData = keyButton; // If our value changed raise it. if (Interactions[i].Changed) { // Raise input system event if it's enabled if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } } if (Interactions[i].InputType == DeviceInputType.Scroll) { Vector2 wheelDelta = UInput.mouseScrollDelta; if (mouseDeviceManager != null) { // Apply wheel speed. wheelDelta *= mouseDeviceManager.WheelSpeed; } Interactions[i].Vector2Data = wheelDelta; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data); } } } }
public static float GetAxis(string name) { return(UnityInput.GetAxis(name)); }
/// <summary> /// Update controller. /// </summary> public void Update() { if (!UInput.mousePresent) { return; } // Bail early if our mouse isn't in our game window. if (UInput.mousePosition.x < 0 || UInput.mousePosition.y < 0 || UInput.mousePosition.x > Screen.width || UInput.mousePosition.y > Screen.height) { return; } if (InputSource.Pointers[0].BaseCursor != null) { controllerPose.Position = InputSource.Pointers[0].BaseCursor.Position; controllerPose.Rotation = InputSource.Pointers[0].BaseCursor.Rotation; } mouseDelta.x = -UInput.GetAxis("Mouse Y"); mouseDelta.y = UInput.GetAxis("Mouse X"); MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, mouseDelta); //MixedRealityToolkit.InputSystem?.RaiseSourcePoseChanged(InputSource, this, controllerPose); //MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, UInput.mouseScrollDelta); for (int i = 0; i < Interactions.Length; i++) { if (Interactions[i].InputType == DeviceInputType.SpatialPointer) { Interactions[i].PoseData = controllerPose; if (Interactions[i].Changed) { MixedRealityToolkit.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } } if (Interactions[i].InputType == DeviceInputType.PointerPosition) { Interactions[i].Vector2Data = mouseDelta; if (Interactions[i].Changed) { MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data); } } if (Interactions[i].InputType == DeviceInputType.Scroll) { Interactions[i].Vector2Data = UInput.mouseScrollDelta; if (Interactions[i].Changed) { //MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data); } } if (Interactions[i].AxisType == AxisType.Digital) { var keyButton = UInput.GetKey(Interactions[i].KeyCode); // Update the interaction data source Interactions[i].BoolData = keyButton; // If our value changed raise it. if (Interactions[i].Changed) { // Raise input system Event if it enabled if (Interactions[i].BoolData) { MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } } } }
void Update() { LastFrame = CurrentFrame; CurrentFrame.MouseLeftHeld = I.GetMouseButton(0); CurrentFrame.MouseLeftDown = I.GetMouseButtonDown(0); CurrentFrame.MouseLeftUp = I.GetMouseButtonUp(0); CurrentFrame.MouseRightHeld = I.GetMouseButton(1); CurrentFrame.MouseRightDown = I.GetMouseButtonDown(1); CurrentFrame.MouseRightUp = I.GetMouseButtonUp(1); CurrentFrame.MouseMiddleHeld = I.GetMouseButton(2); CurrentFrame.MouseMiddleDown = I.GetMouseButtonDown(2); CurrentFrame.MouseMiddleUp = I.GetMouseButtonUp(2); CurrentFrame.MouseScreenPosition = UnityEngine.Input.mousePosition; CurrentFrame.MouseScreenDelta = CurrentFrame.MouseScreenPosition - LastFrame.MouseScreenPosition; CurrentFrame.MouseLeftDragging = CurrentFrame.MouseLeftHeld; CurrentFrame.MouseLeftDragStarted = CurrentFrame.MouseLeftDragging && !LastFrame.MouseLeftDragging; CurrentFrame.MouseLeftDragStopped = !CurrentFrame.MouseLeftDragging && LastFrame.MouseLeftDragging; CurrentFrame.MouseRightDragging = CurrentFrame.MouseRightHeld; CurrentFrame.MouseRightDragStarted = CurrentFrame.MouseRightDragging && !LastFrame.MouseRightDragging; CurrentFrame.MouseRightDragStopped = !CurrentFrame.MouseRightDragging && LastFrame.MouseRightDragging; var mainCamera = CameraController.Instance; var ray = mainCamera.MainCamera.ScreenPointToRay(CurrentFrame.MouseScreenPosition); CurrentFrame.MouseScreenPositionLeftDown = CurrentFrame.MouseLeftDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionLeftDown; CurrentFrame.MouseScreenPositionRightDown = CurrentFrame.MouseRightDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionRightDown; CurrentFrame.MouseScreenPositionMiddleDown = CurrentFrame.MouseMiddleDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionMiddleDown; if (Physics.RaycastNonAlloc(ray, m_Results) > 0) { CurrentFrame.MouseLocalPosition = m_Results[0].point / mainCamera.Data.Units; CurrentFrame.MouseLocalDelta = CurrentFrame.MouseLeftDragStarted ? float3.zero : CurrentFrame.MouseLocalPosition - LastFrame.MouseLocalPosition; CurrentFrame.MouseWorldPosition = mainCamera.Data.LookAtPosition + CurrentFrame.MouseLocalPosition; CurrentFrame.MouseWorldDelta = CurrentFrame.MouseLeftDragStarted ? double3.zero : CurrentFrame.MouseWorldPosition - LastFrame.MouseWorldPosition; } else { CurrentFrame.MouseLocalPosition = LastFrame.MouseLocalPosition; CurrentFrame.MouseLocalDelta = LastFrame.MouseLocalDelta; CurrentFrame.MouseWorldPosition = LastFrame.MouseWorldPosition; CurrentFrame.MouseWorldDelta = LastFrame.MouseWorldDelta; } var topLeft = mainCamera.MainCamera.ScreenPointToRay(new Vector3(Screen.width, Screen.height, 0f)); if (Physics.RaycastNonAlloc(topLeft, m_Results) > 0) { CurrentFrame.TopLeftLocalPosition = m_Results[0].point / mainCamera.Data.Units; CurrentFrame.TopLeftWorldPosition = mainCamera.Data.LookAtPosition + CurrentFrame.TopLeftLocalPosition; } else { CurrentFrame.TopLeftLocalPosition = LastFrame.TopLeftLocalPosition; CurrentFrame.TopLeftWorldPosition = LastFrame.TopLeftWorldPosition; } CurrentFrame.PrimaryAxis = new float2(I.GetAxis("Horizontal"), I.GetAxis("Vertical")); CurrentFrame.SecondaryAxis = new float2(I.GetAxis("Mouse ScrollWheel"), 0f); CurrentFrame.MouseLeftClicked = CurrentFrame.MouseLeftUp && LastFrame.MouseLeftHeld && math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionLeftDown) < 2; CurrentFrame.MouseRightClicked = CurrentFrame.MouseRightUp && LastFrame.MouseRightHeld && math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionRightDown) < 2; CurrentFrame.MouseMiddleClicked = CurrentFrame.MouseMiddleUp && LastFrame.MouseMiddleHeld && math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionMiddleDown) < 2; CurrentFrame.PrimaryAction = I.GetAxis("Fire1") > 0f; CurrentFrame.SecondaryAction = I.GetAxis("Fire2") > 0f; CurrentFrame.TertiaryAction = I.GetAxis("Fire3") > 0f; CurrentFrame.QuaternaryAction = I.GetAxis("Jump") > 0f; CurrentFrame.CycleForwardAction = I.GetKeyUp(KeyCode.Equals); CurrentFrame.CycleBackwardAction = I.GetKeyUp(KeyCode.Minus); CurrentFrame.CancelAction = I.GetKeyUp(KeyCode.Escape); CurrentFrame.SubActions[0] = I.GetKeyUp(KeyCode.F1); CurrentFrame.SubActions[1] = I.GetKeyUp(KeyCode.F2); CurrentFrame.SubActions[2] = I.GetKeyUp(KeyCode.F3); CurrentFrame.SubActions[3] = I.GetKeyUp(KeyCode.F4); CurrentFrame.SubActions[4] = I.GetKeyUp(KeyCode.F5); CurrentFrame.SubActions[5] = I.GetKeyUp(KeyCode.F6); CurrentFrame.SubActions[6] = I.GetKeyUp(KeyCode.F7); CurrentFrame.SubActions[7] = I.GetKeyUp(KeyCode.F8); CurrentFrame.SubActions[8] = I.GetKeyUp(KeyCode.F9); CurrentFrame.SubActions[9] = I.GetKeyUp(KeyCode.F10); CurrentFrame.SubActions[10] = I.GetKeyUp(KeyCode.F11); CurrentFrame.SubActions[11] = I.GetKeyUp(KeyCode.F12); }