added a type-converting room data query function
parent
1645a79abc
commit
8da2f1b4d6
|
|
@ -65,8 +65,7 @@ namespace VELConnect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string TryGetData(string key)
|
public string TryGetData(string key)
|
||||||
{
|
{
|
||||||
string val = null;
|
return userData.TryGetData(key);
|
||||||
return userData.data?.TryGetValue(key, out val) == true ? val : null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -593,6 +592,41 @@ namespace VELConnect
|
||||||
return instance != null ? instance.lastState?.room?.TryGetData(key) : defaultValue;
|
return instance != null ? instance.lastState?.room?.TryGetData(key) : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static T GetRoomData<T>(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.");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets data on the device keys themselves
|
/// Sets data on the device keys themselves
|
||||||
/// These are fixed fields defined for every application
|
/// These are fixed fields defined for every application
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "edu.uga.engr.vel.vel-connect",
|
"name": "edu.uga.engr.vel.vel-connect",
|
||||||
"displayName": "VEL-Connect",
|
"displayName": "VEL-Connect",
|
||||||
"version": "2.1.2",
|
"version": "2.1.3",
|
||||||
"unity": "2019.1",
|
"unity": "2019.1",
|
||||||
"description": "Web-based configuration for VR applications",
|
"description": "Web-based configuration for VR applications",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue