private void ReadGameStateFromCookie() { #if !UNITY_EDITOR var results = CookieApi.GetInstantAppCookie(); Debug.Log("readGameStateFromCookie: " + results); if (string.IsNullOrEmpty(results)) { return; } var attributes = results.Split(','); if (attributes.Length < 2) { return; } var cookieLevel = attributes[0]; var cookieScore = attributes[1]; _level = int.Parse(cookieLevel); _score = int.Parse(cookieScore); Debug.Log("CookieLevel: " + cookieLevel); Debug.Log("CookieScore: " + cookieScore); #endif }
private static void WriteGameStateToCookie(int level, int score) { #if !UNITY_EDITOR var gameStateCsv = level + "," + score; CookieApi.SetInstantAppCookie(gameStateCsv); #endif }
/// <summary> /// Reads the cookie and verifies if it matches the one we stored. /// </summary> public void ButtonEventReadCookie() { // TODO: Currently reading the cookie from the instant app. Prefer to read it from installed app. var readCookie = CookieApi.GetInstantAppCookie(); Debug.LogFormat("Successfully read cookie: {0}", readCookie); if (string.Equals(readCookie, _storedCookie)) { Debug.Log("Read cookie matches the value we stored"); } else { Debug.LogError("Read cookie does not match the value we stored"); } }
/// <summary> /// Sets the instant app cookie to a unique string. /// </summary> public void ButtonEventWriteCookie() { // Write a random value so WriteCookie will always change the cookie. // Note: System.Guid is unavailable with micro mscorlib. var guid = Random.Range(int.MinValue, int.MaxValue); _storedCookie = string.Format("{0}:{1}", guid, CookiePrefix); Debug.LogFormat("Attempting to write cookie: {0}", _storedCookie); if (CookieApi.SetInstantAppCookie(_storedCookie)) { Debug.Log("Successfully wrote cookie"); } else { Debug.LogError("Failed to write cookie"); } }
public void DoInstallClick() { Debug.Log("DoInstallClick"); #if PLAY_INSTANT Debug.LogFormat("Cookie max size: {0}", CookieApi.GetInstantAppCookieMaxSizeBytes()); var result = CookieApi.SetInstantAppCookie("test-cookie"); Debug.LogFormat("Set cookie result: {0}", result); using (var activity = UnityPlayerHelper.GetCurrentActivity()) using (var postInstallIntent = InstallLauncher.CreatePostInstallIntent(activity)) { InstallLauncher.PutPostInstallIntentStringExtra(postInstallIntent, "payload", "test-payload-value"); InstallLauncher.ShowInstallPrompt(activity, 1234, postInstallIntent, "test-referrer"); } #else Debug.LogErrorFormat("Intent result: \"{0}\"", InstallLauncher.GetPostInstallIntentStringExtra("payload")); Debug.LogErrorFormat("Cookie: \"{0}\"", CookieApi.GetInstantAppCookie()); #endif }