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> /// Deserializes a given JSON file into the given type. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fileName"></param> /// <returns></returns> public static T DeserializeFromFile <T>(string fileName, PathType pathType = PathType.PersistentDataPath, bool useEncryption = false) { // Need to handle resource folder files a bit differently. if (pathType == PathType.ResourcesFolder) { TextAsset raw = Resources.Load(fileName) as TextAsset; string rawString = null; if (raw != null) { rawString = raw.ToString(); } if (string.IsNullOrEmpty(rawString)) { return(GetNullOrEmptyOfType <T>()); } else { return(DeserializeString <T>(rawString, fileName, useEncryption)); } } string path = GetPathForType(pathType); string serializedString = ""; if ((pathType == PathType.PersistentDataPath) && Application.isPlaying) { TBLogging.LogWarning("Deserializing files from the persistent data path at runtime will not work on all platforms! Use the Async subclass methods instead."); } serializedString = LoadStringFromStorageDefault(path + fileName); return(DeserializeString <T>(serializedString, fileName, useEncryption)); }
private void ToggleVRMode(bool on) // TODO { if (on) { if (!UsingVRMode()) { if (!_initialized) { } if (Events.OnVRModeEnabled != null) { Events.OnVRModeEnabled(true); } } else { TBLogging.LogWarning("Tried to enter VR mode, but we were already using VR Mode."); } } else { if (UsingVRMode()) { TBLogging.LogWarning("Tried to exit VR mode, but we were already out of VR Mode."); } else { if (Events.OnVRModeEnabled != null) { Events.OnVRModeEnabled(false); } } } }
/// <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(); } }
/// <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); } }
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"); }
public bool GetState(TBXInputButton button, GamepadReading gamepadState) { switch (button) { case TBXInputButton.ButtonA: return(GamepadButtons.A == (gamepadState.Buttons & GamepadButtons.A)); case TBXInputButton.ButtonB: return(GamepadButtons.B == (gamepadState.Buttons & GamepadButtons.B)); case TBXInputButton.ButtonX: return(GamepadButtons.X == (gamepadState.Buttons & GamepadButtons.X)); case TBXInputButton.ButtonY: return(GamepadButtons.Y == (gamepadState.Buttons & GamepadButtons.Y)); case TBXInputButton.LeftStick: return(GamepadButtons.LeftThumbstick == (gamepadState.Buttons & GamepadButtons.LeftThumbstick)); case TBXInputButton.RightStick: return(GamepadButtons.RightThumbstick == (gamepadState.Buttons & GamepadButtons.RightThumbstick)); case TBXInputButton.DpadUp: return(GamepadButtons.DPadUp == (gamepadState.Buttons & GamepadButtons.DPadUp)); case TBXInputButton.DpadRight: return(GamepadButtons.DPadRight == (gamepadState.Buttons & GamepadButtons.DPadRight)); case TBXInputButton.DpadDown: return(GamepadButtons.DPadDown == (gamepadState.Buttons & GamepadButtons.DPadDown)); case TBXInputButton.DpadLeft: return(GamepadButtons.DPadLeft == (gamepadState.Buttons & GamepadButtons.DPadLeft)); case TBXInputButton.Back: return(GamepadButtons.View == (gamepadState.Buttons & GamepadButtons.View)); case TBXInputButton.Start: return(GamepadButtons.Menu == (gamepadState.Buttons & GamepadButtons.Menu)); case TBXInputButton.RightBumper: return(GamepadButtons.RightShoulder == (gamepadState.Buttons & GamepadButtons.RightShoulder)); case TBXInputButton.LeftBumper: return(GamepadButtons.LeftShoulder == (gamepadState.Buttons & GamepadButtons.LeftShoulder)); case TBXInputButton.LeftTrigger: return(gamepadState.LeftTrigger > 0); case TBXInputButton.RightTrigger: return(gamepadState.RightTrigger > 0); default: TBLogging.LogWarning("Could not find requested Windows Input type."); return(false); } }
public static bool HasDataFile(string fileName, PathType pathType = PathType.PersistentDataPath) { if (Application.isPlaying) { TBLogging.LogWarning("TBDataManager.HasDataFile is not safe to call on all platforms! Use the Async subclass."); } return(File.Exists(GetPathForType(pathType) + fileName)); }
/// <summary> /// Needed for generating a controller type compatible with Oculus SDK calls. /// </summary> /// <param name="controller"></param> /// <returns></returns> public static OVRInput.Controller GetOculusControllerID(TBInput.Controller controller) { if (controller == TBInput.Controller.Active) { controller = TBInput.GetActiveController(); } switch (controller) { case TBInput.Controller.LHandController: return(OVRInput.Controller.LTouch); case TBInput.Controller.RHandController: return(OVRInput.Controller.RTouch); case TBInput.Controller.Mobile3DOFController: if (TBCore.UsingEditorMode() || TBCore.GetActivePlatform() == VRPlatform.OculusPC) { if (TBSettings.GetControlSettings().handedness3DOF == TBSettings.TBHardwareHandedness.Left) { return(OVRInput.Controller.LTouch); } else { return(OVRInput.Controller.RTouch); } } else { if (OVRInput.IsControllerConnected(OVRInput.Controller.LTrackedRemote)) { return(OVRInput.Controller.LTrackedRemote); } else { return(OVRInput.Controller.RTrackedRemote); } } case TBInput.Controller.ClickRemote: if (TBCore.GetActivePlatform() == VRPlatform.OculusMobile) { return(OVRInput.Controller.Touchpad); } else { return(OVRInput.Controller.Remote); } case TBInput.Controller.Gamepad: return(OVRInput.Controller.Gamepad); } TBLogging.LogError("Controller type " + controller + " has no match for Oculus."); return(OVRInput.Controller.None); }
/// <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."); } }
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); }
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()); }
public static VRHeadset GetActiveHeadset() { if (_settingsBase != null) { return(_settingsBase.GetActiveHeadset()); } else { TBLogging.LogWarning("Attempted to read active headset before it was initialized."); return(VRHeadset.None); } }
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 uint GetSteamVRControllerID(TBInput.Controller controller) { switch (controller) { case TBInput.Controller.RHandController: return(TBSteamVRDeviceManager.instance.GetRightControllerID()); case TBInput.Controller.LHandController: return(TBSteamVRDeviceManager.instance.GetLeftControllerID()); } TBLogging.LogWarning("Requested device index for controller type " + controller + " that is not supported by Steam VR. Assuming device ID is 0"); return(0); }
public virtual string GetControllerName(TBInput.Controller controller) { if (controller == TBInput.Controller.Active) { controller = GetActiveController(); } if (GetControllerForType(controller) != null) { return(GetControllerForType(controller).GetName()); } TBLogging.LogWarning("Attempted to read controller name, but controller is undefined!"); return("Undefined"); }
public virtual VRController GetControllerModel(TBInput.Controller controller) { if (controller == TBInput.Controller.Active) { controller = GetActiveController(); } if (GetControllerForType(controller) != null) { return(GetControllerForType(controller).GetModel()); } TBLogging.LogWarning("Attempted to get controller model for " + controller + " but controller is undefined!"); return(VRController.None); }
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)); } }
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); } }
public static int GetNumAchievements() { if (_service == VRService.None) { TBLogging.LogWarning("Tried to get achievement list, but no service is initialized.", null, "via TButt.TBServiceManager"); return(0); } if (_achievementList == null) { return(0); } return(_achievementList.Count); }
/// <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); }
/// <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); }
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 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 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); } }); }