예제 #1
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);
        }