Esempio n. 1
0
    protected virtual void Start()
    {
        //
        if (checkParent)
        {
            Transform p = VRContext.GetAnchor(VRNode.TrackingSpace);
            if (p != null)
            {
                target.SetParent(p, true);
            }
        }
        //
        m_ControllerInput = ControllerInputManager.instance.GetControllerInput(source);
        VRNode node = VRNode.None;

        switch (source)
        {
        case ControllerType.LeftController:
            node = VRNode.LeftHand;
            break;

        case ControllerType.RightController:
            node = VRNode.RightHand;
            break;
        }
        if (node != VRNode.None)
        {
            VRContext.SetAnchor(node, target);
        }
        //
        if (m_ControllerInput != null && canRecenter)
        {
            // Like SteamVR,hmd and controllers don't need to reset yaw angle.
            canRecenter = !m_ControllerInput.isAbsRotation;
        }
        //
        if (canRecenter)
        {
            // Invoke Recenter() on VRContext recenter event.
            VRContext ctx = VRContext.main;
            if (ctx != null)
            {
                ctx.onRecenter += Recenter;
            }
        }
        //
        return;

        // TODO:
        enabled = false;
        UpdatePoses.instance.onUpdatePoses += Update;
    }
 public override bool CreateAnchor()
 {
     if (anchor != null)
     {
         return(false);
     }
     //
     anchor = (anchorPrefab == null || !m_IsRequestVR?      // in 2D mode.
               new GameObject():
               Object.Instantiate(anchorPrefab)
               ).transform;
     anchor.name = "TrackerAnchor(Outside-In)";
     anchor.SetParent(trackingSpace);
     //
     UpdateAnchorFromPlugin();
     m_PlayAreaHelper = anchor.GetComponentInChildren <PlayAreaHelper>();
     //
     m_UseAnchorProjection = true;
     VRContext.SetAnchor(VRNode.TrackerDefault, anchor);
     //
     //
     return(true);
 }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        public override bool CreateAnchor()
        {
            if (anchor != null)
            {
                return(false);
            }
            //
            anchor = (anchorPrefab == null || !m_IsRequestVR?      // in 2D mode.
                      new GameObject():
                      Object.Instantiate(anchorPrefab)
                      ).transform;
            anchor.name = "TrackerAnchor(Outside-In)";
            anchor.SetParent(trackingSpace);
            //
            UpdateAnchorFromPlugin();
            m_PlayAreaHelper = anchor.GetComponentInChildren <PlayAreaHelper>();
            //
            m_UseAnchorProjection = true;
            VRContext.SetAnchor(VRNode.TrackerDefault, anchor);
            //
            if (m_IsRequestVR && useAutoRecenter)
            {
                // Recenter hmd firstly,for aligning rotation pivot of vr device and position pivot.
                // In outside-in case,we never use yaw offset(Recenter() will fix the value) in hmd sdk.
                XDevicePlugin.SetBool(m_HmdInput.handle, XDevicePlugin.kField_IsAbsRotationBool, false);
                VRContext.Recenter(false);
                XDevicePlugin.SetBool(m_HmdInput.handle, XDevicePlugin.kField_IsAbsRotationBool, true);
                //
                if (PlayerPrefsEx.GetBool("VRDevice.forceFadeOnBadTracking"))
                {
                    VRContext.FadeOut(1.0f, -1.0f);
                }
            }

            if (m_CenterEye == null)
            {
                m_CenterEye = VRContext.GetAnchor(VRNode.CenterEye);
                m_VRDevice  = VRContext.currentDevice;
            }

            if (uiAutoRecenter != null)
            {
                goUIAutoRecenter = Instantiate(uiAutoRecenter) as GameObject;
                Transform originTranformAuto = uiAutoRecenter.transform;
                goUIAutoRecenter.transform.SetParent(VRContext.uiRootVR);
                goUIAutoRecenter.transform.localPosition = originTranformAuto.localPosition;
                goUIAutoRecenter.transform.localRotation = originTranformAuto.localRotation;
                goUIAutoRecenter.transform.localScale    = originTranformAuto.localScale;
                _needAutoRecenter = true;
            }
            // TODO : Align Notice
            if (alignNeedTime > 0.0f)
            {
                m_UiAlign = new GameObject("Wait for Aligning", typeof(Image), typeof(UIFade)).GetComponent <Image>();
                m_UiAlign.gameObject.SetActive(false);
                //
                m_UiAlign.material   = Resources.Load <Material>("UI/MatNotice");
                m_UiAlign.sprite     = uiAlignSprite;
                m_UiAlign.type       = Image.Type.Filled;
                m_UiAlign.fillMethod = Image.FillMethod.Radial360;
                m_UiAlign.fillOrigin = 2;
                m_UiAlign.fillAmount = 0.0f;
                //
                RectTransform t = m_UiAlign.GetComponent <RectTransform>();
                t.SetParent(VRContext.uiRootVR);
                t.localPosition = Vector3.forward * 0.8f;
                t.localRotation = Quaternion.identity;
                t.localScale    = Vector3.one * 0.0016f;
                t.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 80f);
                t.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 80f);
                //
                m_UiAlignFade             = m_UiAlign.GetComponent <UIFade>();
                m_UiAlignFade.durationOut = 0.25f;
                m_UiAlignFade.onBecameInvisible.AddListener(() => { m_UiAlign.gameObject.SetActive(false); });
            }
            // TODO : LookAt Notice
            if (true)
            {
                m_UiLookAtFade = new GameObject("Look At XHawk", typeof(UIFade), typeof(Image)).GetComponent <UIFade>();
                m_UiLookAtFade.GetComponent <Image>().sprite   = uiXHawkSprite;
                m_UiLookAtFade.GetComponent <Image>().material = Resources.Load <Material>("UI/MatNotice");
                m_UiLookAtFade.durationIn  = .25f;
                m_UiLookAtFade.durationOut = .16f;
                m_UiLookAtFade.onBecameInvisible.AddListener(() => { m_UiLookAtFade.gameObject.SetActive(false); });
                m_UiLookAtFade.gameObject.SetActive(false);

                RectTransform t = m_UiLookAtFade.GetComponent <RectTransform>();
                t.SetParent(VRContext.uiRootVR);
                t.localPosition = Vector3.forward * 0.85f;
                t.localRotation = Quaternion.identity;
                t.localScale    = Vector3.one * 0.0016f;
                t.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 80f);
                t.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 80f);
                //
                m_UiLookAt = new GameObject("Dummy-LookAt").transform;
                m_UiLookAt.SetParent(t);
                m_UiLookAt.localPosition = Vector3.zero;
                m_UiLookAt.localRotation = Quaternion.identity;
                m_UiLookAt.localScale    = Vector3.one;
                //
                t = new GameObject("LookAt", typeof(Image)).GetComponent <RectTransform>();
                t.GetComponent <Image>().sprite   = uiLookAtSprite;
                t.GetComponent <Image>().material = Resources.Load <Material>("UI/MatNotice");
                t.SetParent(m_UiLookAt);
                t.localPosition = Vector3.forward * 80.0f;
                t.localRotation = Quaternion.Euler(new Vector3(90.0f, 0.0f, -90.0f));
                t.localScale    = Vector3.one;
                t.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 40f);
                t.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 40f);
            }
            return(true);
        }
Esempio n. 5
0
    protected virtual void Start()
    {
        //
        if (checkParent)
        {
            Transform p = VRContext.GetAnchor(VRNode.TrackingSpace);
            if (p != null)
            {
                target.SetParent(p, true);
            }
        }
        //
        if (source == ControllerType.None && string.IsNullOrEmpty(sourceName))
        {
            if (name.ToLower().IndexOf("left") != -1)
            {
                source = ControllerType.LeftController;
            }
            else if (name.ToLower().IndexOf("right") != -1)
            {
                source = ControllerType.RightController;
            }
        }
        if (source != ControllerType.None)
        {
            m_ControllerInput = ControllerInputManager.instance.GetControllerInput(source);
        }
        else if (!string.IsNullOrEmpty(sourceName))
        {
            m_ControllerInput = ControllerInputManager.instance.GetControllerInput(sourceName);
        }
        //
        VRNode node = VRNode.None;

        switch (source)
        {
        case ControllerType.LeftController:
            node = VRNode.LeftHand;
            break;

        case ControllerType.RightController:
            node = VRNode.RightHand;
            break;
        }
        if (node != VRNode.None)
        {
            VRContext.SetAnchor(node, target);
        }
        //
        if (m_ControllerInput != null && canRecenter)
        {
            // Like SteamVR,hmd and controllers don't need to reset yaw angle.
            //canRecenter=!m_ControllerInput.isAbsRotation;
        }
        //
        if (canRecenter)
        {
            // Invoke Recenter() on VRContext recenter event.
            VRContext ctx = VRContext.main;
            if (ctx != null)
            {
                ctx.onRecenter += Recenter;
            }
        }
        //
        return;
    }