/// <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); }
/// <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); }
protected GvrControllerInputDevice GetGoogleControllerID(TBInput.Controller controller) { if (controller == TBInput.Controller.Active) { controller = TBInput.GetActiveController(); } switch (controller) { case TBInput.Controller.LHandController: return(GvrControllerInput.GetDevice(GvrControllerHand.Left)); case TBInput.Controller.RHandController: return(GvrControllerInput.GetDevice(GvrControllerHand.Right)); case TBInput.Controller.Mobile3DOFController: return(GvrControllerInput.GetDevice(GvrControllerHand.Dominant)); default: TBLogging.LogError("No controller for " + controller + " exists in TButt's Google VR implementation. Falling back to dominant hand controller."); return(GvrControllerInput.GetDevice(GvrControllerHand.Dominant)); } }