Ejemplo n.º 1
0
 /// <summary>
 /// Main initialization function to read TButt settings from JSON.
 /// </summary>
 public static void Initialize()
 {
     if (!_loadedSettings)
     {
         LoadSettings(TBCore.GetActivePlatform());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This is an optional code path we might enable at some point to use the native arm model on Gear VR, rather than the custom one.
        /// </summary>
        /// <param name="needed"></param>
        void UpdateHandedness(bool needed)
        {
            if (!needed || (_node != XRNode.GameController))
            {
                return;
            }

            switch (TBInput.Get3DOFHandedness())
            {
            case TBInput.Mobile3DOFHandedness.Left:
                if (TBCore.GetActivePlatform() == VRPlatform.OculusPC)
                {
                    _controller = OVRInput.Controller.LTouch;
                }
                else
                {
                    _controller = OVRInput.Controller.LTrackedRemote;
                }
                break;

            case TBInput.Mobile3DOFHandedness.Right:
                if (TBCore.GetActivePlatform() == VRPlatform.OculusPC)
                {
                    _controller = OVRInput.Controller.RTouch;
                }
                else
                {
                    _controller = OVRInput.Controller.RTrackedRemote;
                }
                break;
            }
        }
Ejemplo n.º 3
0
        public virtual void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            instance       = this;
            _initialized   = true;
            _startingScale = transform.localScale.x;
            TBLogging.LogMessage("Assigned new TBCameraRig instance...");
            ReadInitialCameraSettings();
            if (TBCore.GetActivePlatform() != VRPlatform.None)
            {
                _trackingVolume = new GameObject().transform;
                _trackingVolume.gameObject.name = "Tracking Volume";
                _trackingVolume.MakeZeroedChildOf(transform);
            }
            SetupCameraForPlatform(TBCore.GetActivePlatform());

            if (_useBlackoutSphere)
            {
                _blackoutSphere = (Instantiate(Resources.Load("BlackoutSphere")) as GameObject).transform;
                _blackoutSphere.gameObject.SetActive(false);
                _blackoutSphere.SetParent(_centerEyeTransform);
                _blackoutSphere.localScale    = Vector3.one * 2;
                _blackoutSphere.localPosition = Vector3.zero;
            }
        }
Ejemplo n.º 4
0
        public static void AddTrackedDeviceForNode(UnityEngine.XR.XRNode node)
        {
            if (_nodes == null)
            {
                _nodes = new Dictionary <UnityEngine.XR.XRNode, Transform>();
            }

            GameObject newNode = new GameObject();

            _nodes.Add(node, newNode.transform);

            // Handle 3DOF nodes separately, since it relies on the arm model. Skip and assume gamepad if PSVR.
            if (node == UnityEngine.XR.XRNode.GameController)
            {
                switch (TBCore.GetActivePlatform())
                {
                case VRPlatform.PlayStationVR:
                    break;

                default:
                    newNode.AddComponent <TBTrackingNode3DOF>().TrackNode(node);
                    return;
                }
            }

            switch (TBCore.GetActivePlatform())
            {
            case VRPlatform.OculusMobile:
            case VRPlatform.OculusPC:
                newNode.AddComponent <TBTrackingNodeOculus>().TrackNode(node);
                break;

            case VRPlatform.SteamVR:
            case VRPlatform.WindowsMR:
                newNode.AddComponent <TBTrackingNodeBase>().TrackNode(node);
                break;

            case VRPlatform.Daydream:
                newNode.AddComponent <TBTrackingNodeGoogle>().TrackNode(node);
                break;

                #if TB_HAS_UNITY_PS4
            case VRPlatform.PlayStationVR:
                newNode.AddComponent <TBTrackingNodePSVR>().TrackNode(node);
                break;
                #endif
            default:
                Debug.LogError("TButt doesn't support tracked device nodes on this platform yet!");
                break;
            }
        }
Ejemplo n.º 5
0
        public virtual void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            TBCore.Events.OnVRModeEnabled += EnableVRCamera;

            instance       = this;
            _initialized   = true;
            _startingScale = transform.localScale.x;
            TBLogging.LogMessage("Assigned new TBCameraRig instance...");

            ReadInitialCameraSettings();

            _trackingVolume = new GameObject().transform;
            _trackingVolume.gameObject.name = "Tracking Volume";
            _trackingVolume.MakeZeroedChildOf(transform);

            _centerEyeTransform = new GameObject().transform;
            _centerEyeTransform.gameObject.name = "Standard VR Camera";
            _centerEyeTransform.MakeZeroedChildOf(_trackingVolume);

            if (TBCore.UsingVRMode() && (TBCore.GetActivePlatform() != VRPlatform.None))
            {
                SetupVRCamera();
                SetMainCamera(_primaryCamera, true);
            }
            else
            {
                Setup2DCamera();
                SetMainCamera(_2DCamera, true);
            }

            DestroyTempCamera();

            _audioListenerTransform = new GameObject("AudioListener").transform;
            _audioListener          = _audioListenerTransform.gameObject.AddComponent <AudioListener>();
            _audioListenerTransform.gameObject.AddComponent <TBAudioListener>();

            if (TBTracking.OnNodeConnected != null)
            {
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.CenterEye, _centerEyeTransform);
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.Head, _centerEyeTransform);
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.TrackingReference, _trackingVolume);
            }
        }
Ejemplo n.º 6
0
        protected virtual void SetupVRCamera()
        {
            if (_baseCamera == null)
            {
                SetupNativeCamera(TBCore.GetActivePlatform());

                if (_useBlackoutSphere)
                {
                    _blackoutSphere = (Instantiate(Resources.Load("BlackoutSphere")) as GameObject).transform;
                    _blackoutSphere.gameObject.SetActive(false);
                    _blackoutSphere.SetParent(_centerEyeTransform);
                    _blackoutSphere.localScale    = Vector3.one * 2;
                    _blackoutSphere.localPosition = Vector3.zero;
                }
            }
        }
Ejemplo n.º 7
0
            public static void ResetTracking()
            {
                switch (TBCore.GetActivePlatform())
                {
                case VRPlatform.None:
                    TBLogging.LogWarning("Cannot handle recenter event when no HMD is loaded.");
                    break;

                default:
                    UnityEngine.XR.InputTracking.Recenter();
                    break;
                }
                TBLogging.LogMessage("Reset tracking at Core level.");
                if (Events.OnTrackingReset != null)
                {
                    Events.OnTrackingReset();
                }
            }
Ejemplo n.º 8
0
            public static void InitializeStartup()
            {
                // Initialize all required TButt components.
                switch (TBCore.GetActivePlatform())
                {
                case VRPlatform.None:
                    // On platforms where we have to first initialize the HMD, wait for that to finish before initializing TButt.
                    TBCore.instance.StartCheckingForHMD();
                    break;

                default:
                    TBLogging.LogMessage("TBCore is starting up...");
                    TBSettings.Initialize();
                    TBInput.Initialize(GetActivePlatform());
                    instance.InitializePerScene();
                    DontDestroyOnLoad(instance.gameObject);
                    TBLogging.LogMessage("TBCore has finished starting up.");
                    _initialized = true;
                    break;
                }
            }
Ejemplo n.º 9
0
        public static void Initialize()
        {
            if (_nodes != null)
            {
                _nodes.Clear();
            }

            // Add tracked controller nodes under the camera rig if we need them.
            if (TBSettings.GetControlSettings().supportsHandControllers)
            {
                switch (TBCore.GetActivePlatform())
                {
                case VRPlatform.OculusPC:
                case VRPlatform.SteamVR:
                case VRPlatform.PlayStationVR:
                case VRPlatform.WindowsMR:
                    AddTrackedDeviceForNode(UnityEngine.XR.XRNode.LeftHand);
                    AddTrackedDeviceForNode(UnityEngine.XR.XRNode.RightHand);
                    break;

                case VRPlatform.OculusMobile:
                    if (TBInput.GetControllerModel(TBInput.Controller.RHandController) != VRController.None)
                    {
                        AddTrackedDeviceForNode(UnityEngine.XR.XRNode.LeftHand);
                        AddTrackedDeviceForNode(UnityEngine.XR.XRNode.RightHand);
                    }
                    break;

                case VRPlatform.Daydream:
                    if (TBInput.GetControllerModel(TBInput.Controller.RHandController) != VRController.None)
                    {
                        AddTrackedDeviceForNode(UnityEngine.XR.XRNode.LeftHand);
                        AddTrackedDeviceForNode(UnityEngine.XR.XRNode.RightHand);
                    }
                    break;

                default:
                    break;
                }
            }

            if (TBSettings.GetControlSettings().supports3DOFControllers)
            {
                if (TBInput.GetControllerModel(TBInput.Controller.Mobile3DOFController) != VRController.None)
                {
                    TBCameraRig.instance.GetTrackingVolume().gameObject.AddComponent <TB3DOFArmModel>().Initialize();
                    AddTrackedDeviceForNode(UnityEngine.XR.XRNode.GameController);
                }
            }

            if (TBSettings.GetControlSettings().supportsGamepad)
            {
                switch (TBCore.GetActivePlatform())
                {
                case VRPlatform.PlayStationVR:
                    AddTrackedDeviceForNode(UnityEngine.XR.XRNode.GameController);
                    break;

                default:
                    break;
                }
            }
        }