Ejemplo n.º 1
0
    // Download from Cloud Storage into a byte array.
    protected IEnumerator DownloadBytesWithEmail(Dictionary <string, object> scoreEntry)
    {
        var storageReference = GetStorageReference();
        var imageReference   = storageReference.Child("images/" + scoreEntry["email"].ToString());
        //Texture
        Texture2D tex = new Texture2D(128, 128, TextureFormat.PVRTC_RGBA4, false);

        DebugLog(String.Format("Downloading {0} ...", imageReference.Path));
        var task = imageReference.GetBytesAsync(
            0, new StorageProgress <DownloadState>(DisplayDownloadState),
            cancellationTokenSource.Token);

        yield return(new WaitForTaskCompletion(this, task));

        if (!(task.IsFaulted || task.IsCanceled))
        {
            DebugLog("Finished downloading bytes");
            //Add sprite
            fileContents = System.Text.Encoding.Default.GetString(task.Result);
            tex.LoadImage(task.Result);
            Sprite profilePic = Sprite.Create(tex, new Rect(0, 0, 128, 128), new Vector2());
            scoreEntry["sprite"] = profilePic;
            LeaderboardEntry e = (LeaderboardEntry)scoreEntry["entry"];
            e.AddSprite(profilePic);
            DebugLog(String.Format("File Size {0} bytes\n", fileContents.Length));
        }
    }