// Update is called once per frame void Update() { if (Pvr_UnitySDKAPI.Controller.UPvr_GetControllerState(0) == ControllerState.Connected) { if (head != null) { head.SetActive(false); } if (Pvr_UnitySDKAPI.System.UPvr_GetDeviceMode() == DeviceMode.PicoNeo) { Neo.SetActive(true); } else { Goblin.SetActive(true); } } else { if (head != null) { head.SetActive(true); } if (Pvr_UnitySDKAPI.System.UPvr_GetDeviceMode() == DeviceMode.PicoNeo) { Neo.SetActive(false); } else { Goblin.SetActive(false); } } #if UNITY_ANDROID //区分平台 if (controllerlink.cvserviceBindState) { if (controllerlink.controller0Connected) { //手柄0姿态数据 var pose0 = controllerlink.GetCvControllerPoseData(0); controllerlink.Controller0.Rotation = new Quaternion(pose0[0], pose0[1], pose0[2], pose0[3]); controllerlink.Controller0.Position = new Vector3(pose0[4] / 1000.0f, pose0[5] / 1000.0f, -pose0[6] / 1000.0f); //手柄0键值数据 var key0 = controllerlink.GetCvControllerKeyData(0); controllerlink.Controller0.TouchPadPosition = new Vector2(key0[0], key0[1]); //滑动手势判断 SetSwipeData(controllerlink.Controller0); //touchpad点击 SetTouchPadClick(controllerlink.Controller0); //HomeKey TransformData(controllerlink.Controller0.HomeKey, key0[2]); //AppKey TransformData(controllerlink.Controller0.AppKey, key0[3]); //TouchClickKey TransformData(controllerlink.Controller0.TouchKey, key0[4]); //VolumeuUpKey TransformData(controllerlink.Controller0.VolumeUpKey, key0[5]); //VolumeDownKey TransformData(controllerlink.Controller0.VolumeDownKey, key0[6]); //Trigger num controllerlink.Controller0.TriggerNum = key0[7]; //Trigger Click SetTriggerClick(controllerlink.Controller0); //Battery controllerlink.Controller0.Battery = key0[8]; } if (controllerlink.controller1Connected) { //手柄1姿态数据 var pose1 = controllerlink.GetCvControllerPoseData(1); controllerlink.Controller1.Rotation = new Quaternion(pose1[0], pose1[1], pose1[2], pose1[3]); controllerlink.Controller1.Position = new Vector3(pose1[4] / 1000.0f, pose1[5] / 1000.0f, -pose1[6] / 1000.0f); //手柄0键值数据 var key1 = controllerlink.GetCvControllerKeyData(1); controllerlink.Controller1.TouchPadPosition = new Vector2(key1[0], key1[1]); //滑动手势判断 SetSwipeData(controllerlink.Controller1); //touchpad点击 SetTouchPadClick(controllerlink.Controller1); //HomeKey TransformData(controllerlink.Controller1.HomeKey, key1[2]); //AppKey TransformData(controllerlink.Controller1.AppKey, key1[3]); //TouchClickKey TransformData(controllerlink.Controller1.TouchKey, key1[4]); //VolumeuUpKey TransformData(controllerlink.Controller1.VolumeUpKey, key1[5]); //VolumeDownKey TransformData(controllerlink.Controller1.VolumeDownKey, key1[6]); //Trigger num controllerlink.Controller1.TriggerNum = key1[7]; //Trigger Click SetTriggerClick(controllerlink.Controller1); //Battery controllerlink.Controller1.Battery = key1[8]; } } //Goblin controller if (controllerlink.hbserviceBindState && controllerlink.controller0Connected) { //手柄0姿态数据 var pose0 = controllerlink.GetHBControllerPoseData(); var jpose = JsonMapper.ToObject(pose0); controllerlink.Controller0.Rotation = new Quaternion(Convert.ToSingle(jpose[1].ToString()), Convert.ToSingle(jpose[2].ToString()), Convert.ToSingle(jpose[3].ToString()), Convert.ToSingle(jpose[0].ToString())); //手柄0键值数据 var key0 = controllerlink.GetHBControllerKeyData(); var jkey = JsonMapper.ToObject(key0); controllerlink.Controller0.TouchPadPosition = new Vector2(Convert.ToInt16(jkey[0].ToString()), Convert.ToInt16(jkey[1].ToString())); //滑动手势判断 SetSwipeData(controllerlink.Controller0); //touchpad点击 SetTouchPadClick(controllerlink.Controller0); //HomeKey TransformData(controllerlink.Controller0.HomeKey, Convert.ToInt16(jkey[2].ToString())); //AppKey TransformData(controllerlink.Controller0.AppKey, Convert.ToInt16(jkey[3].ToString())); //TouchClickKey TransformData(controllerlink.Controller0.TouchKey, Convert.ToInt16(jkey[4].ToString())); //VolumeuUpKey TransformData(controllerlink.Controller0.VolumeUpKey, Convert.ToInt16(jkey[5].ToString())); //VolumeDownKey TransformData(controllerlink.Controller0.VolumeDownKey, Convert.ToInt16(jkey[6].ToString())); //Battery controllerlink.Controller0.Battery = Convert.ToInt16(jkey[7].ToString()); } //系统按键相关 SetSystemKey(); #endif #region IOSData #if IOS_DEVICE Controller.PVR_GetLark2SensorMessage(ref lark2x, ref lark2y, ref lark2z, ref lark2w); Controller.ControllerQua = new Quaternion(lark2x, lark2y, lark2z, lark2w); Controller.PVR_GetLark2KeyValueMessage(ref lark2touchx, ref lark2touchy, ref lark2home, ref lark2app, ref lark2click, ref lark2volup, ref lark2voldown, ref lark2power); if (lark2touchx > 0 || lark2touchy > 0) { if (lark2touchx == 0) { TouchPadPosition.x = 1; } if (lark2touchy == 0) { TouchPadPosition.y = 1; } TouchPadPosition.x = lark2touchx; TouchPadPosition.y = lark2touchy; } else { touchNum++; if (touchNum >= 1) { TouchPadPosition.x = 0; TouchPadPosition.y = 0; touchNum = 0; } } Controller.BatteryLevel = lark2power; #region base api //键值状态 //Home Key if (lark2home == 1) { if (!HomeKey.state) { HomeKey.pressedDown = true; longPressclock = false; } else { HomeKey.pressedDown = false; } HomeKey.state = true; } else { if (HomeKey.state) { HomeKey.pressedUp = true; } else { HomeKey.pressedUp = false; } HomeKey.state = false; HomeKey.pressedDown = false; } //APP Key if (lark2app == 1) { if (!APPKey.state) { APPKey.pressedDown = true; longPressclock = false; } else { APPKey.pressedDown = false; } APPKey.state = true; } else { if (APPKey.state) { APPKey.pressedUp = true; } else { APPKey.pressedUp = false; } APPKey.state = false; APPKey.pressedDown = false; } //Touchpad Key if (lark2click == 1) { if (!TouchPadKey.state) { TouchPadKey.pressedDown = true; longPressclock = false; } else { TouchPadKey.pressedDown = false; } TouchPadKey.state = true; } else { if (TouchPadKey.state) { TouchPadKey.pressedUp = true; } else { TouchPadKey.pressedUp = false; } TouchPadKey.state = false; TouchPadKey.pressedDown = false; } //VolumeUP Key if (lark2volup == 1) { if (!VolumeUpKey.state) { VolumeUpKey.pressedDown = true; longPressclock = false; } else { VolumeUpKey.pressedDown = false; } VolumeUpKey.state = true; } else { if (VolumeUpKey.state) { VolumeUpKey.pressedUp = true; } else { VolumeUpKey.pressedUp = false; } VolumeUpKey.state = false; VolumeUpKey.pressedDown = false; } //VolumeDown Key if (lark2voldown == 1) { if (!VolumeDownKey.state) { VolumeDownKey.pressedDown = true; longPressclock = false; } else { VolumeDownKey.pressedDown = false; } VolumeDownKey.state = true; } else { if (VolumeDownKey.state) { VolumeDownKey.pressedUp = true; } else { VolumeDownKey.pressedUp = false; } VolumeDownKey.state = false; VolumeDownKey.pressedDown = false; } #endregion #region extended api //打开扩展API后,提供长按和滑动功能 if (ExtendedAPI) { //slip if (TouchPadPosition.x > 0 || TouchPadPosition.y > 0) { if (!touchClock) { touchXBegin = TouchPadPosition.x; touchYBegin = TouchPadPosition.y; touchClock = true; } touchXEnd = TouchPadPosition.x; touchYEnd = TouchPadPosition.y; } else { if (touchXEnd > touchXBegin) { if (touchYEnd > touchYBegin) { if (touchXEnd - touchXBegin > slipNum && ((touchXEnd - touchXBegin) > (touchYEnd - touchYBegin))) { //slide up TouchPadKey.slideup = true; } if (touchYEnd - touchYBegin > slipNum && ((touchYEnd - touchYBegin) > (touchXEnd - touchXBegin))) { //slide right TouchPadKey.slideright = true; } } else if (touchYEnd < touchYBegin) { if (touchXEnd - touchXBegin > slipNum && ((touchXEnd - touchXBegin) > (touchYBegin - touchYEnd))) { //slide up TouchPadKey.slideup = true; } if (touchYBegin - touchYEnd > slipNum && ((touchYBegin - touchYEnd) > (touchXEnd - touchXBegin))) { //slide left TouchPadKey.slideleft = true; } } } else if (touchXEnd < touchXBegin) { if (touchYEnd > touchYBegin) { if (touchXBegin - touchXEnd > slipNum && ((touchXBegin - touchXEnd) > (touchYEnd - touchYBegin))) { //slide down TouchPadKey.slidedown = true; } if (touchYEnd - touchYBegin > slipNum && ((touchYEnd - touchYBegin) > (touchXBegin - touchXEnd))) { //slide right TouchPadKey.slideright = true; } } else if (touchYEnd < touchYBegin) { if (touchXBegin - touchXEnd > slipNum && ((touchXBegin - touchXEnd) > (touchYBegin - touchYEnd))) { //slide down TouchPadKey.slidedown = true; } if (touchYBegin - touchYEnd > slipNum && ((touchYBegin - touchYEnd) > (touchXBegin - touchXEnd))) { //slide left TouchPadKey.slideleft = true; } } } else { TouchPadKey.slideright = false; TouchPadKey.slideleft = false; TouchPadKey.slidedown = false; TouchPadKey.slideup = false; } touchXBegin = 0; touchXEnd = 0; touchYBegin = 0; touchYEnd = 0; touchClock = false; } //longpress if (HomeKey.state) { HomeKey.timecount += Time.deltaTime; if (HomeKey.timecount >= longPressTime && !HomeKey.longPressedClock) { HomeKey.longPressed = true; HomeKey.longPressedClock = true; longPressclock = true; } else { HomeKey.longPressed = false; } } else { HomeKey.longPressedClock = false; HomeKey.timecount = 0; HomeKey.longPressed = false; } if (APPKey.state) { APPKey.timecount += Time.deltaTime; if (APPKey.timecount >= longPressTime && !APPKey.longPressedClock) { APPKey.longPressed = true; APPKey.longPressedClock = true; longPressclock = true; } else { APPKey.longPressed = false; } } else { APPKey.longPressedClock = false; APPKey.timecount = 0; APPKey.longPressed = false; } if (TouchPadKey.state) { TouchPadKey.timecount += Time.deltaTime; if (TouchPadKey.timecount >= longPressTime && !TouchPadKey.longPressedClock) { TouchPadKey.longPressed = true; TouchPadKey.longPressedClock = true; longPressclock = true; } else { TouchPadKey.longPressed = false; } } else { TouchPadKey.longPressedClock = false; TouchPadKey.timecount = 0; TouchPadKey.longPressed = false; } if (VolumeUpKey.state) { VolumeUpKey.timecount += Time.deltaTime; if (VolumeUpKey.timecount >= longPressTime && !VolumeUpKey.longPressedClock) { VolumeUpKey.longPressed = true; VolumeUpKey.longPressedClock = true; longPressclock = true; } else { VolumeUpKey.longPressed = false; } } else { VolumeUpKey.longPressedClock = false; VolumeUpKey.timecount = 0; VolumeUpKey.longPressed = false; } if (VolumeDownKey.state) { VolumeDownKey.timecount += Time.deltaTime; if (VolumeDownKey.timecount >= longPressTime && !VolumeDownKey.longPressedClock) { VolumeDownKey.longPressed = true; VolumeDownKey.longPressedClock = true; longPressclock = true; } else { VolumeDownKey.longPressed = false; } } else { VolumeDownKey.longPressedClock = false; VolumeDownKey.timecount = 0; VolumeDownKey.longPressed = false; } } if (Controller.UPvr_GetKeyLongPressed(0, Pvr_KeyCode.HOME)) { Pvr_UnitySDKManager.pvr_UnitySDKSensor.ResetUnitySDKSensor(); ResetController(0); } #endregion #endif #endregion }