/// <summary> /// Create / update the value of the given key associated to the current logged in gamer. /// </summary> /// <param name="valueType">Type of the value to set.</param> /// <param name="key">Name of the key to set.</param> /// <param name="value">Value of the key to set.</param> public static void Handling_SetGamerKey(Bundle.DataType valueType, string key, string value) { // The key name should not be empty if (string.IsNullOrEmpty(key)) { DebugLogs.LogError("[CotcSdkTemplate:GamerVFSFeatures] The key name is empty ›› Please enter a valid key name"); } else { Bundle setValue; // Create a Bundle from the given value string (a Bundle is an json-like object to represent fields data) according to expected value type switch (valueType) { case Bundle.DataType.Object: setValue = Bundle.FromJson(value); break; case Bundle.DataType.String: setValue = new Bundle(value); break; case Bundle.DataType.Double: setValue = new Bundle(double.Parse(value)); break; case Bundle.DataType.Integer: setValue = new Bundle(int.Parse(value)); break; case Bundle.DataType.Boolean: setValue = new Bundle(bool.Parse(value)); break; // TODO: You may want to add the Array (list) type handling default: DebugLogs.LogError(string.Format("[CotcSdkTemplate:GamerVFSFeatures] The {0} type is unhandled ›› Please handle it or use an handled type", valueType)); return; } Backend_SetValue(key, setValue, SetGamerKey_OnSuccess, SetGamerKey_OnError); } }
/// <summary> /// When the corresponding button is clicked, create / update the value of the given key associated to the current logged in gamer. /// </summary> public void Button_SetGamerKey() { // Default hardcoded values to use if no InputField elements references are assigned string key = "TestString"; string value = "Test value."; Bundle.DataType type = Bundle.DataType.String; // Check the key value if (setGamerKey_Key == null) { Debug.LogWarning(string.Format(noReferenceFormat, "GamerVFS", "setGamerKey_Key")); } else if (!string.IsNullOrEmpty(setGamerKey_Key.text)) { key = setGamerKey_Key.text; } // Check the value value if (setGamerKey_Value == null) { Debug.LogWarning(string.Format(noReferenceFormat, "GamerVFS", "setGamerKey_Value")); } else if (!string.IsNullOrEmpty(setGamerKey_Value.text)) { value = setGamerKey_Value.text; } // Check the type value if (setGamerKey_Type == null) { Debug.LogWarning(string.Format(noReferenceFormat, "GamerVFS", "setGamerKey_Type")); } // This foreach should give only one active toggle else { foreach (Toggle activeToggle in setGamerKey_Type.ActiveToggles()) { switch (activeToggle.name) { case "Toggle-JsonType": type = Bundle.DataType.Object; break; case "Toggle-StringType": type = Bundle.DataType.String; break; case "Toggle-DoubleType": type = Bundle.DataType.Double; break; case "Toggle-IntType": type = Bundle.DataType.Integer; break; case "Toggle-BoolType": type = Bundle.DataType.Boolean; break; } } } // Call the template method GamerVFSFeatures.Handling_SetGamerKey(type, key, value); }