private void Awake() { if (m_Instance == null) { m_Instance = this; } }
public override void Update() { if (m_ProcessedFrame == Time.frameCount) { return; } m_ProcessedFrame = Time.frameCount; if (m_NeedInit) { InitNativeController(); return; } if (!Inited) { return; } int availableCount = ControllerCount; if (availableCount > 0 && NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_POSITION)) { UpdateHeadPoseToController(); } for (int i = 0; i < availableCount; i++) { UpdateControllerState(i); } }
void LateUpdate() { if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { UpdateControllerRotateByInput(); } if (NRInput.EmulateVirtualDisplayInEditor) { DefaultControllerPanel.SetActive(false); UpdateVirtualControllerButtons(); } else { DefaultControllerPanel.SetActive(true); UpdateDefaultControllerButtons(); } NREmulatorManager.Instance.NativeEmulatorApi.SetControllerSubmit(); if (NRInput.GetButtonDown(ControllerButton.TRIGGER)) { NRDebugger.Log("Click down Trigger button !!!"); } else if (NRInput.GetButtonDown(ControllerButton.APP)) { NRDebugger.Log("Click down App button !!!"); } else if (NRInput.GetButtonDown(ControllerButton.HOME)) { NRDebugger.Log("Click down Home button !!!"); } }
public override void TriggerHapticVibration(int index, float durationSeconds = 0.1f, float frequency = 1000f, float amplitude = 0.5f) { if (m_NativeController != null && NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_HAPTIC_VIBRATE)) { Int64 durationNano = (Int64)(durationSeconds * 1000000000); m_NativeController.TriggerHapticVibrate(index, durationNano, frequency, amplitude); } }
private void Update() { if (m_CameraCenter == null) { return; } m_IsEnabled = NRInput.CheckControllerAvailable(defaultHandEnum); UpdateTracker(); }
public virtual bool GetPressUp() { if (raycaster is NRMultScrPointerRaycaster) { return(MultiScreenController.SystemButtonState.pressUp); } else { return(NRInput.GetButtonUp(raycaster.RelatedHand, ControllerButton.TRIGGER)); } }
/// <summary> /// Force kill the app. /// </summary> public static void ForceKill(bool needrelease = true) { Debug.Log("[NRDevice] Start To kill Application, need release SDK:" + needrelease); if (needrelease) { NRInput.Destroy(); NRSessionManager.Instance.DestroySession(); } CallAndroidkillProcess(); }
private void TrackPose() { m_Is6dof = NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_POSITION) && NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ROTATION); if (m_Is6dof) { UpdatePosition(); } else { SmoothTrackTargetPosition(); } UpdateRotation(); }
private void UpdateTracker() { if (CameraCenter == null) { return; } m_IsEnabled = NRInput.CheckControllerAvailable(defaultHandEnum); raycaster.gameObject.SetActive(m_IsEnabled && NRInput.RaycastMode == RaycastModeEnum.Laser); modelAnchor.gameObject.SetActive(m_IsEnabled); if (m_IsEnabled) { TrackPose(); } }
public void UpdateAllVisuals() { int availableCount = NRInput.GetAvailableControllersCount(); if (availableCount > 1) { UpdateVisual(0, m_States[0]); UpdateVisual(1, m_States[1]); } else { int activeVisual = NRInput.DomainHand == ControllerHandEnum.Right ? 0 : 1; int deactiveVisual = NRInput.DomainHand == ControllerHandEnum.Right ? 1 : 0; UpdateVisual(activeVisual, m_States[0]); DestroyVisual(deactiveVisual); } }
private void TrackPose() { m_Is6dof = NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_POSITION) && NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ROTATION); if (m_Is6dof) { raycaster.transform.localPosition = Vector3.zero; modelAnchor.localPosition = Vector3.zero; UpdatePosition(); } else { raycaster.transform.localPosition = m_LaserDefaultLocalOffset; modelAnchor.localPosition = m_ModelDefaultLocalOffset; SmoothTrackTargetPosition(); } UpdateRotation(); }
public override void TriggerHapticVibration(int index, float durationSeconds = 0.1f, float frequency = 1000f, float amplitude = 0.5f) { if (!Inited) { return; } if (states[index].controllerType == ControllerType.CONTROLLER_TYPE_PHONE) { PhoneVibrateTool.TriggerVibrate(durationSeconds); } else { if (m_NativeController != null && NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_HAPTIC_VIBRATE)) { Int64 durationNano = (Int64)(durationSeconds * 1000000000); m_NativeController.TriggerHapticVibrate(index, durationNano, frequency, amplitude); } } }
private void UpdateGrabbles() { bool pressGrab = NRInput.GetButton(handEnum, grabButton); bool grabAction = !m_PreviousGrabPress && pressGrab; bool releaseAction = m_PreviousGrabPress && !pressGrab; m_PreviousGrabPress = pressGrab; if (grabAction && m_GrabbingList.Count == 0 && m_GrabReadyDict.Keys.Count != 0) { if (!grabMultiEnabled) { NRGrabbableObject nearestGrabble = GetNearestGrabbleObject(); if (nearestGrabble) { GrabTarget(nearestGrabble); } } else { foreach (NRGrabbableObject grabble in m_GrabReadyDict.Keys) { GrabTarget(grabble); } } SetChildrenCollidersEnabled(false); } if (releaseAction) { for (int i = 0; i < m_GrabbingList.Count; i++) { m_GrabbingList[0].GrabEnd(); } m_GrabbingList.Clear(); SetChildrenCollidersEnabled(true); } if (m_GrabbingList.Count > 0 && !grabAction) { MoveGrabbingObjects(); } }
public virtual bool GetPressUp() { return(NRInput.GetButtonUp(ControllerButton.TRIGGER)); }
public void ParserControllerState(ControllerState state) { if (!_screen_adapted) { AdaptPhoneScreenSize(); } _device_touch_x = state.touchPos.x; _device_touch_y = state.touchPos.y; _physical_button_down = _physical_button; _physical_button = (Mathf.Abs(_device_touch_x) > PRECISION || Mathf.Abs(_device_touch_y) > PRECISION); if (_device_touch_x < _touch_area_x_min || _device_touch_x > _touch_area_x_max || _device_touch_y < _touch_area_y_min || _device_touch_y > _touch_area_y_max || !_physical_button) { _touch_status = false; _touch.x = 0f; _touch.y = 0f; } else { _touch_status = true; _touch.x = _device_touch_x / (_touch_area_x_max - _touch_area_x_min) * 2f; _touch.y = (_device_touch_y - _touch_area_y_center) / (_touch_area_y_max - _touch_area_y_min) * 2f; } lock (_buttons) { lock (_down) { for (int i = 0; i < _buttons.Length; ++i) { _down[i] = _buttons[i]; } } if (_current_down_btn != -1) { _buttons[_current_down_btn] = _physical_button; if (!_buttons[_current_down_btn]) { _current_down_btn = -1; } } else { _buttons[0] = false; //Trigger _buttons[1] = false; //App _buttons[2] = false; //Home bool _is_down = !_physical_button_down & _physical_button; if (_touch_status) { _buttons[0] = _physical_button && _is_down; } else if (_device_touch_y > _touch_area_y_max) { _buttons[1] = _physical_button && _is_down; } else if (_device_touch_y < _touch_area_y_min) { _buttons[2] = _physical_button && _is_down; } _current_down_btn = -1; for (int i = 0; i < 3; i++) { if (_buttons[i]) { _current_down_btn = i; break; } } } lock (_buttons_up) { lock (_buttons_down) { for (int i = 0; i < _buttons.Length; ++i) { _buttons_up[i] = (_down[i] & !_buttons[i]); _buttons_down[i] = (!_down[i] & _buttons[i]); } } } } state.isTouching = _touch_status; state.touchPos = _touch; state.buttonsState = (_buttons[0] ? ControllerButton.TRIGGER : 0) | (_buttons[1] ? ControllerButton.APP : 0) | (_buttons[2] ? ControllerButton.HOME : 0); state.buttonsDown = (_buttons_down[0] ? ControllerButton.TRIGGER : 0) | (_buttons_down[1] ? ControllerButton.APP : 0) | (_buttons_down[2] ? ControllerButton.HOME : 0); state.buttonsUp = (_buttons_up[0] ? ControllerButton.TRIGGER : 0) | (_buttons_up[1] ? ControllerButton.APP : 0) | (_buttons_up[2] ? ControllerButton.HOME : 0); if (_buttons_down[0] || _buttons_down[1] || _buttons_down[2]) { NRInput.TriggerHapticVibration(0.1f); } }
void LateUpdate() { if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { UpdateControllerRotateByInput(); } if (Input.GetMouseButtonDown(0)) { SetConfirmButton(true); ImageConfirm.SetActive(true); } if (Input.GetMouseButtonUp(0)) { SetConfirmButton(false); ImageConfirm.SetActive(false); } if (Input.GetMouseButtonDown(2)) { SetAppButton(true); ImageApp.SetActive(true); } if (Input.GetMouseButtonUp(2)) { SetAppButton(false); ImageApp.SetActive(false); } if (Input.GetMouseButtonDown(1)) { SetHomeButton(true); ImageHome.SetActive(true); } if (Input.GetMouseButtonUp(1)) { SetHomeButton(false); ImageHome.SetActive(false); } if (m_TouchAction != TouchActionState.Idle) { UpdateTouchAction(); } else { if (Input.GetKeyDown(KeyCode.LeftArrow)) { ImageLeft.SetActive(true); m_TouchAction = TouchActionState.Left; } else if (Input.GetKeyDown(KeyCode.RightArrow)) { ImageRight.SetActive(true); m_TouchAction = TouchActionState.Right; } else if (Input.GetKeyDown(KeyCode.UpArrow)) { ImageUp.SetActive(true); m_TouchAction = TouchActionState.Up; } else if (Input.GetKeyDown(KeyCode.DownArrow)) { ImageDown.SetActive(true); m_TouchAction = TouchActionState.Down; } else if (Input.GetKeyUp(KeyCode.DownArrow) | Input.GetKeyUp(KeyCode.UpArrow) | Input.GetKeyUp(KeyCode.RightArrow) | Input.GetKeyUp(KeyCode.LeftArrow)) { NREmulatorManager.Instance.NativeEmulatorApi.SetControllerIsTouching(false); } } NREmulatorManager.Instance.NativeEmulatorApi.SetControllerSubmit(); if (NRInput.GetButtonDown(ControllerButton.TRIGGER)) { NRDebugger.Log("Click down Trigger button !!!"); } else if (NRInput.GetButtonDown(ControllerButton.APP)) { NRDebugger.Log("Click down App button !!!"); } else if (NRInput.GetButtonDown(ControllerButton.HOME)) { NRDebugger.Log("Click down Home button !!!"); } }
private void UpdatePosition() { transform.position = NRInput.GetPosition(defaultHandEnum); }
private void UpdatePosition() { transform.localPosition = m_DefaultLocalOffset + NRInput.GetPosition(defaultHandEnum); }
private void UpdateRotation() { transform.localRotation = NRInput.GetRotation(defaultHandEnum); transform.Rotate(Vector3.up * m_VerifyYAngle, Space.World); }