示例#1
0
    public static bool SetData(string json)
    {
#if UNITY_EDITOR
        if (Instance.offline)
        {
            SeganX.Console.Logger.Enabled = true;
            return(true);
        }
#endif

        var newdata = JsonUtilityEx.FromJson <Data>(json, false);
        if (newdata == null)
        {
            return(false);
        }

        //  set new data
        Instance.data = newdata;
        SaveData(newdata);
        SeganX.Console.Logger.Enabled = DebugMode;

        // select cohort
        Cohort = PlayerPrefsEx.GetInt("GlobalConfig.Cohort", -1);
        if (Cohort < 0)
        {
            Cohort = Random.Range(0, 100) % 2;
            PlayerPrefsEx.SetInt("GlobalConfig.Cohort", Cohort);
        }
        return(true);
    }
示例#2
0
        /// <summary>
        /// Initialize the X-Device SDK library.
        /// </summary>
        public static int Init()
        {
            // Initialization Lock.
            if (s_IsInited)
            {
                return(0);
            }
            s_IsInited = true;
            //
            NativeMethods.XDeviceExit();
            //
            NativeMethods.XDeviceGetContext(true);
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            //
            string pluginPath = UnityEngine.Application.dataPath + "\\Plugins\\"
#if UNITY_EDITOR_WIN
                                + (GetInt(-1, /*FieldID::*/ kField_CtxPlatformVersion, 0) % 2 == 0?"x86":"x86_64");
#elif UNITY_STANDALONE_WIN
            ;
#endif
            string path = System.Environment.GetEnvironmentVariable("PATH");
            if (path.IndexOf(pluginPath) == -1)
            {
                System.Environment.SetEnvironmentVariable("PATH", path + ";" + pluginPath);
            }
#endif
            NativeMethods.XDeviceSetInt(-1, kField_CtxDeviceVersion, PlayerPrefsEx.GetInt("XimmerseDevice.type", 0x4000));
            int ret = NativeMethods.XDeviceInit();
            // Add Unity objects into X-Device plugin.
            AddExternalControllerDevice("VRDevice", VRContext.s_OnHmdUpdate, VRContext.s_OnHmdMessage);
            return(ret);
        }
示例#3
0
    protected virtual void OnVRContextInited(VRContext context)
    {
        //
        if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x4000)
        {
            Destroy(this);
            Ximmerse.Log.w("TrackedHead", "TrackedHead only works in Outside-in!!!");
            return;
        }
        else
        {
            VRDevice vrDevice = context.vrDevice;
            if (vrDevice.outsideInMarkPose.position != Vector3.zero)
            {
                markTransform.localPosition = vrDevice.outsideInMarkPose.position;
            }
        }
        //
        if (eyeContainer == null)
        {
            eyeContainer = new GameObject("Rotate-Pivot").transform;
            eyeContainer.SetParent(transform);
            //
            eyeContainer.localPosition = Vector3.zero;
            eyeContainer.localRotation = Quaternion.identity;
            eyeContainer.localScale    = Vector3.one;
            //
            if (context.vrDevice != null && context.vrDevice.family != "Dummy")
            {
                markTransform.localPosition = markTransform.localPosition + context.vrDevice.neckToEye;
                eyeContainer.localPosition  = context.vrDevice.neckToEye;
#if UNITY_EDITOR
                // Editor features.
                if (m_Gizmos.Length > 0 && m_Gizmos[0] != null)
                {
                    m_Gizmos[0].transform.localPosition = m_Gizmos[0].transform.localPosition + context.vrDevice.neckToEye;
                }
#endif
            }
        }
        //
        for (int i = 0; i < 3; ++i)
        {
            Transform eye = context.GetAnchor(VRNode.LeftEye + i, null);
            if (eye != null)
            {
                eye.SetParent(eyeContainer, false);
            }
        }
        //
        switch (PlayerPrefsEx.GetInt("XimmerseDevice.type", 0))
        {
        // No head tracking.
        case 0x1010:
            source            = ControllerType.None;
            m_ControllerInput = null;
            break;
        }
    }
示例#4
0
        protected static int DrawIntPopup(string label, string key, int value, string[] displayedOptions, int[] optionValues)
        {
            value = PlayerPrefsEx.GetInt(key, value);
            int newValue = EditorGUILayout.IntPopup(label, value, displayedOptions, optionValues);

            if (newValue != value)
            {
                PlayerPrefsEx.SetInt(key, newValue);
            }
            return(newValue);
        }
示例#5
0
    protected virtual void OnVRContextInited(VRContext context)
    {
        if (eyeContainer == null)
        {
            eyeContainer = new GameObject("Rotate-Pivot").transform;
            eyeContainer.SetParent(transform);
            //
            eyeContainer.localPosition = Vector3.zero;
            eyeContainer.localRotation = Quaternion.identity;
            eyeContainer.localScale    = Vector3.one;
            //
            if (context.vrDevice != null && context.vrDevice.family != "Dummy")
            {
                markTransform.localPosition = markTransform.localPosition + context.vrDevice.neckOffset;
                eyeContainer.localPosition  = context.vrDevice.neckOffset;
#if UNITY_EDITOR
                // Editor features.
                if (m_Gizmos.Length > 0 && m_Gizmos[0] != null)
                {
                    m_Gizmos[0].transform.localPosition = m_Gizmos[0].transform.localPosition + context.vrDevice.neckOffset;
                }
#endif
            }
        }
        //
        for (int i = 0; i < 3; ++i)
        {
            Transform eye = context.GetAnchor(VRNode.LeftEye + i, null);
            if (eye != null)
            {
                eye.SetParent(eyeContainer, false);
            }
        }
        //
        switch (PlayerPrefsEx.GetInt("XimmerseDevice.type", 0))
        {
        // No head tracking.
        case 0x1010:
            source            = ControllerType.None;
            m_ControllerInput = null;
            break;
        }
    }
示例#6
0
    protected virtual void Start()
    {
        m_Transform = transform;
        //
        m_TrackerHandle = -1;
        if (showOnTrackingLost)
        {
            XDevicePlugin.Init();
            m_TrackerHandle = XDevicePlugin.GetInputDeviceHandle(trackerName);
            if (m_TrackerHandle < 0)
            {
                showOnTrackingLost = false;
            }
        }
        //
        m_ReadyForModel = (controlPoints.Length == 8);
        // Cache values.
        m_CosFovX  = Mathf.Cos(Mathf.Deg2Rad * fovX * .5f);
        m_CosFovY  = Mathf.Cos(Mathf.Deg2Rad * fovY * .5f);
        m_SqrNearZ = nearZ * nearZ;
        m_SqrFarZ  = farZ * farZ;

        m_SqrOrthographicSize = orthographicSize * .5f;
        m_SqrOrthographicSize = Vector2.Scale(m_SqrOrthographicSize, m_SqrOrthographicSize);
        //
        if (m_Corners != null && m_Corners.Length != 0)
        {
            m_CachedCorners = m_Corners;
        }
        m_Corners = null;
        //
        m_GroundAlpha      = PlayerPrefsEx.GetInt("PlayArea.drawGround", 1);
        m_WallAlpha        = PlayerPrefsEx.GetInt("PlayArea.drawWall", 1);
        autoCreatePlayArea = PlayerPrefsEx.GetBool("PlayArea.enabled", autoCreatePlayArea);
        showCameraModel    = PlayerPrefsEx.GetBool("PlayArea.showCameraModel", showCameraModel);
        if (m_cameraModel != null)
        {
            m_cameraModel.SetActive(showCameraModel);
        }

        warningDistance = PlayerPrefsEx.GetFloat("PlayArea.warningDistance", 0.5f);
        //
        if (autoCreatePlayArea)
        {
            Transform t = null;
            if (m_PlayArea == null)
            {
                //
                m_PlayArea            = new GameObject("_PlayArea", typeof(PlayAreaRenderer)).GetComponent <PlayAreaRenderer>();
                m_PlayArea.handedness = -1;

                m_PlayArea.groundColor     = PlayerPrefsEx.GetColor("PlayArea.groundColor", Color.cyan);
                m_PlayArea.groundMaterial  = new Material(Shader.Find("Sprites/Default"));
                m_PlayArea.borderThickness = PlayerPrefsEx.GetFloat("PlayArea.borderThickness", .15f);

                m_PlayArea.wallColor    = PlayerPrefsEx.GetColor("PlayArea.wallColor", Color.cyan);
                m_PlayArea.wallMaterial = new Material(Shader.Find("Sprites/Default"));
                m_PlayArea.thickness    = PlayerPrefsEx.GetFloat("PlayArea.thickness", 0.0075f);
                m_PlayArea.height       = PlayerPrefsEx.GetFloat("PlayArea.height", 2.5f);
                m_PlayArea.cellSize     = PlayerPrefsEx.GetFloat("PlayArea.cellSize", 0.25f);
                m_PlayArea.emptySize    = PlayerPrefsEx.GetFloat("PlayArea.emptySize", 0.05f);
            }
            t = m_PlayArea.transform;
            t.SetParent(VRContext.GetAnchor(VRNode.TrackingSpace));
            t.localPosition = (VRContext.trackingOrigin == TrackingOrigin.FloorLevel) ? Vector3.zero :
                              new Vector3(0f, -XDevicePlugin.GetFloat(m_TrackerHandle, XDevicePlugin.kField_TrackerHeight, 0f), 0f);
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;
        }
        //
        UpdateModel();
    }
示例#7
0
    protected virtual void Start()
    {
        m_Transform = transform;
        //
        m_TrackerHandle = -1;
        if (showOnTrackingLost)
        {
            XDevicePlugin.Init();
            m_TrackerHandle = XDevicePlugin.GetInputDeviceHandle(trackerName);
            if (m_TrackerHandle < 0)
            {
                showOnTrackingLost = false;
            }
        }
        //
        m_ReadyForModel = (controlPoints.Length == 8);
        // Cache values.

        /*
         * m_CosFovX=Mathf.Cos(Mathf.Deg2Rad*fovX*.5f);
         * m_CosFovY=Mathf.Cos(Mathf.Deg2Rad*fovY*.5f);
         * m_SqrNearZ=nearZ*nearZ;
         * m_SqrFarZ=farZ*farZ;
         *
         * m_SqrOrthographicSize=orthographicSize*.5f;
         * m_SqrOrthographicSize=Vector2.Scale(m_SqrOrthographicSize,m_SqrOrthographicSize);
         */
        //
        if (m_Corners != null && m_Corners.Length != 0)
        {
            m_CachedCorners = m_Corners;
        }
        m_Corners = null;
        //
        m_GroundAlpha      = PlayerPrefsEx.GetInt("PlayArea.drawGround", 1);
        m_WallAlpha        = PlayerPrefsEx.GetInt("PlayArea.drawWall", 1);
        m_PlaneAlpha       = PlayerPrefsEx.GetInt("PlayArea.drawPlane", 1);
        autoCreatePlayArea = PlayerPrefsEx.GetBool("PlayArea.enabled", autoCreatePlayArea);
        showCameraModel    = PlayerPrefsEx.GetBool("PlayArea.showCameraModel", showCameraModel);
        if (m_cameraModel != null)
        {
            m_cameraModel.SetActive(showCameraModel);
        }
        warningDistance = PlayerPrefsEx.GetFloat("PlayArea.warningDistance", 0.5f);
        //
        if (autoCreatePlayArea)
        {
            Transform t = null;
            Transform trackingSpaceAnchor = VRContext.GetAnchor(VRNode.TrackingSpace);

            if (m_PlayArea == null)
            {
                if (trackingSpaceAnchor != null)
                {
                    m_PlayArea = trackingSpaceAnchor.GetComponentInChildren <PlayAreaRenderer>();
                }
                if (m_PlayArea == null)
                {
                    GameObject go = PlayerPrefsEx.GetObject("PlayAreaRenderer") as GameObject;
                    m_PlayArea      = Instantiate(go).GetComponent <PlayAreaRenderer>();
                    m_PlayArea.name = go.name;
                }
            }
            m_PlayArea.handedness = -1;
            //
            t = m_PlayArea.transform;
            t.SetParent(trackingSpaceAnchor);
            t.localPosition = (VRContext.trackingOrigin == TrackingOrigin.FloorLevel) ? Vector3.zero :
                              new Vector3(0f, -XDevicePlugin.GetFloat(m_TrackerHandle, XDevicePlugin.kField_TrackerHeightFloat, 0f), 0f);
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;
        }
        //
        UpdateModel();
    }