示例#1
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;
            }
        }
示例#2
0
        void Awake()
        {
            if (instance != null)
            {
                TBLogging.LogMessage("An instance of TBCore already exists. Deleting this instance...");
                Destroy(gameObject);
                if (OnNewScene != null)
                {
                    OnNewScene();
                }
                InitializePerScene();
                return;
            }
            else
            {
                // First TBCore instance.
                instance = this;
                if (!Internal.IsValidSetup())
                {
                    Debug.LogError("No platforms are enabled in TBCore. At least one platform must be enabled for TButt to work. See the 'Core Settings' menu.");
                    return;
                }

                SetActivePlatform();
                #if TB_PSVR && UNITY_PS4
                TBCore.instance.gameObject.AddComponent <TBPSVRSystemEvents>();
                #endif
                Internal.InitializeStartup();
            }
        }
示例#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;
            }
        }
示例#4
0
 /// <summary>
 /// Main initialization function to read TButt settings from JSON.
 /// </summary>
 public static void Initialize()
 {
     if (!_loadedSettings)
     {
         LoadSettings(TBCore.GetActivePlatform());
     }
 }
示例#5
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;
            }
        }
示例#6
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);
            }
        }
示例#7
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;
                }
            }
        }
示例#8
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();
                }
            }
示例#9
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;
                }
            }
示例#10
0
        /// <summary>
        /// Returns 3DOF controller handedness as reported by the active SDK (Left, Right, or Center).
        /// </summary>
        /// <returns></returns>
        public static Mobile3DOFHandedness Get3DOFHandedness()
        {
            // In the editor, override hardware settings with whatever is set in the TButt Input Settings tool.
            if (TBCore.UsingEditorMode())
            {
                if (TBSettings.GetControlSettings().handedness3DOF == TBSettings.TBHardwareHandedness.Left)
                {
                    return(Mobile3DOFHandedness.Left);
                }
                else
                {
                    return(Mobile3DOFHandedness.Right);
                }
            }

            if (_hasActiveSDK)
            {
                return(_activeSDK.Get3DOFHandedness());
            }
            else
            {
                return(TBInput.Mobile3DOFHandedness.Center);
            }
        }
示例#11
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;
                }
            }
        }