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; } }
/// <summary> /// Sets the timestep overrides as specified in TBCore's settings. /// </summary> private static void SetTimestep() { switch (_settingsBase.GetDisplaySettings().targetTimestep) { case TBTimestep.Half: Time.fixedDeltaTime = (1f / (GetRefreshRate()) * 2f); break; case TBTimestep.Locked: Time.fixedDeltaTime = 1f / GetRefreshRate(); break; case TBTimestep.KeepUnitySetting: break; } switch (_settingsBase.GetDisplaySettings().maxTimestep) { case TBTimestep.Half: Time.maximumDeltaTime = (1f / (GetRefreshRate()) * 2f); break; case TBTimestep.Locked: Time.maximumDeltaTime = 1f / GetRefreshRate(); break; case TBTimestep.KeepUnitySetting: break; } TBLogging.LogMessage("Fixed Timestep: " + Time.fixedDeltaTime + ", Max Timestep: " + Time.maximumDeltaTime); }
/// <summary> /// Loads controller data into memory for a given SDK. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="controllers"></param> /// <param name="controllerName"></param> /// <param name="defaultButtonDefs"></param> /// <param name="fileName"></param> public static string LoadController <T>(ref Dictionary <string, ButtonMapGroup <TBInput.ButtonDef <T> > > controllers, string controllerName, List <TBInput.ButtonDef <T> > defaultButtonDefs, string fileName) { ButtonMapGroup <TBInput.ButtonDef <T> > newController; if (controllers.TryGetValue(controllerName, out newController)) { return(controllerName); } else { newController = new ButtonMapGroup <TBInput.ButtonDef <T> >(); newController.fileName = fileName; newController.controllerName = controllerName; newController.defs = defaultButtonDefs; // If a custom mapping exits, try to use it. if (File.Exists(settingsPath + TBSettings.settingsFolder + newController.fileName + ".json")) { newController.defs = TBInput.LoadButtonDefs(defaultButtonDefs, fileName); TBLogging.LogMessage("Found and loaded button maps for " + controllerName + ".", null, messageEnd); } else { // If no custom mapping, we use the default one. A custom one will be saved if you make any changes. TBLogging.LogMessage("Could not find custom button maps for " + controllerName + " in " + settingsPath + TBSettings.settingsFolder + newController.fileName + ".json. Created new maps from default.", null, messageEnd); } controllers.Add(controllerName, newController); return(controllerName); } }
/// <summary> /// Loads a button set from JSON by its filename. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="buttons"></param> /// <param name="fileName"></param> /// <returns></returns> public static List <ButtonDef <T> > LoadButtonDefs <T>(List <ButtonDef <T> > buttons, string fileName) { if (Application.isPlaying) { TBLogging.LogMessage("Loading button maps from " + TBSettings.settingsFolder + fileName + "..."); } SerializedButtonDef[] serializedButtonDefs = TBDataManager.FromJsonWrapper <SerializedButtonDef>(TBDataManager.DeserializeFromFile <TBDataManager.Wrapper <TBInput.SerializedButtonDef> >(TBSettings.settingsFolder + fileName, TBDataManager.PathType.ResourcesFolder)); if (serializedButtonDefs == null) { if (Application.isPlaying) { TBLogging.LogWarning("Serialized button maps for " + fileName + " were invalid (empty file). Using defaults."); } return(buttons); } if (serializedButtonDefs.Length != buttons.Count) { TBLogging.LogError("Serialized button maps for " + fileName + " exist, but are invalid! (Input count mismatch). You need to clear the JSON file or manually fix it."); } for (int i = 0; i < buttons.Count; i++) { buttons[i].virtualButtons = serializedButtonDefs[i].virtualButtons; } if (Application.isPlaying) { TBLogging.LogMessage("Done! Found maps for " + buttons.Count + " buttons in " + TBSettings.settingsFolder + fileName + "."); } return(buttons); }
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(); } }
protected void SetReady(bool on) { _ready = on; if (on) { TBLogging.LogMessage("Service is ready! Local instances populated."); } }
public virtual void Initialize() { SetTrackingOrigin(TBSettings.GetCameraSettings().trackingOrigin); TBCameraRig.instance.sortMode = TBSettings.GetDisplaySettings().opaqueSortMode; _camera.depthTextureMode = TBSettings.GetDisplaySettings().depthTextureMode; TBLogging.LogMessage("Opaque Sort Mode set to " + _camera.opaqueSortMode); _camera.allowHDR = false; }
private static void SetActivePlatform() { if (!UnityEngine.XR.XRSettings.enabled) { TBLogging.LogMessage("VR is disabled in PlayerSettings (or Unity's XRSettings). Setting VRPlatform to None."); _activePlatform = VRPlatform.None; return; } switch (UnityEngine.XR.XRSettings.loadedDeviceName) { case TBSettings.VRDeviceNames.Oculus: if (Application.isMobilePlatform) { _activePlatform = VRPlatform.OculusMobile; } else { _activePlatform = VRPlatform.OculusPC; } break; case TBSettings.VRDeviceNames.SteamVR: #if !TB_STEAM_VR _activePlatform = VRPlatform.OculusPC; // Allows Oculus Utilities to be used as a fallback if Steam VR plugin is not present. #else _activePlatform = VRPlatform.SteamVR; #endif break; case TBSettings.VRDeviceNames.Daydream: _activePlatform = VRPlatform.Daydream; break; case TBSettings.VRDeviceNames.PlayStationVR: _activePlatform = VRPlatform.PlayStationVR; break; case TBSettings.VRDeviceNames.WindowsMR: _activePlatform = VRPlatform.WindowsMR; break; default: if (string.IsNullOrEmpty(UnityEngine.XR.XRSettings.loadedDeviceName)) { TBLogging.LogMessage("No VR device is currently loaded in Unity's XRSettings, even though VR was enabled. That may be a sign of an error."); } else { Debug.LogError("Detected " + UnityEngine.XR.XRSettings.loadedDeviceName); Debug.LogError("The current HMD / SDK pairing doesn't match any known TButt preset! TCore initialization failed."); } _activePlatform = VRPlatform.None; UnityEngine.XR.XRSettings.enabled = false; return; } TBLogging.LogMessage("TBCore's VRPlatform is now " + _activePlatform + ". Configured for " + UnityEngine.XR.XRDevice.model + " running through " + UnityEngine.XR.XRSettings.loadedDeviceName + " SDK"); }
static void SaveSettings() { // Save global settings. if (!savedControlSettings.Equals(controlSettings)) { TBEditorHelper.CheckoutAndSaveJSONFile(settingsPath + TBSettings.settingsFolder + TBSettings.controlSettingsFileName + ".json", controlSettings, TBDataManager.PathType.ProjectFolder); //TBDataManager.SerializeObjectToFile(controlSettings, settingsPath + TBSettings.settingsFolder + TBSettings.controlSettingsFileName + ".json", TBDataManager.PathType.ProjectFolder); } SaveAllButtonMaps(); TBLogging.LogMessage("All input settings saved.", null, messageEnd); }
/// <summary> /// Override function to force TBCore to initialize for a specific platform. /// Only necessary for devices that can start without a headset active. /// </summary> /// <param name="platform"></param> public static void Initialize(VRPlatform platform) { if (!_loadedSettings) { LoadSettings(platform); } else { TBLogging.LogMessage("TBSettings.Initialize() was called, but settings were already initialized."); } }
public static void SetActiveControlType(TBInput.ControlType controlType) { if (_activeControlType == controlType) { return; } _activeControlType = controlType; Events.Internal.UpdateControlType(_activeControlType); TBLogging.LogMessage("Control type changed to " + controlType.ToString()); }
private void InitializeCameraAndTracking(TBCameraRig rig) { if (rig == null) { TBLogging.LogMessage("TBCameraRig wasn't found at startup. Waiting for TBCameraRig instance."); StartCoroutine(WaitForCameraRig()); } else { rig.Initialize(); TBTracking.Initialize(); } }
public virtual void SetRenderscale(float newScale) { TBLogging.LogMessage("Setting renderscale (eyeTextureResolutionScale) to " + newScale + "..."); if (UnityEngine.XR.XRSettings.eyeTextureResolutionScale == newScale) { TBLogging.LogMessage("Unity renderscale (eyeTextureResolutionScale) was already " + UnityEngine.XR.XRSettings.eyeTextureResolutionScale); return; } else { UnityEngine.XR.XRSettings.eyeTextureResolutionScale = newScale; TBLogging.LogMessage("Unity renderscale (eyeTextureResolutionScale) is now " + UnityEngine.XR.XRSettings.eyeTextureResolutionScale); } }
protected virtual void PrintStartupResults() { TBLogging.LogMessage("TButt settings initialized. Diagnostics Report (click to view) \n" + "------------------------------------------------------------------------------------- \n" + "SystemInfo DeviceModel: " + SystemInfo.deviceModel + "\n" + "Device Name: " + SystemInfo.deviceName + "\n" + "Unity XR Device: " + UnityEngine.XR.XRSettings.loadedDeviceName + "\n" + "Unity XR Device Model: " + UnityEngine.XR.XRDevice.model + "\n" + "TButt Platform: " + TBCore.GetActivePlatform() + "\n" + "TButt HMD: " + TBCore.GetActiveHeadset() + "\n" + "Configured Renderscale: " + _displaySettings.renderscale + ", Actual Renderscale: " + UnityEngine.XR.XRSettings.eyeTextureResolutionScale + "\n" + "Configured Refresh Rate: " + _displaySettings.refreshRate + ", Actual Refresh Rate: " + UnityEngine.XR.XRDevice.refreshRate + "\n" + "Configured TBQuality Level: " + _displaySettings.qualityLevel); }
public static TBSettings.TBDisplaySettings LoadDisplaySettings(string filename) { TBSettings.TBDisplaySettings settings = TBDataManager.DeserializeFromFile <TBSettings.TBDisplaySettings>(TBSettings.settingsFolder + filename, TBDataManager.PathType.ResourcesFolder); if (settings.initialized) { return(settings); } else { TBLogging.LogMessage("No settings were found for Windows Mixed Reality. Loading default settings."); return(GetDefaultDisplaySettings(settings)); } }
/// <summary> /// Saves button settings to JSON. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="maps"></param> public static void SaveButtonMaps <T>(ButtonMapGroup <TBInput.ButtonDef <T> > maps) { TBLogging.LogMessage("Writing maps for " + maps.controllerName + " to " + settingsPath + TBSettings.settingsFolder + maps.fileName + ".json...", null, messageEnd); TBInput.SerializedButtonDef[] controllerDef = new TBInput.SerializedButtonDef[maps.defs.Count]; for (int i = 0; i < maps.defs.Count; i++) { controllerDef[i] = new TBInput.SerializedButtonDef(); controllerDef[i].virtualButtons = maps.defs[i].virtualButtons; } //string json = TBDataManager.ToJson<TBInput.SerializedButtonDef>(controllerDef); //TBDataManager.SerializeObjectToFile(TBDataManager.ToJsonWrapper<TBInput.SerializedButtonDef>(controllerDef), settingsPath + TBSettings.settingsFolder + maps.fileName + ".json", TBDataManager.PathType.ResourcesFolder); TBEditorHelper.CheckoutAndSaveJSONFile(settingsPath + TBSettings.settingsFolder + maps.fileName + ".json", TBDataManager.ToJsonWrapper <TBInput.SerializedButtonDef>(controllerDef), TBDataManager.PathType.ResourcesFolder); TBLogging.LogMessage("Finished writing maps for " + maps.controllerName + ". ", null, messageEnd); }
/// <summary> /// Fires the "on system menu" event for when we're going to or coming from a system-level menu during gameplay. /// </summary> /// <param name="focus"></param> private IEnumerator OnApplicationFocus(bool focus) { if (focus) { TBLogging.LogMessage("Application regained focus!"); } else { TBLogging.LogMessage("Application lost focus!"); } yield return(null); Internal.SetSystemMenu(focus); }
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); } }
public override void UnlockAchievement(string token) { base.UnlockAchievement(token); Achievements.Unlock(token).OnComplete((Message <AchievementUpdate> msg) => { if (msg.IsError) { Debug.LogError("Oculus Platform services encountered an error while trying to unlock the achievement!"); } else { TBLogging.LogMessage("Achievement unlocked!"); TBServiceManager.UpdateAchievementList(token, msg.Data.JustUnlocked); } }); }
public static void Initialize() { #if TB_OCULUS_SERVICE _service = VRService.Oculus; _activeService = TBCore.instance.gameObject.AddComponent <TBOculusService>(); #elif TB_STEAM_SERVICE _service = VRService.Steam; _activeService = TBCore.instance.gameObject.AddComponent <TBSteamService>(); #else _service = VRService.None; _activeService = TBCore.instance.gameObject.AddComponent <TBServiceBase>(); #endif _activeService.Initialize(); _initialized = true; TBLogging.LogMessage("Initialized TBServices!"); }
public override Dictionary <string, bool> GetAchievementDictionary() { Dictionary <string, bool> achievements = new Dictionary <string, bool>(); Achievements.GetAllDefinitions().OnComplete((Message <AchievementDefinitionList> msg) => { if (msg.IsError) { TBLogging.LogWarning("Failed to get Oculus achievement dictionary from server"); } else { TBLogging.LogMessage("Received Oculus achievement dictionary from server with " + msg.Data.Count + " entries"); } for (int i = 0; i < msg.Data.Count; i++) { achievements.Add(msg.Data[i].Name, false); } Achievements.GetAllProgress().OnComplete((Message <AchievementProgressList> msg2) => { if (msg2.IsError) { TBLogging.LogWarning("Failed to get Oculus achievement progress from server"); } else { TBLogging.LogMessage("Received Oculus achievement progress dictionary from server with " + msg.Data.Count + " entries"); } for (int j = 0; j < msg2.Data.Count; j++) { bool unlocked = false; if (achievements.TryGetValue(msg2.Data[j].Name, out unlocked)) { achievements[msg2.Data[j].Name] = unlocked; TBLogging.LogMessage("Achievement " + msg2.Data[j].Name + " is unlocked."); } } TBServiceManager.SetAchievementList(achievements); }); }); return(achievements); }
static void ApplyQualitySettingsOverrides(TBQualitySettings settings) { TBLogging.LogMessage("Overriding Unity quality settings..."); QualitySettings.masterTextureLimit = (int)settings.textureQuality; QualitySettings.antiAliasing = (int)settings.antialiasingLevel; QualitySettings.anisotropicFiltering = settings.anisotropicFiltering; QualitySettings.realtimeReflectionProbes = settings.realtimeReflectionProbes; QualitySettings.pixelLightCount = settings.pixelLighCount; QualitySettings.softParticles = settings.softParticles; QualitySettings.shadows = settings.shadowQuality; QualitySettings.shadowResolution = settings.shadowResolution; QualitySettings.shadowNearPlaneOffset = settings.shadowNearPlaneOffset; QualitySettings.shadowDistance = settings.shadowDistance; QualitySettings.lodBias = settings.LODbias; QualitySettings.maximumLODLevel = settings.maximumLODLevel; QualitySettings.blendWeights = settings.blendWeights; }
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(); } }
protected override void LoadClickRemotes() { if (TBCore.UsingEditorMode() || (TBCore.GetActivePlatform() == VRPlatform.OculusPC)) // Oculus Remote is only supported click remote when in the editor or on PC builds. { controller_ClickRemote = TBController_Oculus_Remote.instance; #if UNITY_ANDROID TBLogging.LogMessage("Using Oculus Remote instead of Gear VR Touchpad when running Gear VR builds in the editor."); #endif } else if (TBCore.GetActivePlatform() == VRPlatform.OculusMobile) // Use Gear VR Touchpad when in Android builds { switch (Settings.TBOculusSettings.GetOculusDeviceFamily()) { case Settings.TBOculusSettings.OculusDeviceFamily.GearVR: case Settings.TBOculusSettings.OculusDeviceFamily.Unknown: controller_ClickRemote = TBController_Oculus_GearVRTouchpad.instance; break; } } }
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; } }
private IEnumerator WaitForCameraRig() { yield return(null); TBCameraRig rig; while (true) { rig = FindObjectOfType <TBCameraRig>(); if (rig != null) { TBLogging.LogMessage("TBCameraRig found!"); InitializeCameraAndTracking(rig); yield break; } else { yield return(null); } } }
static void PrintControlSettings() { string inputList = "Supported inputs: "; if (_controlSettings.supportsHandControllers) { inputList += " Hand Controllers. "; } if (_controlSettings.supports3DOFControllers) { inputList += " 3DOF Controllers. "; } if (_controlSettings.supportsClickRemote) { inputList += " Click Remotes. "; } if (_controlSettings.supportsGamepad) { inputList += " Gamepads. "; } TBLogging.LogMessage(inputList); }
protected override void Load3DOFControllers() { if (!TBCore.UsingEditorMode() && (TBCore.GetActivePlatform() == VRPlatform.OculusMobile)) // Prevents 3DOF controller from initializing when on PC unless we're in the editor. { controller_3DOF = TBController_Oculus_GearVRController.instance; } else if (TBCore.UsingEditorMode() || (TBCore.GetActivePlatform() == VRPlatform.OculusPC)) { if (TBSettings.GetControlSettings().handedness3DOF == TBSettings.TBHardwareHandedness.Left) { controller_3DOF = TBController_Oculus_TouchLeft.instance; } else { controller_3DOF = TBController_Oculus_TouchRight.instance; } TBLogging.LogMessage("Emulating 3DOF Controller with Oculus Touch controller with " + TBSettings.GetControlSettings().handedness3DOF + " handedness."); } else { base.Load3DOFControllers(); } }
public static void SetPlatformDefine(string platform, bool on) { if (string.IsNullOrEmpty(buildDefString)) { buildDefString = UnityEditor.PlayerSettings.GetScriptingDefineSymbolsForGroup(UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup); } if (on) { if (!buildDefString.Contains(platform)) { TBLogging.LogMessage("Adding " + platform); buildDefString += ";" + platform; } } else { if (buildDefString.Contains(platform)) { TBLogging.LogMessage("Removing " + platform); buildDefString = buildDefString.Remove(buildDefString.IndexOf(platform), platform.Length); } } }
public virtual void SaveSettingsFile(string filename, object obj) { TBLogging.LogMessage("Saving " + filename + "..."); TBEditorHelper.CheckoutAndSaveJSONFile(TBEditorDefines.settingsPath + TBSettings.settingsFolder + filename + ".json", obj, TBDataManager.PathType.ResourcesFolder); }