コード例 #1
0
        public async Task <Sprite> getAvatar(string url)
        {
            var    hashCode = url.GetHashCode();
            Sprite sprite   = null;

            if (!Images.TryGetValue(hashCode, out sprite))
            {
                Texture2D texture  = new Texture2D(100, 100);
                string    prefsURL = PlayerPrefs.GetString(url);
                if (string.IsNullOrEmpty(url))
                {
                    return(null);
                }
                UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
                await www.SendWebRequest();

                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.LogWarning(www.error);
                    return(null);
                }
                var avatarTexture = DownloadHandlerTexture.GetContent(www);
                texture = ImagesManager.RoundCrop(avatarTexture);
                PlayerPrefs.SetString(url, System.Convert.ToBase64String(texture.EncodeToPNG()));
                sprite = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), Vector2.zero);
                Images.Add(hashCode, sprite);
                return(sprite);
            }
            else
            {
                return(sprite);
            }
        }
コード例 #2
0
        public static Sprite getSpriteFromBytes(byte[] bytes)
        {
            Texture2D texture   = new Texture2D(1, 1);
            Sprite    newSprite = null;

            texture.LoadImage(bytes);
            Texture2D roundTxt = ImagesManager.RoundCrop(texture);

            newSprite = Sprite.Create(roundTxt as Texture2D, new Rect(0f, 0f, roundTxt.width, roundTxt.height), Vector2.zero);
            return(newSprite);
        }
コード例 #3
0
        public IEnumerator initPlayerAvatar(string url, Image avatar)
        {
            UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);

            yield return(www.SendWebRequest());

            var       texture  = DownloadHandlerTexture.GetContent(www);
            Texture2D RoundTxt = ImagesManager.RoundCrop(texture);

            avatar.sprite = Sprite.Create(RoundTxt, new Rect(0, 0, RoundTxt.width, RoundTxt.height), new Vector2(0, 0));
        }
コード例 #4
0
        public void Signup(string username, string email, string password, Image avatar)
        {
            LoaderManager.Get.LoaderController.ShowLoader(LoaderManager.CHECKING_CONNECTION);
            StartCoroutine(
                EventsController.Get.checkInternetConnection(async(isConnected) =>
            {
                if (isConnected == true)
                {
                    Texture2D mytexture = avatar.sprite.texture;
                    byte[] bytes;
                    bytes = mytexture.EncodeToPNG();

                    LoaderManager.Get.LoaderController.ShowLoader(LoaderManager.ACCOUNT_CREATING);

                    var avatarUrl = await ImagesManager.FixImage(bytes);

                    JSONNode Res = null;
                    if (avatarUrl != "error")
                    {
                        Res = await UserManager.Get.signingUp(username.ToUpper(), email, password, avatarUrl);
                    }
                    LoaderManager.Get.LoaderController.HideLoader();

                    if (Res["success"].AsBool)
                    {
                        SeembaAnalyticsManager.Get.SendGameEvent("Signed up");
                        var deviceToken = PlayerPrefs.GetString("DeviceToken");
                        var userid      = UserManager.Get.getCurrentUserId();
                        var platform    = "";
                        if (Application.platform == RuntimePlatform.Android)
                        {
                            platform = "android";
                        }
                        else
                        {
                            platform = "ios";
                        }
                        //Add Device Token To Receive notification on current device
                        try
                        {
                            await UserManager.Get.addUserDeviceToken(userid, GamesManager.GAME_ID, deviceToken, platform);
                        }
                        catch (Exception)
                        {
                        }
                        UserManager.Get.CurrentUser.username = username;
                        LoaderManager.Get.LoaderController.ShowLoader(LoaderManager.SAVING);
                        UserManager.Get.CurrentAvatarBytesString = await UserManager.Get.getAvatar(avatarUrl);
                        var mTexture = await UserManager.Get.GetFlagBytes(await UserManager.Get.GetGeoLoc());
                        UserManager.Get.CurrentFlagBytesString = Convert.ToBase64String(mTexture.EncodeToPNG());
                        PlayerPrefs.SetString("CurrentFlagBytesString", UserManager.Get.CurrentFlagBytesString);
                        ChallengeManager.CurrentChallengeGain     = "2";
                        ChallengeManager.CurrentChallengeGainType = ChallengeManager.CHALLENGE_WIN_TYPE_BUBBLES;
                        LoaderManager.Get.LoaderController.HideLoader();
                        EventsController.Get.startFirstChallenge(Res["token"].Value);
                        SeembaAnalyticsManager.Get.SendUserEvent("Signed up with Email");
                    }
                    else
                    {
                        ConnectivityController.CURRENT_ACTION = "";
                        LoaderManager.Get.LoaderController.HideLoader();
                        PopupManager.Get.PopupController.ShowPopup(PopupType.INFO_POPUP_CONNECTION_FAILED, PopupsText.Get.ConnectionFailed());
                        SeembaAnalyticsManager.Get.SendGameEvent("weak network");
                    }
                }
            }));
        }