Esempio n. 1
0
    void SaveLog()
    {
        if (stringBuilder.Length == 0)
        {
            return;
        }

        GSRequestData logData = new GSRequestData();

        logData.AddString("key", "InAppPurchase");
        logData.AddString("message", "User purchase in-app");

        GSData _d = new GSData(new Dictionary <string, object>()
        {
            { "purchase", stringBuilder },
        });

        logData.AddObject("data", _d);

        GameSparksManager.Instance.Log(logData);

        string purchaseLog = PreferencesFactory.GetString("PurchaseLog", "");

        purchaseLog = string.Format("{0}\n-----------\n{1}", purchaseLog, stringBuilder);

        PreferencesFactory.SetString("PurchaseLog", purchaseLog);

        stringBuilder.Length = 0;
    }
    void CheckNotificationsPermission()
    {
        int      CountMainMenuColdStart = PreferencesFactory.GetInt(Constants.KeyCountMainMenuColdStart);
        DateTime now = UnbiasedTime.Instance.Now();

        // not in first launch
        if (CountMainMenuColdStart > 0 && !Allowed())
        {
            // the date when we detected that notifications are denied
            if (!PreferencesFactory.HasKey(Constants.KeyNoNotificationPermissionDeniedDate))
            {
                PreferencesFactory.SetString(Constants.KeyNoNotificationPermissionDeniedDate, now.ToString(CultureInfo.InvariantCulture));

                return;
            }

            DateTime dateOfDenying = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyNoNotificationPermissionDeniedDate, now.ToString(CultureInfo.InvariantCulture)));
            float    minutes3days  = 3 * 24 * 60;
            float    minutes10days = 10 * 24 * 60;

            if (Debug.isDebugBuild)
            {
                minutes3days  = 1f;                // 30 sec
                minutes10days = 2f;                // 1 min
            }

            // 3 days before show alert for first time
            if (now.Date < dateOfDenying.AddMinutes(minutes3days).Date)
            {
                return;
            }

            DateTime postponeDate = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyNoNotificationPermissionDate, now.ToString(CultureInfo.InvariantCulture)));

            // 10 days to show alert again if user postpone it
            if (PreferencesFactory.HasKey(Constants.KeyNoNotificationPermissionDate) &&
                now.Date < postponeDate.AddMinutes(minutes10days).Date)
            {
                return;
            }

            PreferencesFactory.DeleteKey(Constants.KeyNoNotificationPermissionDate);

            string text = LocaliseText.Get("Notifications.DeniedText");

            Alert alert = new Alert("", text)
                          .SetPositiveButton(LocaliseText.Get("Notifications.AllowText"), () => {
                iSDK.Utils.OpenSettings();
            })
                          .SetNeutralButton(LocaliseText.Get("Notifications.IgnoreText"), () => {
                PreferencesFactory.SetString(Constants.KeyNoNotificationPermissionDate, now.ToString(CultureInfo.InvariantCulture));
            })
                          .AddOptions(new AlertIOSOptions()
            {
                PreferableButton = Alert.ButtonType.Positive
            });

            alert.Show();
        }
    }
    public static void RewardRate()
    {
        DateTime dateTime = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyRateRewardLastDate, UnbiasedTime.Instance.Now().AddDays(-1).ToString(CultureInfo.InvariantCulture)));

        if (dateTime.Date < UnbiasedTime.Instance.Now().Date)
        { // last rate was yesterday, reset all data
            PreferencesFactory.SetString(Constants.KeyRateRewardLastDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture));
            PreferencesFactory.SetInt(Constants.KeyRateRewardTotal, 0);

            dateTime = UnbiasedTime.Instance.Now();
        }

        int totalRates = PreferencesFactory.GetInt(Constants.KeyRateRewardTotal);

        if (dateTime.Date == UnbiasedTime.Instance.Now().Date&& totalRates < 1)
        {
            GameObject animatedCoins = GameObject.Find("AddCoinsAnimated");

            GameObject       addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent);
            AddCoinsAnimated addCoins      = addCoinsClone.GetComponent <AddCoinsAnimated>();

            RectTransform tr = null;
            GameObject    _c = GameObject.Find("BoardContainer");

            if (_c != null)
            {
                tr = _c.transform as RectTransform;
            }

            addCoins.AnimateCoinsAdding(Constants.RateRewardCoins, rect: tr, showAnimation: false);
        }

        PreferencesFactory.SetInt(Constants.KeyRateRewardTotal, totalRates + 1);
        PreferencesFactory.SetInt(Constants.KeyRateMaxRewardsTime, PreferencesFactory.GetInt(Constants.KeyRateMaxRewardsTime, 0) + 1);
    }
Esempio n. 4
0
    public static bool BonusCoins()
    {
        DateTime dateTime = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyAskFriendsLastDate, UnbiasedTime.Instance.Now().AddDays(-1).ToString(CultureInfo.InvariantCulture)));

        if (dateTime.Date < UnbiasedTime.Instance.Now().Date)
        { // last invite was yesterday, reset all data
            PreferencesFactory.SetString(Constants.KeyAskFriendsLastDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture));
            PreferencesFactory.SetInt(Constants.KeyAskFriendsTotal, 0);

            dateTime = UnbiasedTime.Instance.Now();
        }

        bool addedCoins = false;

        int totalInvites = PreferencesFactory.GetInt(Constants.KeyAskFriendsTotal);

        if (dateTime.Date == UnbiasedTime.Instance.Now().Date&& totalInvites < Constants.AskFriendsPerDay)
        {
            GameObject animatedCoins = GameObject.Find("AddCoinsAnimated");

            GameObject       addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent);
            AddCoinsAnimated addCoins      = addCoinsClone.GetComponent <AddCoinsAnimated>();

            addCoins.AnimateCoinsAdding(Constants.AskFriendsCoins, rect: GameObject.Find("BoardContainer").transform as RectTransform, showAnimation: false);

            addedCoins = true;
        }

        PreferencesFactory.SetInt(Constants.KeyAskFriendsTotal, totalInvites + 1);

        return(addedCoins);
    }
    public void SyncProgress()
    {
        if (!IsUserLoggedIn())
        {
            return;
        }

        DateTime now = UnbiasedTime.Instance.Now();

        // when implement void SaveState(), add it here to save state before sync
        CustomFreePrizeManager.Instance.SaveState();
        LevelController.Instance.SaveState();

        PreferencesFactory.SetString("LastProgressSyncDate", now.ToString(CultureInfo.InvariantCulture), false);
        PreferencesFactory.Save();

        string json = JSONPrefs.String();

        GSRequestData parsedJson = new GSRequestData(json);

        new LogEventRequest()
        .SetEventKey("PlayerProgress")
        .SetEventAttribute("data", parsedJson)
        .Send(((response) => {
            if (!response.HasErrors)
            {
                PlayerPrefs.SetString("LastProgressSyncDate", now.ToString(CultureInfo.InvariantCulture));
                PlayerPrefs.Save();
            }
        }));
    }
Esempio n. 6
0
    private void ProcessDailyBonus(bool doublePrize = true)
    {
        _prizeIsProcessed = true;
        int DaysInRow  = PreferencesFactory.GetInt(Constants.KeyFreePrizeTakeDaysInRow, 0);
        int extraCoins = 0;

        if (DaysInRow == 7)                         // reset
        {
            extraCoins = Constants.DialyBonusCoins; // bonus coins at last day

            PreferencesFactory.SetInt(Constants.KeyFreePrizeTakeDaysInRow, 1);
        }

        PreferencesFactory.SetString(Constants.KeyDateLastFreePrizeTake, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture));

        if (PrizeDialogClosedAudioClip != null)
        {
            GameManager.Instance.PlayEffect(PrizeDialogClosedAudioClip);
        }

        if ((prizeIsCoins && this.PrizeItems > 0) || extraCoins > 0)
        {
            // add extra coins to reward coins only of prize is coins
            if (prizeIsCoins)
            {
                extraCoins += this.PrizeItems;
            }

            GameObject       animatedCoins = GameObject.Find("AddCoinsAnimated");
            GameObject       addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent);
            AddCoinsAnimated addCoins      = addCoinsClone.GetComponent <AddCoinsAnimated>();

            addCoins.AnimateCoinsAdding(extraCoins);
        }

        if (prizeIsPoints)
        {
            GameObject animatedPoints = GameObject.Find("AddPointsAnimated");

            GameObject        _clone = Instantiate(animatedPoints, animatedPoints.transform.parent);
            AddPointsAnimated _add   = _clone.GetComponent <AddPointsAnimated>();

            _add.AnimateAdding(this.PrizeItems);

            GameSparksManager.Instance.SendPoints(this.PrizeItems, "FreePrize");
        }

        SetCurrentPrizeAmount();

        // Local notifications
#if !UNITY_EDITOR
        CancelLocalNotifications();
        RegisterLocalNotifications();
#endif

        if (doublePrize)
        {
            ShowDoubleScreen();
        }
    }
Esempio n. 7
0
    public void ChangeUser(string userName)
    {
        if (string.IsNullOrEmpty(userName))
        {
            DialogManager.Instance.ShowError(LocaliseText.Get("Account.UsernameEmptyError"));
            return;
        }

        if (!IsUsernameValid(userName))
        {
            DialogManager.Instance.ShowError(LocaliseText.Get("Account.UsernameNotValid"));
            return;
        }

        new ChangeUserDetailsRequest()
        .SetDisplayName(userName)
        .Send((response) => {
            if (response.HasErrors)
            {
                ParseServerResponse(response.Errors);
                return;
            }

            PreferencesFactory.SetString(Constants.ProfileUsername, userName);
        });
    }
        /// <summary>
        /// Save the current state including free prize times
        /// </summary>
        public override void SaveState()
        {
            MyDebug.Log("FreePrizeManager: SaveState");

            PreferencesFactory.SetString("FreePrize.NextCountdownStart", NextCountdownStart.ToString(CultureInfo.InvariantCulture));
            PreferencesFactory.SetString("FreePrize.NextPrize", NextFreePrizeAvailable.ToString(CultureInfo.InvariantCulture));
            PreferencesFactory.Save();
        }
Esempio n. 9
0
 /// <summary>
 /// Update PlayerPrefs with values that should be saved.
 /// </summary>
 /// Note: This does not call PlayerPrefs.Save()
 /// <param name="prefix"></param>
 /// <param name="useSecurePrefs"></param>
 public void UpdatePlayerPrefs(string prefix = "", bool?useSecurePrefs = null)
 {
     foreach (var variable in StringVariables)
     {
         if (variable.PersistChanges)
         {
             PreferencesFactory.SetString(prefix + variable.Tag, variable.Value, useSecurePrefs);
         }
     }
 }
    public static void LoadLevelFromServer(Action <JSONArray> callback = null)
    {
        GameSparksManager.Instance.GetWords((JSONArray _arr) => {
            PreferencesFactory.SetString(Constants.KeyRandomLevelWords, _arr.ToString());

            if (callback != null)
            {
                callback(_arr);
            }
        });
    }
    public static void ChangeLanguage(string language)
    {
        for (var i = 0; i < LocaliseText.AllowedLanguages.Length; i++)
        {
            if (LocaliseText.AllowedLanguages[i] == language)
            {
                LocaliseText.Language = language;

                PreferencesFactory.SetString("Language", language, useSecurePrefs: false);
            }
        }
    }
Esempio n. 12
0
 /// <summary>
 /// Update PlayerPrefs with values that should be saved.
 /// </summary>
 /// Note: This does not call PreferencesFactory.Save()
 /// <param name="prefix"></param>
 /// <param name="useSecurePrefs"></param>
 public void UpdatePlayerPrefs(string prefix = "", bool?useSecurePrefs = null)
 {
     foreach (var variable in BoolVariables)
     {
         if (variable.PersistChanges)
         {
             PreferencesFactory.SetBool(prefix + variable.Tag, variable.Value, useSecurePrefs);
         }
     }
     foreach (var variable in FloatVariables)
     {
         if (variable.PersistChanges)
         {
             PreferencesFactory.SetFloat(prefix + variable.Tag, variable.Value, useSecurePrefs);
         }
     }
     foreach (var variable in IntVariables)
     {
         if (variable.PersistChanges)
         {
             PreferencesFactory.SetInt(prefix + variable.Tag, variable.Value, useSecurePrefs);
         }
     }
     foreach (var variable in StringVariables)
     {
         if (variable.PersistChanges)
         {
             PreferencesFactory.SetString(prefix + variable.Tag, variable.Value, useSecurePrefs);
         }
     }
     foreach (var variable in Vector2Variables)
     {
         if (variable.PersistChanges)
         {
             PreferencesFactory.SetVector2(prefix + variable.Tag, variable.Value, useSecurePrefs);
         }
     }
     foreach (var variable in Vector3Variables)
     {
         if (variable.PersistChanges)
         {
             PreferencesFactory.SetVector3(prefix + variable.Tag, variable.Value, useSecurePrefs);
         }
     }
     foreach (var variable in ColorVariables)
     {
         if (variable.PersistChanges)
         {
             PreferencesFactory.SetColor(prefix + variable.Tag, variable.Value, useSecurePrefs);
         }
     }
 }
    void GetUploadMessage(GSMessage message)
    {
        var uploadId = message.BaseData.GetString("uploadId");

        new GetUploadedRequest()
        .SetUploadId(uploadId)
        .Send((response) => {
            GSData scriptData = response.ScriptData;
            var size          = response.Size;
            string url        = response.Url;

            PreferencesFactory.SetString(Constants.ProfileAvatarUploadId, uploadId);
        });
    }
Esempio n. 14
0
        public static void SetLanguage(SystemLanguage language)
        {
            if (language == Application.systemLanguage)
            {
                PreferencesFactory.DeleteKey(SettingsKeys.Language);
            }
            else
            {
                PreferencesFactory.SetString(SettingsKeys.Language, language.ToString());
            }

            _initialized = false;
            if (OnLocalisationChanged != null)
            {
                OnLocalisationChanged(null, null);
            }
        }
    public void AnonymousLogin()
    {
        if (!GS.Available)
        {
            GS.Reconnect();
        }

        new DeviceAuthenticationRequest()
        .Send((response) => {
            if (!response.HasErrors)
            {
                if (string.IsNullOrEmpty(response.UserId) == false)
                {
                    PreferencesFactory.SetString(Constants.ProfileAnonymousUserId, response.UserId);
                }
            }
        });
    }
Esempio n. 16
0
    public void Show(Action callback = null)
    {
        this.active = true;

        if (callback != null)
        {
            _closeCallback = callback;
        }

        GameObjectHelper.GetChildNamedGameObject(gameObject, "Dialog", true).SetActive(true);

        GameManager.SafeAddListener <FacebookAppRequestMessage>(FacebookMessageHandler);

        if (!Debug.isDebugBuild)
        {
            Fabric.Answers.Answers.LogContentView("Invite", "Dialog");
        }

        PreferencesFactory.SetString(Constants.KeyInviteBalloonShowedDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture));

        HideBalloon();
    }
Esempio n. 17
0
    public static bool InviteBonusCoins()
    {
        DateTime dateTime = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyInviteLastDate, UnbiasedTime.Instance.Now().AddDays(-1).ToString(CultureInfo.InvariantCulture)));

        if (dateTime.Date < UnbiasedTime.Instance.Now().Date)
        { // last invite was yesterday, reset all data
            PreferencesFactory.SetString(Constants.KeyInviteLastDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture));
            PreferencesFactory.SetInt(Constants.KeyInvitesTotal, 0);

            dateTime = UnbiasedTime.Instance.Now();
        }

        bool addedCoins = false;

        int totalInvites = PreferencesFactory.GetInt(Constants.KeyInvitesTotal);

#if UNITY_EDITOR
        totalInvites = 0;
#endif

        if (dateTime.Date == UnbiasedTime.Instance.Now().Date&& totalInvites < Constants.InviteMaxPerDay)
        {
            GameObject animatedCoins = GameObject.Find("AddCoinsAnimated");

            GameObject       addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent);
            AddCoinsAnimated addCoins      = addCoinsClone.GetComponent <AddCoinsAnimated>();

            addCoins.AnimateCoinsAdding(Constants.InviteAwardCoins);

            addedCoins = true;
        }

        PreferencesFactory.SetInt(Constants.KeyInvitesTotal, totalInvites + 1);

        return(addedCoins);
    }
    void CompleteReward()
    {
        GameObject       animatedCoins = GameObject.Find("AddCoinsAnimated");
        GameObject       addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent);
        AddCoinsAnimated addCoins      = addCoinsClone.GetComponent <AddCoinsAnimated>();

        addCoins.AnimateCoinsAdding(Constants.FreeCoinsDaily);

        //

        PreferencesFactory.SetString(Constants.KeyFreeCoinsAvailable, UnbiasedTime.Instance.Now().AddMinutes(Constants.MinutesBetweenFreeCoins).ToString(CultureInfo.InvariantCulture));

        int TimesFreeCoins = PreferencesFactory.GetInt(Constants.KeyFreeCoinsCounter, 0);

        TimesFreeCoins += 1;

        PreferencesFactory.SetInt(Constants.KeyFreeCoinsCounter, TimesFreeCoins);

        if (TimesFreeCoins >= Constants.TimesFreeCoins)
        {
            GameObjectHelper.SafeSetActive(FreeCoinsObject, false);
            GameObjectHelper.SafeSetActive(FreeCoinsCounterObject, true);
        }
    }
    public void SendPoints(int points, string source = null, JSONObject pointsJsonData = null)
    {
        int    offlinePoints     = PreferencesFactory.GetInt(Constants.KeyOfflinePoints, 0);
        string _pointsDataString = PreferencesFactory.GetString(Constants.KeyOfflinePointsData, null);

        if (pointsJsonData != null && source != null)
        {
            pointsJsonData.Add("source", source);
        }

        JSONArray _pointsData = new JSONArray();

        if (!string.IsNullOrEmpty(_pointsDataString))
        {
            try
            {
                _pointsData = JSONArray.Parse(_pointsDataString);
            } catch (Exception e) {}
        }

        if (pointsJsonData != null)     // add new record
        {
            _pointsData.Add(pointsJsonData);
        }

        if (Reachability.Instance.IsReachable() == false || IsUserLoggedIn() == false)
        {
            PreferencesFactory.SetInt(Constants.KeyOfflinePoints, points + offlinePoints);
            PreferencesFactory.SetString(Constants.KeyOfflinePointsData, _pointsData.ToString());

            return;
        }

        if (points + offlinePoints <= 0)
        {
            return;
        }

        int levelNumber = -1;

        try
        {
            Level level = LevelController.FirstUnplayedLevel();

            if (level != null)
            {
                levelNumber = level.Number - 1;
            }
        } catch (Exception e) {}

        GSRequestData requestData = new GSRequestData();

        requestData.AddNumber("offlinePoints", offlinePoints);
        requestData.AddNumber("score", points);
        requestData.AddNumber("lastPlayedLevel", levelNumber);

        if (_pointsData != null)
        {
            requestData.AddJSONStringAsObject("pointsData", _pointsData.ToString());
        }

        if (source != null)
        {
            requestData.AddString("source", source);
        }

        new LogEventRequest()
        .SetEventKey("SubmitScoreV2")
        .SetEventAttribute("score", points + offlinePoints)
        .SetEventAttribute("data", requestData)
        .Send((response) => {
            if (!response.HasErrors)
            {
                PreferencesFactory.DeleteKey(Constants.KeyOfflinePoints);
                PreferencesFactory.DeleteKey(Constants.KeyOfflinePointsData);
            }
        });
    }
    protected override void GameSetup()
    {
        // secure preferences
        PreferencesFactory.UseSecurePrefs = SecurePreferences;
        if (SecurePreferences)
        {
            if (string.IsNullOrEmpty(PreferencesPassPhrase))
            {
                Debug.LogWarning("You have not set a custom pass phrase in GameManager | Player Preferences. Please correct for improved security.");
            }
            else
            {
                PreferencesFactory.PassPhrase = PreferencesPassPhrase;
            }
            PreferencesFactory.AutoConvertUnsecurePrefs = AutoConvertUnsecurePrefs;
        }

        StartupLevels = NumberOfAutoCreatedLevels;

        int NumberOfAdditionalCreatedLevels = PreferencesFactory.GetInt(Constants.KeyNumberOfAdditionalCreatedLevels);

        NumberOfAutoCreatedLevels += NumberOfAdditionalCreatedLevels;

        string FirstAppStartDate = PreferencesFactory.GetString(Constants.KeyFirstAppStartDate, null);

        if (FirstAppStartDate == null)
        {
            PreferencesFactory.SetString(Constants.KeyFirstAppStartDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture));
        }

        PreferencesFactory.SetString(Constants.KeyLastAppStartDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture));

        int TimesAppStarted = PreferencesFactory.GetInt(Constants.KeyTimesAppStarted, 0);

        PreferencesFactory.SetInt(Constants.KeyTimesAppStarted, TimesAppStarted + 1);

        base.GameSetup();

        if (PlayerPrefs.GetInt("ManualChangedLanguage", 0) == 0)
        {
#if UNITY_ANDROID || UNITY_EDITOR
            string savedLanguage  = PreferencesFactory.GetString("Language", useSecurePrefs: false);
            string systemLanguage = DeviceLanguage();

            // user does not changed his language manual
            // and system language is different from previous auto-detected
            if (systemLanguage != savedLanguage)
            {
                LanguageController.ChangeLanguage(systemLanguage);
            }
#endif

#if UNITY_IOS
            IOSNativeUtility.OnLocaleLoaded += GetLocale;
            IOSNativeUtility.Instance.GetLocale();
#endif
        }

        Packs = new PackGameItemManager();

        if (LevelSetupMode == GameItemSetupMode.FromResources)
        {
            Packs.Load(1, NumberOfAutoCreatedPacks);
        }

        Ranks = new RankGameItemManager();

        if (LevelSetupMode == GameItemSetupMode.FromResources)
        {
            Ranks.Load(1, NumberOfAutoCreatedRanks);
        }

        Rank rank = Ranks.GetItem(1);

        if (!rank.IsUnlocked)
        {
            rank.IsUnlocked = true; // first rank is unlocked by default
            rank.UpdatePlayerPrefs();
        }

        Pack pack = Packs.GetItem(1);

        if (!pack.IsUnlocked)
        {
            pack.IsUnlocked = true; // first pack is unlocked by default
            pack.UpdatePlayerPrefs();
        }

        Level level = Levels.GetItem(1);

        if (!level.IsUnlocked)
        {
            level.IsUnlocked = true; // first level is unlocked by default
            level.UpdatePlayerPrefs();
        }

        GameManager.SafeAddListener <UserNotificationsChangedMessage>(UserNotificationsChangedHandler);
        GameManager.SafeAddListener <LocalisationChangedMessage>(LocalisationHandler);

        // bug fix in gameframework when user loose all his lives and start game again and Lives back to full
        if (FirstAppStartDate != null)
        { // but only after first start ever
            Player.Lives = Player.GetSettingInt("Lives", 0);
        }

        if (FirstAppStartDate == null)
        { // first start
            PreferencesFactory.SetInt(Constants.KeyNotificationsAllowed, 1);
        }

        //

        Advertisement.Initialize(Constants.UnityAdsGameId);

        if (BackGroundAudioVolume > Constants.DefaultAudioVolume)
        {
            BackGroundAudioVolume = Constants.DefaultAudioVolume;
        }

        if (EffectAudioVolume > Constants.DefaultAudioVolume)
        {
            EffectAudioVolume = Constants.DefaultAudioVolume;
        }

        _currentBackgroundSoundVolume = BackGroundAudioVolume;

        if (!SoundEnabled())
        {
            BackGroundAudioSource.Stop();
        }

#if UNITY_IPHONE
        SA.IOSNative.Core.AppController.Subscribe();

        SA.IOSNative.Core.AppController.OnApplicationDidReceiveMemoryWarning += OnApplicationDidReceiveMemoryWarning;
#endif

#if !UNITY_EDITOR
        CancelLocalNotifications();
        RegisterLocalNotifications();
#endif
    }
Esempio n. 21
0
    public void ConnectedWithFacebook()
    {
        if (FacebookManager.Instance.IsLoggedIn)
        {
            if (!GS.Available)
            {
                GS.Reconnect();
            }

            new FacebookConnectRequest()
            .SetAccessToken(AccessToken.CurrentAccessToken.TokenString)
            .SetDoNotLinkToCurrentPlayer(false)
            .SetSwitchIfPossible(true)
            .Send((response) => {
                if (!response.HasErrors)
                {
                    var scriptData = response.ScriptData;
                    if (scriptData != null)
                    {
                        var avatar = scriptData.GetString("avatar");

                        if (avatar != null)
                        {
                            PreferencesFactory.SetString(Constants.ProfileAvatar, avatar);
                        }
                    }

                    var displayName = response.DisplayName;
                    var userId      = response.UserId;

                    PreferencesFactory.SetString(Constants.ProfileUsername, displayName);
                    PreferencesFactory.SetString(Constants.ProfileUserId, response.UserId);
                    PreferencesFactory.SetString(Constants.ProfileFBUserId, AccessToken.CurrentAccessToken.UserId);
                    PreferencesFactory.Save();

                    if (_callback != null)
                    {
                        _callback.OnUserLoggedIn();
                    }

                    if (response.NewPlayer == true)
                    {
                        GameManager.SafeQueueMessage(new UserRegisterMessage());

                        if (!Debug.isDebugBuild)
                        {
                            Fabric.Answers.Answers.LogSignUp("Facebook");
                            Branch.userCompletedAction("RegisterFacebook");
                            Branch.setIdentity(PreferencesFactory.GetString(Constants.ProfileUserId));
                        }
                    }
                    else
                    {
                        GameManager.SafeQueueMessage(new UserLoginMessage());

                        if (!Debug.isDebugBuild)
                        {
                            Fabric.Answers.Answers.LogLogin("Facebook");
                            Branch.userCompletedAction("LoginFacebook");
                            Branch.setIdentity(PreferencesFactory.GetString(Constants.ProfileUserId));
                        }
                    }

                    if (!Debug.isDebugBuild)
                    {
                        Flurry.Flurry.Instance.LogEvent("Register_Facebook");
                    }
                }
                else
                {
                    MyDebug.Log(response.Errors.JSON.ToString());
                    ParseServerResponse(response.Errors);
                }
            });
        }
    }
Esempio n. 22
0
    public void LoginAction(GameObject GO)
    {
        var mainTransform = GO.transform;
        var email         = mainTransform.Find("EmailField").GetComponent <InputField> ();
        var password      = mainTransform.Find("PasswordField").GetComponent <InputField> ();

        var emailString    = email.text;
        var passwordString = password.text;

        if (string.IsNullOrEmpty(emailString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.EmailEmptyError"), "CLOSE");
            return;
        }
        if (!IsMailValid(emailString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.EmailNotValidError"), "CLOSE");
            return;
        }
        if (string.IsNullOrEmpty(passwordString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.PasswordEmptyError"), "CLOSE");
            return;
        }

        if (!Reachability.Instance.IsReachable())
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.NoConnection"), "CLOSE");
            return;
        }

        if (!GS.Available)
        {
            GS.Reconnect();
        }

        Loading.Instance.Show();

        new AuthenticationRequest()
        .SetUserName(emailString)
        .SetPassword(passwordString)
        .Send(((response) => {
            Loading.Instance.Hide();

            if (!response.HasErrors)
            {
                email.text = null;
                password.text = null;

                var scriptData = response.ScriptData;
                if (scriptData != null)
                {
                    var avatar = scriptData.GetString("avatar");

                    if (avatar != null)
                    {
                        PreferencesFactory.SetString(Constants.ProfileAvatar, avatar);
                    }
                }

                var username = response.DisplayName;
                PreferencesFactory.SetString(Constants.ProfileUsername, username);
                PreferencesFactory.SetString(Constants.ProfileUserId, response.UserId);
                PreferencesFactory.SetString(Constants.ProfileEmail, emailString);
                PreferencesFactory.Save();

                if (_callback != null)
                {
                    _callback.OnUserLoggedIn();
                }

                GameManager.SafeQueueMessage(new UserLoginMessage());

                if (!Debug.isDebugBuild)
                {
                    Fabric.Answers.Answers.LogLogin("Email");
                    Branch.userCompletedAction("Login");
                    Branch.setIdentity(PreferencesFactory.GetString(Constants.ProfileUserId));
                }
            }
            else
            {
                ParseServerResponse(response.Errors);
            }
        }));
    }
Esempio n. 23
0
    public void RegisterAction(GameObject GO)
    {
        var mainTransform  = GO.transform;
        var email          = mainTransform.Find("EmailField").GetComponent <InputField> ();
        var username       = mainTransform.Find("UsernameField").GetComponent <InputField> ();
        var password       = mainTransform.Find("PasswordField").GetComponent <InputField> ();
        var repearPassword = mainTransform.Find("RepeatPasswordField").GetComponent <InputField> ();

        var emailString    = email.text;
        var usernameString = username.text;
        var passwordString = password.text;
        var repeatString   = repearPassword.text;

        if (string.IsNullOrEmpty(emailString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.EmailEmptyError"), "OK");
            return;
        }
        if (!IsMailValid(emailString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.EmailNotValidError"), "OK");
            return;
        }
        if (string.IsNullOrEmpty(usernameString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.UsernameEmptyError"), "OK");
            return;
        }
        if (!IsUsernameValid(usernameString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.UsernameNotValid"), "OK");
            return;
        }
        if (string.IsNullOrEmpty(passwordString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.PasswordEmptyError"), "OK");
            return;
        }
        if (string.IsNullOrEmpty(repeatString) || !repeatString.Equals(passwordString))
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.PasswordsNotEqual"), "OK");
            return;
        }

        if (!Reachability.Instance.IsReachable())
        {
            ShowInfoDialogWithText(LocaliseText.Get("Account.NoConnection"), "CLOSE");
            return;
        }

        if (!GS.Available)
        {
            GS.Reconnect();
        }

        Loading.Instance.Show();

        // user was logged from DeviceAuthenticationRequest and now only update his data
        if (PreferencesFactory.HasKey(Constants.ProfileAnonymousUserId))
        {
            new ChangeUserDetailsRequest()
            .SetDisplayName(usernameString)
            .SetUserName(emailString)
            .SetNewPassword(passwordString)
            .Send((response) => {
                Loading.Instance.Hide();

                if (response.HasErrors)
                {
                    ParseServerResponse(response.Errors);
                    return;
                }

                email.text          = null;
                username.text       = null;
                password.text       = null;
                repearPassword.text = null;

                PreferencesFactory.SetString(Constants.ProfileEmail, emailString);
                PreferencesFactory.SetString(Constants.ProfileUsername, usernameString);
                PreferencesFactory.SetString(Constants.ProfileUserId, PreferencesFactory.GetString(Constants.ProfileAnonymousUserId));
                PreferencesFactory.DeleteKey(Constants.ProfileAnonymousUserId);
                PreferencesFactory.Save();

                if (_callback != null)
                {
                    _callback.OnUserRegistered();
                }
                GameManager.SafeQueueMessage(new UserRegisterMessage());

                if (!Debug.isDebugBuild)
                {
                    Flurry.Flurry.Instance.LogEvent("Register_Email");
                    Fabric.Answers.Answers.LogSignUp("Email");
                    Branch.userCompletedAction("Register");
                    Branch.setIdentity(PreferencesFactory.GetString(Constants.ProfileUserId));
                }
            });

            return;
        }

        new RegistrationRequest()
        .SetUserName(emailString)
        .SetDisplayName(usernameString)
        .SetPassword(passwordString)
        .Send(((response) => {
            Loading.Instance.Hide();

            if (!response.HasErrors)
            {
                email.text = null;
                username.text = null;
                password.text = null;
                repearPassword.text = null;

                var scriptData = response.ScriptData;
                if (scriptData != null)
                {
                    var avatar = scriptData.GetString("avatar");

                    if (avatar != null)
                    {
                        PreferencesFactory.SetString(Constants.ProfileAvatar, avatar);
                    }
                }

                PreferencesFactory.SetString(Constants.ProfileEmail, emailString);
                PreferencesFactory.SetString(Constants.ProfileUsername, response.DisplayName);
                PreferencesFactory.SetString(Constants.ProfileUserId, response.UserId);
                PreferencesFactory.Save();

                if (_callback != null)
                {
                    _callback.OnUserRegistered();
                }
                GameManager.SafeQueueMessage(new UserRegisterMessage());

                if (!Debug.isDebugBuild)
                {
                    Flurry.Flurry.Instance.LogEvent("Register_Email");
                    Fabric.Answers.Answers.LogSignUp("Email");
                    Branch.userCompletedAction("Register");
                    Branch.setIdentity(PreferencesFactory.GetString(Constants.ProfileUserId));
                }
            }
            else
            {
                ParseServerResponse(response.Errors);
            }
        }));
    }