public void OnRecentered(ControllerHandEnum handEnum) { if (handEnum != defaultHandEnum) { return; } Vector3 horizontalFoward = Vector3.ProjectOnPlane(m_CameraCenter.forward, Vector3.up); m_VerifyYAngle = Mathf.Sign(Vector3.Cross(Vector3.forward, horizontalFoward).y) * Vector3.Angle(horizontalFoward, Vector3.forward); }
/** * @brief Trigger vibration of a certain handedness controller */ public static void TriggerHapticVibration(ControllerHandEnum hand, float durationSeconds = 0.1f, float frequency = 200f, float amplitude = 0.8f) { if (!HapticVibrationEnabled) { return; } if (GetAvailableControllersCount() == 0) { return; } m_ControllerProvider.TriggerHapticVibration(ConvertHandToIndex(hand), durationSeconds, frequency, amplitude); }
/** * @brief Set the current enumeration of handedness. */ public static void SetDomainHandMode(ControllerHandEnum handEnum) { if (m_DomainHand == handEnum) { return; } m_DomainHand = handEnum; if (OnDomainHandChanged != null) { OnDomainHandChanged(m_DomainHand); } }
/// <summary> Updates this object. </summary> private void Update() { if (NRInput.GetAvailableControllersCount() < 2) { m_CurrentDebugHand = NRInput.DomainHand; } else { if (NRInput.GetButtonDown(ControllerHandEnum.Right, ControllerButton.TRIGGER)) { m_CurrentDebugHand = ControllerHandEnum.Right; } else if (NRInput.GetButtonDown(ControllerHandEnum.Left, ControllerButton.TRIGGER)) { m_CurrentDebugHand = ControllerHandEnum.Left; } } if (NRInput.GetButtonDown(m_CurrentDebugHand, ControllerButton.TRIGGER)) { AddExtraInfo("trigger_btn_down"); } if (NRInput.GetButtonDown(m_CurrentDebugHand, ControllerButton.HOME)) { AddExtraInfo("home_btn_down"); } if (NRInput.GetButtonDown(m_CurrentDebugHand, ControllerButton.APP)) { AddExtraInfo("app_btn_down"); } if (NRInput.GetButtonUp(m_CurrentDebugHand, ControllerButton.TRIGGER)) { AddExtraInfo("trigger_btn_up"); } if (NRInput.GetButtonUp(m_CurrentDebugHand, ControllerButton.HOME)) { AddExtraInfo("home_btn_up"); } if (NRInput.GetButtonUp(m_CurrentDebugHand, ControllerButton.APP)) { AddExtraInfo("app_btn_up"); } FollowMainCam(); RefreshInfoTexts(); }
/** * @brief Returns true if the controller */ public static bool CheckControllerAvailable(ControllerHandEnum handEnum) { int availableCount = GetAvailableControllersCount(); if (availableCount == 2) { return(true); } if (availableCount == 1) { return(handEnum == DomainHand); } return(false); }
/** * @brief Add button up event listerner */ public static void AddUpListener(ControllerHandEnum hand, ControllerButton button, Action action) { GetControllerState(hand).AddButtonListener(ButtonEventType.Up, button, action); }
/** * @brief Returns the battery level of a certain handedness controller, range from 0 to 100 */ public static int GetControllerBattery(ControllerHandEnum hand) { return(GetControllerState(hand).batteryLevel); }
/** * @brief Returns the magnetic sensor value of a certain handedness controller */ public static Vector3 GetMag(ControllerHandEnum hand) { return(GetControllerState(hand).mag); }
/** * @brief Returns the accel sensor value of a certain handedness controller */ public static Vector3 GetAccel(ControllerHandEnum hand) { return(GetControllerState(hand).accel); }
// Update is called once per frame void Update() { // コントローラ(左手右手)情報の取得 // 複数のコントローラを使用している場合、使用したコントローラを判断するための処理。 // 今後のハンドジェスチャーを見越しての処理か? if (NRInput.GetAvailableControllersCount() < 2) { m_CurrentDebugHand = NRInput.DomainHand; } else { if (NRInput.GetButtonDown(ControllerHandEnum.Right, ControllerButton.TRIGGER)) { m_CurrentDebugHand = ControllerHandEnum.Right; } else if (NRInput.GetButtonDown(ControllerHandEnum.Left, ControllerButton.TRIGGER)) { m_CurrentDebugHand = ControllerHandEnum.Left; } } // Trigger以外のボタン動作をハンドリングするにはIPointerDownHandlerではなく、Updateでハンドリングする // Triggerだけで良ければIPointerDownHandler/IPointerUpHandlerで実装するほうが良い if (NRInput.GetButtonDown(this.m_CurrentDebugHand, ControllerButton.APP)) { this.director.WriteLog("OnPointerDown_APP"); this.currentDownButton = ControllerButton.APP; if (this.unityChanEnterState) { GetComponent <Animator>().SetTrigger("doJump"); } } else if (NRInput.GetButtonDown(this.m_CurrentDebugHand, ControllerButton.TRIGGER)) { this.director.WriteLog("OnPointerDown_TRIGGER"); this.currentDownButton = ControllerButton.TRIGGER; } else if (NRInput.GetButtonDown(this.m_CurrentDebugHand, ControllerButton.GRIP)) { this.director.WriteLog("OnPointerDown_GRID"); this.currentDownButton = ControllerButton.GRIP; } else if (NRInput.GetButtonDown(this.m_CurrentDebugHand, ControllerButton.HOME)) { this.director.WriteLog("OnPointerDown_HOME"); this.currentDownButton = ControllerButton.HOME; } else if (NRInput.GetButtonDown(this.m_CurrentDebugHand, ControllerButton.TOUCHPAD_BUTTON)) { this.director.WriteLog("OnPointerDown_TOUCHPAD_BUTTON"); this.currentDownButton = ControllerButton.TOUCHPAD_BUTTON; } if (NRInput.GetButtonUp(this.m_CurrentDebugHand, ControllerButton.APP) || NRInput.GetButtonUp(this.m_CurrentDebugHand, ControllerButton.TRIGGER) || NRInput.GetButtonUp(this.m_CurrentDebugHand, ControllerButton.GRIP) || NRInput.GetButtonUp(this.m_CurrentDebugHand, ControllerButton.HOME) || NRInput.GetButtonUp(this.m_CurrentDebugHand, ControllerButton.TOUCHPAD_BUTTON)) { this.director.WriteLog("OnPointerUp_all"); this.currentDownButton = 0; } }
/** * @brief Returns the current position of a certain handedness controller if 6dof, otherwise returns Vector3.zero */ public static Vector3 GetPosition(ControllerHandEnum hand) { return(GetControllerState(hand).position); }
/** * @brief Returns a Vector2 delta touch value on touchpad of a certain handedness controller */ public static Vector2 GetDeltaTouch(ControllerHandEnum hand) { return(GetControllerState(hand).deltaTouch); }
/** * @brief Returns a Vector2 touch position on touchpad of a certain handedness controller, range: x(-1f ~ 1f), y(-1f ~ 1f). */ public static Vector2 GetTouch(ControllerHandEnum hand) { return(GetControllerState(hand).touchPos); }
/** * @brief Returns true if the button was released this frame on a certain handedness controller. */ public static bool GetButtonUp(ControllerHandEnum hand, ControllerButton button) { return(GetControllerState(hand).GetButtonUp(button)); }
private static ControllerState GetControllerState(ControllerHandEnum hand) { return(m_States[ConvertHandToIndex(hand)]); }
/** * @brief Remove button click event listerner */ public static void RemoveClickListener(ControllerHandEnum hand, ControllerButton button, Action action) { GetControllerState(hand).RemoveButtonListener(ButtonEventType.Click, button, action); }
/** * @brief Returns the current rotation of a certain handedness controller */ public static Quaternion GetRotation(ControllerHandEnum hand) { return(GetControllerState(hand).rotation); }
/** * @brief Returns the gyro sensor value of a certain handedness controller */ public static Vector3 GetGyro(ControllerHandEnum hand) { return(GetControllerState(hand).gyro); }
private static bool IsTouching(ControllerHandEnum hand) { // return GetControllerState(hand).isTouching; // BUG always true on emulator return(GetTouch(hand).sqrMagnitude > float.Epsilon * float.Epsilon); }
/// <summary> /// Returns true if the touchpad is being touched this frame on a certain handedness controller /// </summary> public static bool IsTouching(ControllerHandEnum hand) { return(GetControllerState(hand).isTouching); }