public override bool InitInternal() { if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0x4000) & 0xF000) != 0x4000) { return(false); } // if (true) { Vector3 position = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].position"); Vector3 rotation = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].rotation"); XDevicePlugin.SetTrackerPose(m_Handle, position.y, position.z, rotation.x); // XDevicePlugin.GetTrackerPose(m_Handle, out position.y, out position.z, out rotation.x); // int i = m_Controllers.Length; while (i-- > 0) { XDevicePlugin.SetBool(XDevicePlugin.GetInputDeviceHandle(m_Controllers[i].key), XDevicePlugin.kField_IsAbsRotationBool, true); } // //PlayerPrefsEx.SetBool("VRDevice.forceFadeOnBadTracking",true); XDevicePlugin.NativeMethods.XDeviceSetDecoderFeature(XDevicePlugin.FEATURE_BLOB_AUTO); } return(base.InitInternal()); }
/// <summary> /// We will lose the VR context,when reloading level. /// Calling this function per frame can ensure that the anchor is alive. /// </summary> public virtual bool EnsureAnchor() { // <!-- TODO: VR Legacy Mode. --> // If the X-Hawk isn't connected,the game will run as legacy VR mode(Gets input events with GearVR touchpad). if (XDevicePlugin.GetInt(m_Handle, XDevicePlugin.kField_ConnectionState, 0) != (int)DeviceConnectionState.Connected) { XDevicePlugin.SetInt(m_HmdHandle, XDevicePlugin.kField_ConnectionState, (int)DeviceConnectionState.Disconnected); return(false); } // if (trackingSpace == null) { trackingSpace = VRContext.GetAnchor(VRNode.TrackingSpace); } // if (anchor == null) { Transform centerEyeAnchor = VRContext.GetAnchor(VRNode.CenterEye); if (m_IsRequestVR && centerEyeAnchor == null) { return(false); } else { // switch ((XDevicePlugin.GetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0x4000) & 0xF000)) { case 0x3000: anchor = new GameObject("XHawkAnchor").transform; anchor.SetParent(centerEyeAnchor); anchor.localPosition = anchorPosition; anchor.localRotation = Quaternion.Euler(anchorRotation); // m_UseAnchorProjection = !PlayerPrefsEx.GetBool("XimmerseTracker[Inside-out].fixShake", false); //!modifyHierarchy; VRContext.SetAnchor(VRNode.TrackerDefault, anchor); // TODO : /*if(modifyHierarchy) { * for(int i=0;i<2;++i) { * Transform hand=VRContext.GetAnchor(VRNode.LeftHand+i); * if(hand!=null) { * hand.SetParent(anchor,true); * } * } * }*/ if (PlayerPrefsEx.GetBool("XimmerseTracker[Inside-out].fixShake", false)) { m_AnchorMatrixQueue = new List <Matrix4x4>(8); m_M2pFrameIndex = Mathf.CeilToInt(PlayerPrefsEx.GetFloat("XimmerseTracker[Inside-out].m2pLatency", 0.0f) * VRContext.refreshRate); Log.i("XHawkInput", "m_M2pFrameIndex=" + m_M2pFrameIndex); } else { m_AnchorMatrixQueue = null; } break; case 0x4000: // float trackerHeight, trackerDepth, trackerPitch; XDevicePlugin.GetTrackerPose(m_Handle, out trackerHeight, out trackerDepth, out trackerPitch); // anchor = (anchorPrefab == null || !m_IsRequestVR? // in 2D mode. new GameObject(): Object.Instantiate(anchorPrefab) ).transform; anchor.name = "TrackerAnchor(X-Hawk DK4)"; anchor.SetParent(trackingSpace); // #if XDEVICE_RELEASE if (true) { UpdateAnchorFromPlugin(); } else #endif { anchor.localPosition = new Vector3(0f, VRContext.trackingOrigin == TrackingOrigin.FloorLevel?trackerHeight:0.0f, trackerDepth); anchor.localRotation = Quaternion.Euler(-trackerPitch, 180f, 0f); } // m_TrackerFrustum = anchor.GetComponentInChildren <TrackerFrustum>(); // //#if XDEVICE_RELEASE // m_UseAnchorProjection=false; //#else m_UseAnchorProjection = true; //#endif VRContext.SetAnchor(VRNode.TrackerDefault, anchor); m_AnchorMatrixQueue = null; break; default: anchor = new GameObject("Dummy Anchor").transform; anchor.SetParent(trackingSpace, false); break; } // Override anchor info. if (m_AnchorInfoCached) { anchor.localPosition = m_AnchorPosition; anchor.localRotation = m_AnchorRotation; } // if (m_IsRequestVR) { VRContext.main.onRecenter -= RecenterOnVRContextRecenter; VRContext.main.onRecenter += RecenterOnVRContextRecenter; } } } return(true); }