diff --git a/unity_package/Runtime/VELConnectManager.cs b/unity_package/Runtime/VELConnectManager.cs index dc0216c..9c75240 100644 --- a/unity_package/Runtime/VELConnectManager.cs +++ b/unity_package/Runtime/VELConnectManager.cs @@ -65,8 +65,7 @@ namespace VELConnect /// public string TryGetData(string key) { - string val = null; - return userData.data?.TryGetValue(key, out val) == true ? val : null; + return userData.TryGetData(key); } } @@ -593,6 +592,41 @@ namespace VELConnect return instance != null ? instance.lastState?.room?.TryGetData(key) : defaultValue; } + public static T GetRoomData(string key, string defaultValue = null) + { + string value = instance != null ? instance.lastState?.room?.TryGetData(key) : defaultValue; + + if (typeof(T) == typeof(int)) + { + if (int.TryParse(value, out int result)) + { + return (T)Convert.ChangeType(result, typeof(T)); + } + + return (T)(object)0; + } + else if (typeof(T) == typeof(double)) + { + if (double.TryParse(value, out double result)) + { + return (T)Convert.ChangeType(result, typeof(T)); + } + + return (T)(object)0.0; + } + else if (typeof(T) == typeof(float)) + { + if (float.TryParse(value, out float result)) + { + return (T)Convert.ChangeType(result, typeof(T)); + } + + return (T)(object)0f; + } + + throw new NotSupportedException($"Conversion to type {typeof(T)} is not supported."); + } + /// /// Sets data on the device keys themselves /// These are fixed fields defined for every application diff --git a/unity_package/package.json b/unity_package/package.json index 491beda..0a9a24a 100644 --- a/unity_package/package.json +++ b/unity_package/package.json @@ -1,7 +1,7 @@ { "name": "edu.uga.engr.vel.vel-connect", "displayName": "VEL-Connect", - "version": "2.1.2", + "version": "2.1.3", "unity": "2019.1", "description": "Web-based configuration for VR applications", "keywords": [],