public bool IsQuatConn() { if (debugInEditor) { return(true); } if (gamepadEnabled) { if (NxrControllerHelper.Is3DofControllerConnected) { return(true); } if (InteractionManager.IsInteractionSDKEnabled()) { return(InteractionManager.Is3DofControllerConnected()); } #if UNITY_ANDROID && !UNITY_EDITOR return(ControllerAndroid.isQuatConn()); #endif } return(false); }
void Start() { HeadPosition = Vector3.zero; nxrArmModel = GetComponent <NxrArmModel>(); #if UNITY_ANDROID && !UNITY_EDITOR if (!InteractionManager.IsInteractionSDKEnabled()) { ControllerAndroid.onStart(); NibiruTaskApi.setOnDeviceListener(OnDeviceConnectState); } #endif }
string GetControllerName() { int deviceType = ControllerAndroid.getDeviceType(); if (deviceType == CDevice.DEVICE_CLEER) { return(Controller_Name_CLEER); } else if (deviceType == CDevice.DEVICE_XIMMERSE) { return(Controller_Name_XIMMERSE); } return(Controller_Name_DEFAULT); }
private void HandlePendingClick() { if (!pointerData.eligibleForClick && !pointerData.dragging) { return; } if (gazePointer != null) { Camera camera = pointerData.enterEventCamera; gazePointer.OnGazeTriggerEnd(camera); } var go = pointerData.pointerCurrentRaycast.gameObject; // Send pointer up and click events. ExecuteEvents.Execute(pointerData.pointerPress, pointerData, ExecuteEvents.pointerUpHandler); // 符合资格的点击 if (pointerData.eligibleForClick) { if (NxrViewer.Instance != null) { if (NxrViewer.Instance.HeadControl != HeadControl.Hover || (NxrPlayerCtrl.Instance.IsQuatConn() || ControllerAndroid.IsNoloConn())) { ExecuteEvents.Execute(pointerData.pointerPress, pointerData, ExecuteEvents.pointerClickHandler); } } } else if (pointerData.dragging) { ExecuteEvents.ExecuteHierarchy(go, pointerData, ExecuteEvents.dropHandler); ExecuteEvents.Execute(pointerData.pointerDrag, pointerData, ExecuteEvents.endDragHandler); } // Clear the click state. pointerData.pointerPress = null; pointerData.rawPointerPress = null; pointerData.eligibleForClick = false; pointerData.clickCount = 0; pointerData.clickTime = 0; pointerData.pointerDrag = null; pointerData.dragging = false; }
public override void Process() { //when ime show unity is still running, disable input process if (TouchScreenKeyboard.visible) { NxrViewer.Instance.Triggered = false; pointerData.eligibleForClick = false; return; } #if UNITY_ANDROID && !ANDROID_REMOTE_NRR if ((NxrPlayerCtrl.Instance.GamepadEnabled && NibiruTaskApi.IsQuatConn()) || ControllerAndroid.IsNoloConn()) #elif UNITY_STANDALONE_WIN || ANDROID_REMOTE_NRR if (NxrControllerHelper.IsLeftNoloControllerConnected || NxrControllerHelper.IsRightNoloControllerConnected) { CastRayFromController(true); if (isShowGaze) { NxrViewer.Instance.GazeApi(GazeTag.Hide, ""); isShowGaze = false; } } else if (NxrControllerHelper.Is3DofControllerConnected) #else if (true) #endif { // 3dof/6dof controller CastRayFromGamepad(); if (isShowGaze) { NxrViewer.Instance.SwitchControllerMode(true); isShowGaze = false; } } else { if (!isShowGaze) { NxrViewer.Instance.SwitchControllerMode(false); isShowGaze = true; pointerData.pointerPress = null; HandlePointerExitAndEnter(pointerData, null); } // Save the previous Game Object GameObject gazeObjectPrevious = GetCurrentGameObject(); CastRayFromGaze(); UpdateCurrentObject(); UpdateReticle(gazeObjectPrevious); } if (!pointerData.eligibleForClick && NxrViewer.Instance.Triggered) { // New trigger action. ok键->click HandleTrigger(); NxrViewer.Instance.Triggered = false; } else if (!NxrViewer.Instance.Triggered) { // Check if there is a pending click to handle. HandlePendingClick(); } else if (pointerData.eligibleForClick && NxrViewer.Instance.Triggered) { NxrViewer.Instance.Triggered = false; } }
private void processControllerKeyEvent(int noloType) { int handType = noloType == (int)CDevice.NOLO_TYPE.LEFT ? (int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT : (int)InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT; initState(); _prevStates = _currentStates; lastState = curState; float[] touchInfo = new float[] { 0, CKeyEvent.ACTION_UP, 0, 0 }; // type-action-x-y if (InteractionManager.IsInteractionSDKEnabled()) { curState = InteractionManager.GetKeyAction(handType); touchInfo[1] = curState[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH]; if (noloType == (int)CDevice.NOLO_TYPE.LEFT) { Vector3 pos = InteractionManager.TouchPadPositionLeft; touchInfo[2] = pos.x; touchInfo[3] = pos.y; } else { Vector3 pos = InteractionManager.TouchPadPositionRight; touchInfo[2] = pos.x; touchInfo[3] = pos.y; } } else { touchInfo = ControllerAndroid.getTouchEvent(noloType, 1); curState = ControllerAndroid.getKeyState(noloType, 1); } // N int btnNibiru = curState[CKeyEvent.KEYCODE_BUTTON_NIBIRU]; int btnStart = curState[CKeyEvent.KEYCODE_BUTTON_START]; // Side A/B int btnSelect = curState[CKeyEvent.KEYCODE_BUTTON_SELECT]; // Menu int btnApp = curState[CKeyEvent.KEYCODE_BUTTON_APP]; // TouchPad int btnCenter = curState[CKeyEvent.KEYCODE_DPAD_CENTER]; // Trigger int btnR1 = curState[CKeyEvent.KEYCODE_BUTTON_R1]; int btnR2 = curState[CKeyEvent.KEYCODE_BUTTON_R2]; int btnInternalTrigger = curState[CKeyEvent.KEYCODE_CONTROLLER_TRIGGER_INTERNAL]; // Nolo TouchPad = Center // Nolo Menu = App // Nolo Trigger = R1 // Nolo Side = Select // Debug.LogError("=======>_currentStates.buttons=" + _currentStates.buttons); if (touchInfo[1] == CKeyEvent.ACTION_MOVE) { _currentStates.touches |= 1 << (int)ButtonID.TrackpadTouch; _currentStates.touchpadAxis = new Vector2(touchInfo[2], touchInfo[3]); } else if (touchInfo[1] == CKeyEvent.ACTION_UP && ((_currentStates.touches & (1 << (int)ButtonID.TrackpadTouch)) != 0)) { _currentStates.touches = 0; _currentStates.touchpadAxis = new Vector2(0, 0); } if (btnCenter == 0) { // down _currentStates.buttons |= 1 << (int)ButtonID.TouchPad; } else if (lastState[CKeyEvent.KEYCODE_DPAD_CENTER] == 0) { // up _currentStates.buttons -= 1 << (int)ButtonID.TouchPad; } if (btnApp == 0) { _currentStates.buttons |= 1 << (int)ButtonID.Menu; } else if (lastState[CKeyEvent.KEYCODE_BUTTON_APP] == 0) { _currentStates.buttons -= 1 << (int)ButtonID.Menu; } if (btnR1 == 0 || btnR2 == 0) { _currentStates.buttons |= 1 << (int)ButtonID.Trigger; } else if (lastState[CKeyEvent.KEYCODE_BUTTON_R1] == 0 || lastState[CKeyEvent.KEYCODE_BUTTON_R2] == 0) { _currentStates.buttons -= 1 << (int)ButtonID.Trigger; } if (btnInternalTrigger == 0) { _currentStates.buttons |= 1 << (int)ButtonID.InternalTrigger; } else if (lastState[CKeyEvent.KEYCODE_CONTROLLER_TRIGGER_INTERNAL] == 0) { _currentStates.buttons -= 1 << (int)ButtonID.InternalTrigger; } if (btnSelect == 0) { _currentStates.buttons |= 1 << (int)ButtonID.Grip; } else if (lastState[CKeyEvent.KEYCODE_BUTTON_SELECT] == 0) { _currentStates.buttons -= 1 << (int)ButtonID.Grip; } //Debug.LogError("=====>" + _currentStates.buttons + "->Start=" + btnStart + // "->Nibiru=" + btnNibiru + // "->Select=" + btnSelect + // "->App=" + btnApp + // "->Center=" + btnCenter + // "->R1=" + btnR1); }
// Update is called once per frame void Update() { #if UNITY_ANDROID //&& !UNITY_EDITOR if (!NxrViewer.Instance.IsWinPlatform && !isGamePad) { // Android/NOLO int noloType = GetNoloType(); int handType = noloType == (int)CDevice.NOLO_TYPE.LEFT ? (int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT : (int)InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT; bool isConnected = false; if (InteractionManager.IsInteractionSDKEnabled()) { isConnected = InteractionManager.IsSixDofControllerConnected(handType); } else { isConnected = ControllerAndroid.isDeviceConn(noloType); } if (DebugInEditor) { isConnected = true; } if (_currentStates.connectStatus == 0 && isConnected) { NxrViewer.Instance.SwitchControllerMode(true); _currentStates.connectStatus = 1; NxrPlayerCtrl mNxrPlayerCtrl = NxrPlayerCtrl.Instance; if (mNxrPlayerCtrl != null) { // 关闭3dof手柄显示 mNxrPlayerCtrl.GamepadEnabled = false; // 关闭白点显示 } } else if (_currentStates.connectStatus == 1 && !isConnected) { _currentStates.connectStatus = 0; } //Debug.Log("status="+_currentStates.connectStatus + ", " + deviceType.ToString() + "," // + ControllerAndroid.isDeviceConn((int) CDevice.NOLO_TYPE.LEFT) + ", " + ControllerAndroid.isDeviceConn((int)CDevice.NOLO_TYPE.RIGHT)); if (!IsConneted() && controllerModel != null && controllerModel.gameObject.activeSelf) { if (controllerPower != null) { controllerPower.gameObject.SetActive(false); } controllerModel.gameObject.SetActive(false); laserPointer.holder.SetActive(false); NxrControllerHelper.ControllerRaycastObject = null; Debug.Log("controllerModel Dismiss " + deviceType + "," + controllerModel.gameObject.activeSelf); } else if (IsConneted() && controllerModel != null && !controllerModel.gameObject.activeSelf) { if (controllerPower != null) { controllerPower.gameObject.SetActive(true); } controllerModel.gameObject.SetActive(true); laserPointer.holder.SetActive(true); Debug.Log("controllerModel Show " + deviceType); } if (GetButtonUp(ButtonID.InternalTrigger)) { NxrSDKApi.Instance.SixDofControllerPrimaryDeviceType = deviceType; Debug.Log("IsPrimaryControllerHand " + deviceType.ToString()); } if (laserPointer != null && controllerModel != null) { if (NxrSDKApi.Instance.SixDofControllerPrimaryDeviceType != deviceType) { // 非主手柄,隐藏射线 laserPointer.holder.SetActive(false); } else { laserPointer.holder.SetActive(controllerModel.gameObject.activeSelf); } } if (IsConneted()) { processControllerKeyEvent(noloType); float[] poseData = new float[8]; if (InteractionManager.IsSixDofControllerConnected(handType)) { float[] pose = InteractionManager.GetControllerPose((InteractionManager.NACTION_HAND_TYPE)handType); poseData[1] = pose[4]; poseData[2] = pose[5]; poseData[3] = pose[6]; for (int i = 0; i < 4; i++) { poseData[4 + i] = pose[i]; } } else { poseData = ControllerAndroid.getCPoseEvent(noloType, 1); } if (NxrViewer.Instance.SixDofMode == SixDofMode.Head_3Dof_Ctrl_6Dof) { Vector3 HeadPosition = NxrSDKApi.Instance.HeadPosition; // Debug.LogError(noloType + ".NOLO Controller Y: " + poseData[2] + "/HeadY=" + HeadPosition.y); poseData[1] = poseData[1] - HeadPosition.x; poseData[2] = poseData[2] - HeadPosition.y; poseData[3] = poseData[3] - HeadPosition.z; } else if (NxrViewer.Instance.SixDofMode == SixDofMode.Head_3Dof_Ctrl_3Dof) { var factor = handType == (int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT ? -1 : 1; var headPos = NxrViewer.Instance.GetHead().transform.localPosition; var pos = new Vector3(headPos.x + 0.25f * factor, headPos.y - 0.6f, headPos.z + 0.5f); poseData[1] = pos.x; poseData[2] = pos.y; poseData[3] = pos.z; } transform.localPosition = new Vector3(poseData[1], poseData[2], poseData[3]); transform.localRotation = new Quaternion(poseData[4], poseData[5], poseData[6], poseData[7]); } } #endif #if UNITY_STANDALONE_WIN if (NxrInstantNativeApi.Inited) { _prevStates = _currentStates; _currentStates = NxrInstantNativeApi.GetControllerStates(deviceType); if (isGamePad) { // 3dof手柄左右手模式切换 if (!IsConneted()) { _currentStates = NxrInstantNativeApi.GetControllerStates(NxrInstantNativeApi.NibiruDeviceType.LeftController); if (!IsConneted()) { deviceType = NxrInstantNativeApi.NibiruDeviceType.RightController; } else { NxrControllerHelper.HandMode3DOF = NxrControllerHelper.LEFT_HAND_MODE; deviceType = NxrInstantNativeApi.NibiruDeviceType.LeftController; Debug.Log("Current 3dof HandMode is Left !!!"); } } } if (!IsConneted() && controllerModel != null && controllerModel.gameObject.activeSelf) { controllerModel.gameObject.SetActive(false); laserPointer.holder.SetActive(false); if (deviceType == NxrInstantNativeApi.NibiruDeviceType.LeftController) { NxrControllerHelper.IsLeftNoloControllerConnected = false; } else if (deviceType == NxrInstantNativeApi.NibiruDeviceType.RightController) { NxrControllerHelper.IsRightNoloControllerConnected = false; } Debug.Log("controllerModel Dismiss " + deviceType + "," + controllerModel.gameObject.activeSelf); } else if (IsConneted() && controllerModel != null && !controllerModel.gameObject.activeSelf) { controllerModel.gameObject.SetActive(true); laserPointer.holder.SetActive(true); if (NxrControllerHelper.ControllerType == (int)NxrInstantNativeApi.NibiruControllerId.NOLO) { if (deviceType == NxrInstantNativeApi.NibiruDeviceType.LeftController) { NxrControllerHelper.IsLeftNoloControllerConnected = true; } else if (deviceType == NxrInstantNativeApi.NibiruDeviceType.RightController) { NxrControllerHelper.IsRightNoloControllerConnected = true; } } Debug.Log("controllerModel Show " + deviceType); } else if (!IsConneted() && isGamePad && NxrControllerHelper.Is3DofControllerConnected) { NxrControllerHelper.Is3DofControllerConnected = false; Debug.Log("Controller 3dof Dismiss."); } else if (IsConneted() && isGamePad && !NxrControllerHelper.Is3DofControllerConnected) { if (NxrControllerHelper.ControllerType == (int)NxrInstantNativeApi.NibiruControllerId.NORMAL_3DOF) { NxrControllerHelper.Is3DofControllerConnected = true; } Debug.Log("Controller 3dof Show." + NxrControllerHelper.ControllerType); } if (!isGamePad) { NxrInstantNativeApi.Nibiru_Pose pose = NxrInstantNativeApi.GetPoseByDeviceType(deviceType); // NOLO 非3DOF transform.localPosition = pose.position; transform.localRotation = new Quaternion(pose.rotation.x, pose.rotation.y, pose.rotation.z, pose.rotation.w); } } #endif }
void Update() { #if UNITY_ANDROID //&& !UNITY_EDITOR bool isQuatConn = IsQuatConn(); if (debugInEditor) { isQuatConn = true; } bool isNeedShowController = isQuatConn ? controllerModelDisplay : false; if (!isCreateControllerHandler && isNeedShowController) { CreateControllerHandler(); isCreateControllerHandler = true; } else if (isCreateControllerHandler && !isNeedShowController) { DestroyChild(mTransform); isCreateControllerHandler = false; debugInEditor = false; } if (isQuatConn) { //四元素 if (InteractionManager.IsControllerConnected()) { float[] res = InteractionManager.GetControllerPose(InteractionManager.GetHandTypeByHandMode()); controllerQuat.x = res[0]; controllerQuat.y = res[1]; controllerQuat.z = res[2]; controllerQuat.w = res[3]; } else { float[] res = ControllerAndroid.getQuat(1); controllerQuat.x = res[0]; controllerQuat.y = res[1]; controllerQuat.z = res[2]; controllerQuat.w = res[3]; } #if UNITY_EDITOR if (NxrViewer.Instance.RemoteDebug && NxrViewer.Instance.RemoteController) { controllerQuat = EditorRemoteQuat; } #endif //赋值 te.q为九轴传过来的四元数信息 mTransform.rotation = controllerQuat; if (nxrArmModel != null) { float factor = 1; if (InteractionManager.IsInteractionSDKEnabled()) { factor = InteractionManager.IsLeftControllerConnected() ? -1 : 1; } else if (ControllerAndroid.isQuatConn()) { factor = ControllerAndroid.getHandMode() == 0 ? 1 : -1; } nxrArmModel.OnControllerInputUpdated(); Vector3 armPos = new Vector3(nxrArmModel.ControllerPositionFromHead.x * factor, nxrArmModel.ControllerPositionFromHead.y, nxrArmModel.ControllerPositionFromHead.z); mTransform.position = HeadPosition + armPos; } if (NxrSDKApi.Instance.Is3DofSpriteFirstLoad && !isTipsCreated) { CreateTipImgs(); } else if (isTipsCreated) { ChangeTipAlpha(); } } #elif UNITY_STANDALONE_WIN || ANDROID_REMOTE_NRR if (NxrControllerHelper.Is3DofControllerConnected) { if (!NxrInstantNativeApi.Inited) { return; } _prevStates = _currentStates; NxrInstantNativeApi.NibiruDeviceType deviceTypeOf3dof = NxrControllerHelper.HandMode3DOF == NxrControllerHelper.LEFT_HAND_MODE ? NxrInstantNativeApi.NibiruDeviceType.LeftController : NxrInstantNativeApi.NibiruDeviceType.RightController; _currentStates = NxrInstantNativeApi.GetControllerStates(deviceTypeOf3dof); NxrInstantNativeApi.Nibiru_Pose pose = NxrInstantNativeApi.GetPoseByDeviceType(NxrInstantNativeApi.NibiruDeviceType.RightController); mTransform.rotation = new Quaternion(pose.rotation.x, pose.rotation.y, pose.rotation.z, pose.rotation.w); //3dof位移 if (nxrArmModel != null) { nxrArmModel.OnControllerInputUpdated(); mTransform.position = HeadPosition + nxrArmModel.ControllerPositionFromHead; } if (GetButtonDown(NxrTrackedDevice.ButtonID.TouchPad)) { int[] KeyAction = NibiruTaskApi.GetKeyAction(); KeyAction[CKeyEvent.KEYCODE_DPAD_CENTER] = 1; } if (GetButtonUp(NxrTrackedDevice.ButtonID.TouchPad)) { int[] KeyAction = NibiruTaskApi.GetKeyAction(); KeyAction[CKeyEvent.KEYCODE_DPAD_CENTER] = 0; } } #endif }
void OnApplicationQuit() { #if UNITY_ANDROID && !UNITY_EDITOR ControllerAndroid.onStop(); #endif }
void OnApplicationPause() { #if UNITY_ANDROID && !UNITY_EDITOR ControllerAndroid.onPause(); #endif }
// One Frame Update public void Process() { //when ime show unity is still running, disable input process if (TouchScreenKeyboard.visible) { NxrViewer.Instance.Triggered = false; return; } Array.Copy(KeyStateHMD, KeyStateHMD_Pre, MAX_INDEX); Array.Copy(KeyStateControllerLeft, KeyStateControllerLeft_Pre, MAX_INDEX); Array.Copy(KeyStateControllerRight, KeyStateControllerRight_Pre, MAX_INDEX); bool dpadCenterDown = Input.GetKey(KeyCode.JoystickButton0) || Input.GetKey((KeyCode)10) || Input.GetMouseButtonDown(0); bool backDown = Input.GetKey(KeyCode.Escape); bool dpadLeftDown = Input.GetKey(KeyCode.LeftArrow); bool dpadRightDown = Input.GetKey(KeyCode.RightArrow); bool dpadUpDown = Input.GetKey(KeyCode.UpArrow); bool dpadDownDown = Input.GetKey(KeyCode.DownArrow); // 功能按键nf1/nf2 bool nf1Down = Input.GetKey(KeyCode.Joystick6Button1); bool nf2Down = Input.GetKey(KeyCode.Joystick6Button2); bool dpadCenterUp = false; if ((!InteractionManager.IsControllerConnected() && !ControllerAndroid.isQuatConn() && !ControllerAndroid.IsNoloConn()) || Application.isEditor) { dpadCenterUp = Input.GetKeyUp(KeyCode.JoystickButton0) || Input.GetKeyUp((KeyCode)10) || Input.GetMouseButtonUp(0); } // 模拟一体机按键: WASD 上左下右,空格返回,回车确定 if (Application.isEditor) { dpadCenterDown = Input.GetKey(KeyCode.Return) || Input.GetMouseButton(0); dpadLeftDown = Input.GetKey(KeyCode.A); dpadRightDown = Input.GetKey(KeyCode.D); dpadUpDown = Input.GetKey(KeyCode.W); dpadDownDown = Input.GetKey(KeyCode.S); backDown = Input.GetKey(KeyCode.Space); } if (nf1Down) { KeyStateHMD[CKeyEvent.KEYCODE_NF_1] = CKeyEvent.ACTION_DOWN; } else { KeyStateHMD[CKeyEvent.KEYCODE_NF_1] = CKeyEvent.ACTION_UP; } if (nf2Down) { KeyStateHMD[CKeyEvent.KEYCODE_NF_2] = CKeyEvent.ACTION_DOWN; } else { KeyStateHMD[CKeyEvent.KEYCODE_NF_2] = CKeyEvent.ACTION_UP; } if (backDown) { KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_DOWN; } else { KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP; } if (dpadCenterUp) { NxrViewer.Instance.Triggered = true; } if (dpadCenterDown) { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_CENTER] = CKeyEvent.ACTION_DOWN; } else { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_CENTER] = CKeyEvent.ACTION_UP; } if (dpadLeftDown) { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_LEFT] = CKeyEvent.ACTION_DOWN; } else { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_LEFT] = CKeyEvent.ACTION_UP; } if (dpadRightDown) { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_RIGHT] = CKeyEvent.ACTION_DOWN; } else { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_RIGHT] = CKeyEvent.ACTION_UP; } if (dpadUpDown) { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_UP] = CKeyEvent.ACTION_DOWN; } else { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_UP] = CKeyEvent.ACTION_UP; } if (dpadDownDown) { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_DOWN] = CKeyEvent.ACTION_DOWN; } else { KeyStateHMD[CKeyEvent.KEYCODE_DPAD_DOWN] = CKeyEvent.ACTION_UP; } // 3Dof/6Dof Controller if (InteractionManager.IsControllerConnected()) { //3DOF Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX); int[] keyAction = InteractionManager.GetKeyAction(); KeyStateController3DOF = keyAction; // NOLO if (InteractionManager.IsSixDofController) { Array.Copy(KeyStateControllerNOLO_Left, KeyStateControllerNOLO_Left_Pre, MAX_INDEX); Array.Copy(KeyStateControllerNOLO_Right, KeyStateControllerNOLO_Right_Pre, MAX_INDEX); int[] keyActionLeft = InteractionManager.GetKeyAction((int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT); int[] keyActionRight = InteractionManager.GetKeyAction((int)InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT); KeyStateControllerNOLO_Left = keyActionLeft; KeyStateControllerNOLO_Right = keyActionRight; } } else if (ControllerAndroid.isQuatConn() || ControllerAndroid.IsNoloConn()) { // 交互库Close Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX); int[] keyAction = NibiruTaskApi.GetKeyAction(); KeyStateController3DOF = keyAction; // type, action, x, y float[] touchInfo = ControllerAndroid.getTouch(); if (touchInfo[1] == CKeyEvent.ACTION_MOVE) { InteractionManager.TouchPadPosition = new Vector2(touchInfo[2], touchInfo[3]); KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_DOWN; } else if (touchInfo[1] == CKeyEvent.ACTION_UP) { KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP; } bool isNoloLeftConnected = ControllerAndroid.isDeviceConn((int)CDevice.NOLO_TYPE.LEFT); bool isNoloRightConnected = ControllerAndroid.isDeviceConn((int)CDevice.NOLO_TYPE.RIGHT); if (isNoloLeftConnected) { Array.Copy(KeyStateControllerNOLO_Left, KeyStateControllerNOLO_Left_Pre, MAX_INDEX); int[] keyActionLeft = ControllerAndroid.getKeyState((int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT, 0); KeyStateControllerNOLO_Left = keyActionLeft; float[] touchInfoLeft = ControllerAndroid.getTouchEvent((int)CDevice.NOLO_TYPE.LEFT); if (touchInfoLeft[1] == CKeyEvent.ACTION_MOVE) { InteractionManager.TouchPadPosition = new Vector2(touchInfoLeft[2], touchInfoLeft[3]); KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_DOWN; } else if (touchInfoLeft[1] == CKeyEvent.ACTION_UP) { KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP; } } if (isNoloRightConnected) { Array.Copy(KeyStateControllerNOLO_Right, KeyStateControllerNOLO_Right_Pre, MAX_INDEX); int[] keyActionRight = ControllerAndroid.getKeyState((int)InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT, 0); KeyStateControllerNOLO_Right = keyActionRight; float[] touchInfoRight = ControllerAndroid.getTouchEvent((int)CDevice.NOLO_TYPE.RIGHT); if (touchInfoRight[1] == CKeyEvent.ACTION_MOVE) { InteractionManager.TouchPadPosition = new Vector2(touchInfoRight[2], touchInfoRight[3]); KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_DOWN; } else if (touchInfoRight[1] == CKeyEvent.ACTION_UP) { KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP; } } } // 3Dof/6Dof Controller if (Application.isEditor && NxrViewer.Instance.RemoteDebug && NxrViewer.Instance.RemoteController) { Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX); NibiruEmulatorManager nibiruEmulatorManager = NibiruEmulatorManager.Instance; Array.Copy(nibiruEmulatorManager.KeyStateController3DOF, KeyStateController3DOF, MAX_INDEX); } // 内部事件处理返回键逻辑 if (GetKeyUp(CKeyEvent.KEYCODE_BACK) || GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU) || GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU, InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) || GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU, InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT)) { bool EatBackKeyEvent = false; if (NibiruRemindBox.Instance && NibiruRemindBox.Instance.remindbox != null) { NibiruRemindBox.Instance.ReleaseDestory(); EatBackKeyEvent = true; } if (NibiruShutDownBox.Instance && NibiruShutDownBox.Instance.Showing()) { NibiruShutDownBox.Instance.ReleaseDestory(); EatBackKeyEvent = true; } if (NibiruKeyBoard.Instance.isShown()) { NibiruKeyBoard.Instance.Dismiss(); EatBackKeyEvent = true; Debug.Log("NibiruKeyBoard->Dismiss"); } if (EatBackKeyEvent) { Debug.Log("EatBackKeyEvent"); KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP; KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP; KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP; KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP; KeyStateHMD_Pre[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP; KeyStateController3DOF_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP; KeyStateControllerNOLO_Left_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP; KeyStateControllerNOLO_Right_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP; } } bool IsTouchpadUp = GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD) || GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD, InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) || GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD, InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT); if (IsTouchpadUp) { NxrViewer.Instance.Triggered = true; } }
// Update is called once per frame void Update() { #if UNITY_ANDROID if (Application.platform == RuntimePlatform.Android && (NxrPlayerCtrl.Instance.IsQuatConn() || ControllerAndroid.IsNoloConn())) { int[] KeyAction = null; if (InteractionManager.IsControllerConnected()) { KeyAction = InteractionManager.GetKeyAction(); } else { KeyAction = NibiruTaskApi.GetKeyAction(); } if (KeyAction[CKeyEvent.KEYCODE_DPAD_CENTER] == 0) { if (isCanUse) { isCanUse = false; Invoke("CanKey", m_dwInputClip); NibiruKeyBoard.Instance.OnPressEnterByQuat(); } } } Transform mTransform = NxrViewer.Instance.GetHead().transform; if (Input.GetKeyDown(KeyCode.I) || Input.GetKeyDown((KeyCode)10) || Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetMouseButtonDown(0)) { if (isCanUse) { isCanUse = false; Invoke("CanKey", m_dwInputClip); NibiruKeyBoard.Instance.OnPressEnterByCamera(); } } #else if (Input.GetMouseButtonDown(0)) { if (isCanUse) { isCanUse = false; Invoke("CanKey", m_dwInputClip); NibiruKeyBoard.Instance.OnPressEnterByCamera(); // OnPressEnterByMouse PC通过鼠标选中 } } #endif }