コード例 #1
0
    /// <summary>
    /// Called when a purchase fails.
    /// </summary>
    public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    {
        PurchaseInProgress = false;
        Loading.Instance.Hide();

        stringBuilder.AppendFormat("Product {0} failed at {1}, reason: {2}\n", LastPurchaseProductId, UnbiasedTime.Instance.UTCNow().ToString(CultureInfo.InvariantCulture), failureReason);

        SaveLog();

        MyDebug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));

        Fabric.Crashlytics.Crashlytics.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));

        // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing this reason with the user.
        switch (failureReason)
        {
        // for these cases we don't need to inform further
        case PurchaseFailureReason.UserCancelled:
            break;

        // for these we show an error
        default:
            DialogManager.Instance.ShowError(LocaliseText.Format("GeneralMessage.Error.GeneralError", failureReason));
            break;
        }
    }
コード例 #2
0
        /// <summary>
        /// Free prize dialog that giges the user coins. We default to the standard General Message window, adding any additional
        /// content as setup in the FreePrizeManager configuration.
        /// </summary>
        public void ShowFreePrizeDialog()
        {
            var    dialogInstance = DialogManager.Instance.Create(null, null, ContentPrefab, null, runtimeAnimatorController: ContentAnimatorController);
            string text           = LocaliseText.Format("FreePrize.Text1", CurrentPrizeAmount);

            dialogInstance.Show(title: LocaliseText.Get("FreePrize.Title"), text: text, text2Key: "FreePrize.Text2", doneCallback: ShowFreePrizeDone, dialogButtons: ContentShowsButtons ? DialogInstance.DialogButtonsType.Custom : DialogInstance.DialogButtonsType.Ok);
        }
コード例 #3
0
        /// <summary>
        /// Should be called if we assume they like the game and when not invoked as a direct result of their
        /// actions (e.g. use after 20 plays). Gives rate, later and remind options.
        /// </summary>
        public void GameFeedbackAssumeTheyLikeOptional()
        {
            // open the text based upon the platform
            var text2Key = "";

            switch (Application.platform)
            {
            case RuntimePlatform.Android:
                text2Key = "GameFeedback.AssumeLikeOptionalAndroid";
                break;

            case RuntimePlatform.IPhonePlayer:
                text2Key = "GameFeedback.AssumeLikeOptionaliOS";
                break;
            }

            DialogManager.Instance.Show("GameFeedbackDialog",
                                        titleKey: "GameFeedback.RateTitle",
                                        text2: LocaliseText.Format(text2Key, GameManager.Instance.GameName),
                                        doneCallback: RateCallback,
                                        dialogButtons: DialogInstance.DialogButtonsType.Custom);

//#if UNITY_EDITOR
//            Application.OpenURL(GameManager.Instance.PlayWebUrl);
//#elif UNITY_ANDROID
//		AndroidRateUsPopUp rate = AndroidRateUsPopUp.Create(DialogTitle, String.Format(LocaliseText.Get("GameFeedback.AssumeLikeOptionalAndroid"), GameManager.Instance.GameName), GameManager.Instance.PlayMarketUrl);
//        rate.ActionComplete += OnAndroidRatePopUpClose;
//#elif UNITY_IPHONE
//		IOSRateUsPopUp rate = IOSRateUsPopUp.Create(DialogTitle, String.Format(LocaliseText.Get("GameFeedback.AssumeLikeOptionaliOS"), GameManager.Instance.GameName));
//        rate.OnComplete += OnIOSRatePopUpClose;
//#else
//#endif
        }
コード例 #4
0
    void AnimateScoreText(int _points)
    {
        Text _scoreText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(_multiplayer ? multiplayerView : pointsView, "ScoreResult", true);

        if (!_scoreText)
        {
            return;
        }

        int points = 0;

        DOTween.To(() => points, x => points = x, _points, 1.25f).SetEase(Ease.Linear).OnUpdate(() => {
            if (!_scoreText)
            {
                return;
            }

            string distanceText;
            if (points == 1 || points == -1)
            {
                distanceText = LocaliseText.Format("LevelCompleted.ScoreOne", points.ToString());
            }
            else
            {
                distanceText = LocaliseText.Format("LevelCompleted.Score", points.ToString());
            }

            _scoreText.text = distanceText;
        });
    }
コード例 #5
0
    public static void SetRewardText(GameObject parent)
    {
        Text text = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(parent, "Text", true);

        if (text == null)
        {
            return;
        }

        text.text = string.Format("+ {0}", LocaliseText.Format("Text.NumberCoins", Constants.AskFriendsCoins));
    }
コード例 #6
0
    void CompleteReward()
    {
        if (!Debug.isDebugBuild)
        {
            Flurry.Flurry.Instance.LogEvent("ExtraCoins_DailyBonus");
            Fabric.Answers.Answers.LogCustom("ExtraCoins_DailyBonus");
        }

        if (dialogInstance != null && dialogInstance.gameObject != null && this.PrizeItems > 0)
        {
            GameObject part2 = GameObjectHelper.GetChildNamedGameObject(dialogInstance.Content, "Part2", true);

            Text rewardsCoinsText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(part2, "RewardsCoins", true);

            if (prizeIsPoints)
            {
                rewardsCoinsText.text = LocaliseText.Format("FreePrize.NumberMorePoints", this.PrizeItems);
            }

            if (prizeIsCoins)
            {
                rewardsCoinsText.text = LocaliseText.Format("FreePrize.NumberMoreCoins", this.PrizeItems);
            }

            GameObject WatchAds = GameObjectHelper.GetChildNamedGameObject(part2, "WatchAds", true);
            WatchAds.SetActive(false);

            GameObject DoubleButton = GameObjectHelper.GetChildNamedGameObject(part2, "DoubleButton", true);
            DoubleButton.SetActive(false);

            if (prizeIsCoins && this.PrizeItems > 0)
            {
                GameObject animatedCoins = GameObject.Find("AddCoinsAnimated");

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

                addCoins.AnimateCoinsAdding(this.PrizeItems);
            }

            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-Double");
            }
        }
    }
コード例 #7
0
 public void OnInitLoginAndGetUserDataAction(FacebookManager.FacebookHelperResultType result)
 {
     FacebookManager.Instance.OnInitLoginAndGetUserDataAction -= OnInitLoginAndGetUserDataAction;
     if (result == FacebookManager.FacebookHelperResultType.OK)
     {
         FacebookManager.Instance.AppRequest(message: LocaliseText.Format("Facebook.Invite.Caption", GameManager.Instance.GameName), title: LocaliseText.Format("Facebook.Invite.Description", GameManager.Instance.GameName));
     }
     else
     {
         DialogManager.Instance.ShowError(textKey: "Facebook.Error.Login.Description");
     }
 }
コード例 #8
0
    public virtual void BuyProductId(string productId)
    {
        if (PurchaseInProgress == true)
        {
            DialogManager.Instance.ShowInfo("Purchase processing...");
            return;
        }

        stringBuilder.Length  = 0;
        PurchaseInProgress    = true;
        LastPurchaseProductId = productId;

        //

        // If the stores throw an unexpected exception, use try..catch to protect my logic here.
        try
        {
            // If Purchasing has been initialized ...
            if (IsInitialized())
            {
                // ... look up the Product reference with the general product identifier and the Purchasing system's products collection.
                Product product = _controller.products.WithID(productId);

                // If the look up found a product for this device's store and that product is ready to be sold ...
                if (product != null && product.availableToPurchase)
                {
                    Loading.Instance.Show();
                    stringBuilder.AppendFormat("Buy product {0} at {1}, coins {2}, points {3}\n", productId, UnbiasedTime.Instance.UTCNow().ToString(CultureInfo.InvariantCulture), GameManager.Instance.Player.Coins, GameManager.Instance.Player.Score);

                    MyDebug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));// ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed asynchronously.
                    _controller.InitiatePurchase(product);
                }
                // Otherwise ...
                else
                {
                    // ... report the product look-up failure situation
                    DialogManager.Instance.ShowError(textKey: "Billing.NotAvailable");
                }
            }
            // Otherwise ...
            else
            {
                // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or retrying initiailization.
                DialogManager.Instance.ShowError(textKey: "Billing.NotInitialised");
            }
        }
        // Complete the unexpected exception handling ...
        catch (Exception e)
        {
            // ... by reporting any unexpected exception for later diagnosis.
            DialogManager.Instance.ShowError(LocaliseText.Format("GeneralMessage.Error.GeneralError", e.ToString()));
        }
    }
コード例 #9
0
        /// <summary>
        /// Should be called when invoked as a direct result of their actions (e.g. click rate button) and
        /// if we assume they like the game.
        /// This displays a popup with just a message and ok button before taking them to the rate page.
        /// </summary>
        public void GameFeedbackAssumeTheyLike()
        {
            DialogManager.Instance.Show(titleKey: "GameFeedback.RateTitle",
                                        text2: LocaliseText.Format("GameFeedback.AssumeLike", GameManager.Instance.GameName),
                                        doneCallback: RateCallback);
            //#if UNITY_EDITOR

            //            Application.OpenURL(GameManager.Instance.PlayWebUrl);
            //#elif UNITY_ANDROID
            //		AndroidMessage msg = AndroidMessage.Create(DialogTitle, String.Format(LocaliseText.Get("GameFeedback.AssumeLikeAndroid"), GameManager.Instance.GameName));
            //        msg.ActionComplete += OnAndroidRateMessageClose;
            //#elif UNITY_IPHONE
            //		IOSMessage msg = IOSMessage.Create(DialogTitle, String.Format(LocaliseText.Get("GameFeedback.AssumeLikeiOS"), GameManager.Instance.GameName));
            //        msg.OnComplete += OnIOSRateMessageClose;
            //#else
            //#endif
        }
コード例 #10
0
 public void OnInitLoginAndGetUserDataAction(FacebookManager.FacebookHelperResultType result)
 {
     FacebookManager.Instance.OnInitLoginAndGetUserDataAction -= OnInitLoginAndGetUserDataAction;
     if (result == FacebookManager.FacebookHelperResultType.OK)
     {
         FacebookManager.Instance.ShareLink(
             contentURL: new Uri(FacebookManager.Instance.PostLink),
             contentTitle: LocaliseText.Format("Facebook.Share.Caption", GameManager.Instance.GameName),
             contentDescription: LocaliseText.Format("Facebook.Share.Description", GameManager.Instance.GameName),
             photoURL: new Uri(FacebookManager.Instance.PostPicture)
             );
     }
     else
     {
         DialogManager.Instance.ShowError(textKey: "Facebook.Error.Login.Description");
     }
 }
コード例 #11
0
        /// <summary>
        /// Called when a purchase fails.
        /// </summary>
        public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
        {
            Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));

            // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing this reason with the user.
            switch (failureReason)
            {
            // for these cases we don't need to inform further
            case PurchaseFailureReason.UserCancelled:
                break;

            // for these we show an error
            default:
                DialogManager.Instance.ShowError(LocaliseText.Format("GeneralMessage.Error.GeneralError", failureReason));
                break;
            }
        }
コード例 #12
0
 /// <summary>
 /// Should be called as a direct result of the user clicking on a rate button when you are uncertain if they
 /// like the game. Gives a yes/no dialog to check they like. Yes takes them to the rate page, no takes
 /// them to a feedback dialog.
 /// </summary>
 public void GameFeedbackUnsureIfTheyLike()
 {
     DialogManager.Instance.Show("GameFeedbackDialog",
                                 titleKey: "GameFeedback.FeedbackTitle",
                                 text2: LocaliseText.Format("GameFeedback.AssumeLike", GameManager.Instance.GameName),
                                 doneCallback: LikeCallback,
                                 dialogButtons: DialogInstance.DialogButtonsType.YesNo);
     //#if UNITY_EDITOR
     //            Application.OpenURL(GameManager.Instance.PlayWebUrl);
     //#elif UNITY_ANDROID
     //		AndroidDialog dialog = AndroidDialog.Create(LocaliseText.Get("GameFeedback.FeedbackTitle"), String.Format(LocaliseText.Get("GameFeedback.Unsure"), GameManager.Instance.GameName));
     //		dialog.ActionComplete += OnAndroidUnsureIfTheyLikeDialogClose;
     //#elif UNITY_IPHONE
     //		IOSDialog dialog = IOSDialog.Create(LocaliseText.Get("GameFeedback.FeedbackTitle"), String.Format(LocaliseText.Get("GameFeedback.Unsure"), GameManager.Instance.GameName));
     //		dialog.OnComplete += OnIOSUnsureIfTheyLikeDialogClose;
     //#else
     //#endif
 }
コード例 #13
0
    public void ShowPointsScreen()
    {
        Text nameText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text> (DialogInstance.gameObject, "LevelName", true);

        if (_multiplayer)
        {
            nameText.text = LocaliseText.Get("LevelCompleted.Match");
            multiplayerView.SetActive(true);
        }
        else
        {
            Level currentLevel = GameManager.Instance.Levels.Selected;

            nameText.text = LocaliseText.Format("LevelCompleted.LevelName", currentLevel.Number);
            pointsView.SetActive(true);
        }

        shareView.SetActive(false);
    }
コード例 #14
0
    void CompleteReward()
    {
        var currentLevel = GameManager.Instance.Levels.Selected;
        var points       = currentLevel.Score;

        currentLevel.AddPoints(points);

        GameManager.Instance.Player.AddPoints(points);

        GameManager.Instance.Player.UpdatePlayerPrefs();
        currentLevel.UpdatePlayerPrefs();
        PreferencesFactory.Save();

        UIHelper.SetTextOnChildGameObject(pointsView, "ScoreResult", LocaliseText.Format("LevelCompleted.ScoreDouble", points), true);

        GameObject DoubleButton = GameObjectHelper.GetChildNamedGameObject(pointsView, "DoubleButton", true);

        DoubleButton.SetActive(false);

        GameObject AdsObject = GameObjectHelper.GetChildNamedGameObject(pointsView, "Ads", true);

        AdsObject.SetActive(false);

        GameObject unlockTextObject = GameObjectHelper.GetChildNamedGameObject(pointsView, "UnlockText", true);

        unlockTextObject.SetActive(false);

        GameObject ShareButton = GameObjectHelper.GetChildNamedGameObject(pointsView, "ShareButton", true);

        ShareButton.SetActive(true);

        if (!_multiplayer)
        {
            JSONObject pointsData = new JSONObject();
            pointsData.Add("Level", currentLevel.Number.ToString());
            pointsData.Add("Language", LocaliseText.Language);
            pointsData.Add("RealLanguage", LanguageUtils.RealLanguage(LocaliseText.Language));
            pointsData.Add("Words", JsonUtils.ListToArray(GameController.Instance.GetFoundWords()));
            pointsData.Add("Date", DateTimeUtils.DateTimeToISO8601(UnbiasedTime.Instance.UTCNow()));

            GameSparksManager.Instance.SendPoints(points, "LevelComplete-Double", pointsData);
        }
    }
コード例 #15
0
        /// <summary>
        /// Show an advert and award the player coins if they complete watching it.
        /// </summary>
        /// <param name="coins"></param>
        public static void ShowWatchAdvertForCoins(int coins)
        {
#if UNITY_ADS
            //TODO only show advert button if actually ready to avoid errors.
            if (Advertisement.IsReady())
            {
                Advertisement.Show(null, new ShowOptions
                {
                    //pause = true,
                    resultCallback = result =>
                    {
                        switch (result)
                        {
                        case (ShowResult.Finished):
                            GameManager.Instance.Player.Coins += coins;
                            GameManager.Instance.Player.UpdatePlayerPrefs();
                            PreferencesFactory.Save();
                            DialogManager.Instance.Show(title: "Coins", text: LocaliseText.Format("Advertising.UnityAds.WatchForCoins.Finished", coins));
                            break;

                        case (ShowResult.Skipped):
                            DialogManager.Instance.Show(title: "Coins", text: LocaliseText.Get("Advertising.UnityAds.WatchForCoins.Skipped"));
                            break;

                        case (ShowResult.Failed):
                            DialogManager.Instance.Show(title: "Coins", text: LocaliseText.Get("Advertising.UnityAds.WatchForCoins.UnableToShow"));
                            break;
                        }
                        Debug.Log(result.ToString());
                    }
                });
            }
            else
            {
                DialogManager.Instance.Show(title: "Error", text: LocaliseText.Get("Advertising.UnityAds.UnableToShow"));
            }
#else
            DialogManager.Instance.ShowInfo("This functionality requires that you enable the standard Unity Ads service.\n\nPlease check our website if you need further help.");
#endif
        }
コード例 #16
0
    void ShowDoubleScreen()
    {
        GameObject part1 = GameObjectHelper.GetChildNamedGameObject(dialogInstance.Content, "Part1", true);

        GameObjectHelper.SafeSetActive(part1, false);

        GameObject part2 = GameObjectHelper.GetChildNamedGameObject(dialogInstance.Content, "Part2", true);

        GameObjectHelper.SafeSetActive(part2, true);

        Text rewardsCoinsText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text> (part2, "RewardsCoins", true);

        if (prizeIsPoints)
        {
            rewardsCoinsText.text = LocaliseText.Format("FreePrize.NumberPoints", this.PrizeItems);
        }

        if (prizeIsCoins)
        {
            rewardsCoinsText.text = LocaliseText.Format("FreePrize.NumberCoins", this.PrizeItems);
        }
    }
コード例 #17
0
        /// <summary>
        /// Try and purchase the given product id.
        /// </summary>
        /// <param name="productId"></param>
        public virtual void BuyProductId(string productId)
        {
            // If the stores throw an unexpected exception, use try..catch to protect my logic here.
            try
            {
                // If Purchasing has been initialized ...
                if (IsInitialized())
                {
                    // ... look up the Product reference with the general product identifier and the Purchasing system's products collection.
                    Product product = _controller.products.WithID(productId);

                    // If the look up found a product for this device's store and that product is ready to be sold ...
                    if (product != null && product.availableToPurchase)
                    {
                        Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id)); // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed asynchronously.
                        _controller.InitiatePurchase(product);
                    }
                    // Otherwise ...
                    else
                    {
                        // ... report the product look-up failure situation
                        DialogManager.Instance.ShowError(textKey: "Billing.NotAvailable");
                    }
                }
                // Otherwise ...
                else
                {
                    // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or retrying initiailization.
                    DialogManager.Instance.ShowError(textKey: "Billing.NotInitialised");
                }
            }
            // Complete the unexpected exception handling ...
            catch (Exception e)
            {
                // ... by reporting any unexpected exception for later diagnosis.
                DialogManager.Instance.ShowError(LocaliseText.Format("GeneralMessage.Error.GeneralError", e.ToString()));
            }
        }
コード例 #18
0
        /// <summary>
        /// Update the display for needed coins to unlock a new level if that option is in use.
        /// </summary>
        public void UpdateNeededCoins()
        {
            var minimumCoins          = GameManager.Instance.Levels.ExtraCoinsNeededToUnlock(GameManager.Instance.Player.Coins);
            var targetCoinsGameobject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "TargetCoins", true);

            if (targetCoinsGameobject != null)
            {
                if (minimumCoins == 0)
                {
                    UIHelper.SetTextOnChildGameObject(DialogInstance.gameObject, "TargetCoins",
                                                      LocaliseText.Format(LocalisationBase + ".TargetCoinsGot", minimumCoins), true);
                }
                else if (minimumCoins > 0)
                {
                    UIHelper.SetTextOnChildGameObject(DialogInstance.gameObject, "TargetCoins",
                                                      LocaliseText.Format(LocalisationBase + ".TargetCoins", minimumCoins), true);
                }
                else
                {
                    targetCoinsGameobject.SetActive(false);
                }
            }
        }
コード例 #19
0
        public override void RunMethod()
        {
            TimeSpan time = FreePrizeManager.Instance.GetTimeToPrize();

            _text.text = LocaliseText.Format("FreePrize.NewPrize", time.Hours, time.Minutes, time.Seconds);
        }
コード例 #20
0
        /// <summary>
        /// Shows the game over dialog.
        /// </summary>
        /// Override this in your own base class if you want to customise the game over window. Be sure to call this base instance when done.
        public virtual void Show(bool isWon)
        {
            Assert.IsTrue(LevelManager.IsActive, "Ensure that you have a LevelManager component attached to your scene.");

            var currentLevel = GameManager.Instance.Levels.Selected;

            // update the player score if necessary
            if ((UpdatePlayerScore == CopyType.Always) || (UpdatePlayerScore == CopyType.OnWin && isWon))
            {
                GameManager.Instance.Player.AddPoints(currentLevel.Score);
            }

            // update the player coins if necessary
            if ((UpdatePlayerCoins == CopyType.Always) || (UpdatePlayerCoins == CopyType.OnWin && isWon))
            {
                GameManager.Instance.Player.AddCoins(currentLevel.Coins);
            }

            // show won / lost game objects as appropriate
            GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Lost", true), !isWon);

            // see if the world or game is won and also if we should unlock the next world / level
            GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "GameWon", true), false);
            GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "WorldWon", true), false);
            GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "LevelWon", true), false);
            GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Won", true), false);
            if (isWon)
            {
                //TODO: if coins unlock mode then need to check all levels are done before saying world complete - same for game...
                //TODO: perhaps in future we might want to distinguish between the first and subsequent times a user completes something?
                //// is the game won
                //if (GameHelper.IsCurrentLevelLastInGame()) {
                //    GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "GameWon", true), true);
                //}

                //// is a world won
                //else if (GameHelper.IsCurrentLevelLastInGame())
                //{
                //    GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "WorldWon", true), true);
                //}

                //// level won
                //else if (GameManager.Instance.Levels.GetNextItem() != null)
                //{
                //    GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "LevelWon", true), true);
                //}

                //// else won with some other condition
                //else
                //{
                GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Won", true), true);
                //}

                // process and update game state - do this last so we can check some bits above.
                GameHelper.ProcessCurrentLevelComplete();
            }

            // set some text based upon the result
            UIHelper.SetTextOnChildGameObject(DialogInstance.gameObject, "AchievementText", LocaliseText.Format(LocalisationBase + ".Achievement", currentLevel.Score, currentLevel.Name));

            // setup stars
            var starsGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Stars", true);

            GameObjectHelper.SafeSetActive(starsGameObject, ShowStars);
            if (ShowStars)
            {
                Assert.IsNotNull(starsGameObject, "GameOver->ShowStars is enabled, but could not find a 'Stars' gameobject. Disable the option or fix the structure.");
                starsGameObject.SetActive(ShowStars);
                var newStarsWon = GetNewStarsWon();
                currentLevel.StarsWon |= newStarsWon;
                var star1WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star1", true);
                var star2WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star2", true);
                var star3WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star3", true);
                StarWon(currentLevel.StarsWon, newStarsWon, star1WonGameObject, 1);
                StarWon(currentLevel.StarsWon, newStarsWon, star2WonGameObject, 2);
                StarWon(currentLevel.StarsWon, newStarsWon, star3WonGameObject, 4);
                GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(starsGameObject, "StarWon", true), newStarsWon != 0);
            }

            // set time
            var difference     = DateTime.Now - LevelManager.Instance.StartTime;
            var timeGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Time", true);

            GameObjectHelper.SafeSetActive(timeGameObject, ShowTime);
            if (ShowTime)
            {
                Assert.IsNotNull(timeGameObject, "GameOver->ShowTime is enabled, but could not find a 'Time' gameobject. Disable the option or fix the structure.");

                UIHelper.SetTextOnChildGameObject(timeGameObject, "TimeResult", difference.Minutes.ToString("D2") + "." + difference.Seconds.ToString("D2"), true);
            }

            // set coins
            var coinsGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Coins", true);

            GameObjectHelper.SafeSetActive(coinsGameObject, ShowCoins);
            if (ShowCoins)
            {
                Assert.IsNotNull(coinsGameObject, "GameOver->ShowCoins is enabled, but could not find a 'Coins' gameobject. Disable the option or fix the structure.");
                UIHelper.SetTextOnChildGameObject(coinsGameObject, "CoinsResult", currentLevel.Coins.ToString(), true);
            }

            // set score
            var scoreGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Score", true);

            GameObjectHelper.SafeSetActive(scoreGameObject, ShowScore);
            if (ShowScore)
            {
                Assert.IsNotNull(scoreGameObject, "GameOver->ShowScore is enabled, but could not find a 'Score' gameobject. Disable the option or fix the structure.");
                var distanceText = LocaliseText.Format(LocalisationBase + ".ScoreResult", currentLevel.Score.ToString());
                if (currentLevel.HighScore > currentLevel.OldHighScore)
                {
                    distanceText += "\n" + LocaliseText.Get(LocalisationBase + ".NewHighScore");
                }
                UIHelper.SetTextOnChildGameObject(scoreGameObject, "ScoreResult", distanceText, true);
            }

            UpdateNeededCoins();

            // save game state.
            GameManager.Instance.Player.UpdatePlayerPrefs();
            currentLevel.UpdatePlayerPrefs();
            PreferencesFactory.Save();

            //show dialog
            DialogInstance.Show();

            //TODO bug - as we increase TimesPlayedForRatingPrompt on both game start (GameManager) and level finish we can miss this comparison.
            if (GameManager.Instance.TimesPlayedForRatingPrompt == TimesPlayedBeforeRatingPrompt)
            {
                var gameFeedback = new GameFeedback();
                gameFeedback.GameFeedbackAssumeTheyLikeOptional();
            }

#if UNITY_ANALYTICS
            // record some analytics on the level played
            var values = new Dictionary <string, object>
            {
                { "score", currentLevel.Score },
                { "Coins", currentLevel.Coins },
                { "time", difference },
                { "level", currentLevel.Number }
            };
            Analytics.CustomEvent("GameOver", values);
#endif

            // co routine to periodic updates of display (don't need to do this every frame)
            if (!Mathf.Approximately(PeriodicUpdateDelay, 0))
            {
                StartCoroutine(PeriodicUpdate());
            }
        }
コード例 #21
0
        public void UpdateNeededCoins()
        {
            int minimumCoins = GameManager.Instance.Levels.ExtraValueNeededToUnlock(GameManager.Instance.Player.Coins);

            if (minimumCoins == 0)
            {
                UIHelper.SetTextOnChildGameObject(DialogInstance.gameObject, "TargetCoins", LocaliseText.Format(LocalisationBase + ".TargetCoinsGot", minimumCoins), true);
            }
            else
            {
                UIHelper.SetTextOnChildGameObject(DialogInstance.gameObject, "TargetCoins", LocaliseText.Format(LocalisationBase + ".TargetCoins", minimumCoins), true);
            }
        }
コード例 #22
0
    public virtual void Show(bool isWon, float time, int points = 0, ChallengeManager.GameStates gameState = ChallengeManager.GameStates.Leaved, ChallengeManager.GameStateMessage message = null)
    {
        _multiplayer = GameSparksManager.Instance.GetGameMode() == GameMode.Multi;

        _buttonPurchaseObject = GameObject.Find("PurchaseButton");

        if (_buttonPurchaseObject != null && !_multiplayer)
        {
            _inviteOriginalParent   = _buttonPurchaseObject.transform.parent.gameObject;
            _inviteOriginalPosition = _buttonPurchaseObject.transform.position;

            _inviteButtonObject = gameObject;
            DialogInstance _inviteDialogInstance = gameObject.GetComponent <DialogInstance>();

            GameObjectUtils.MoveObjectToAtIndex(_buttonPurchaseObject, _inviteDialogInstance.Target, 1);
        }

        pointsView      = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "PointsView", true);
        shareView       = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "SharingView", true);
        multiplayerView = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "MultiplayerPointsView", true);

        if (_multiplayer)
        {
            pointsView.SetActive(false);
            multiplayerView.SetActive(true);

            if (gameState == ChallengeManager.GameStates.Won || gameState == ChallengeManager.GameStates.Draw)
            {
                ButtonUtils.PlayWinSound();
            }
            else
            {
                ButtonUtils.PlayLoseSound();
            }
        }
        else
        {
            pointsView.SetActive(true);
            multiplayerView.SetActive(false);

            ButtonUtils.PlayWinSound();
        }

        var currentLevel = GameManager.Instance.Levels.Selected;

        int  coins           = 0;
        bool firstTimePlayed = _multiplayer ? true : currentLevel.ProgressBest < 0.9f;

        LevelManager.Instance.EndLevel();

        this.Coins = coins;

        if (firstTimePlayed && !_multiplayer)
        {
            currentLevel.AddPoints(points);
            currentLevel.ProgressBest = 1.0f;
        }

        if (_multiplayer && gameState == ChallengeManager.GameStates.Lost)
        {
            points *= -1;
        }

        GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Dialog", true), false);

        Assert.IsTrue(LevelManager.IsActive, "Ensure that you have a LevelManager component attached to your scene.");

        if (coins > 0 && !_multiplayer)
        { // add coins for this level
            currentLevel.AddCoins(coins);
            GameManager.Instance.Player.AddCoins(coins);
        }

        GameManager.Instance.Player.AddPoints(points);

        // update the player coins if necessary
        if (((UpdatePlayerCoins == CopyType.Always) || (UpdatePlayerCoins == CopyType.OnWin && isWon)) && !_multiplayer)
        {
            GameManager.Instance.Player.AddCoins(currentLevel.Coins);
        }

        // show won / lost game objects as appropriate
        GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Lost", true), !isWon);

        // see if the world or game is won and also if we should unlock the next world / level
        GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "GameWon", true), false);
        GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "WorldWon", true), false);
        GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "LevelWon", true), false);
        GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Won", true), false);

        GameObject levelName = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "LevelName", true);

        if (_multiplayer)
        {
            levelName.GetComponent <Text>().text = LocaliseText.Get("LevelCompleted.Match");
        }
        else
        {
            levelName.GetComponent <Text>().text = LocaliseText.Format("LevelCompleted.LevelName", currentLevel.Number);
        }

        GameObjectHelper.SafeSetActive(levelName, true);

        if (!_multiplayer && isWon)
        {
            GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Won", true), true);

            // process and update game state - do this last so we can check some bits above.
            GameHelper.ProcessCurrentLevelComplete();
        }

        // set some text based upon the result
        UIHelper.SetTextOnChildGameObject(DialogInstance.gameObject, "AchievementText", LocaliseText.Format(LocalisationBase + ".Achievement", currentLevel.Score, currentLevel.Name));

        // setup stars
        var starsGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Stars", true);

        GameObjectHelper.SafeSetActive(starsGameObject, ShowStars);
        if (ShowStars && !_multiplayer)
        {
            Assert.IsNotNull(starsGameObject, "GameOver->ShowStars is enabled, but could not find a 'Stars' gameobject. Disable the option or fix the structure.");
            starsGameObject.SetActive(ShowStars);
            var newStarsWon = GetNewStarsWon();
            currentLevel.StarsWon |= newStarsWon;
            var star1WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star1", true);
            var star2WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star2", true);
            var star3WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star3", true);
            StarWon(currentLevel.StarsWon, newStarsWon, star1WonGameObject, 1, coins);
            StarWon(currentLevel.StarsWon, newStarsWon, star2WonGameObject, 2, coins);
            StarWon(currentLevel.StarsWon, newStarsWon, star3WonGameObject, 4, coins);
            GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(starsGameObject, "StarWon", true), newStarsWon != 0);
        }

        // set time

        var timeGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Time", true);

        GameObjectHelper.SafeSetActive(timeGameObject, ShowTime);
        if (!_multiplayer && ShowTime)
        {
            TimeSpan timeSpan = TimeSpan.FromSeconds(time);

            string timeText = LocaliseText.Format("LevelCompleted.Time", timeSpan.Minutes, timeSpan.Seconds);

            Assert.IsNotNull(timeGameObject, "GameOver->ShowTime is enabled, but could not find a 'Time' gameobject. Disable the option or fix the structure.");

            UIHelper.SetTextOnChildGameObject(timeGameObject, "TimeResult", timeText, true);
        }

        if (!_multiplayer && currentLevel.TimeBest < 0.05)
        { // save only first time played
            currentLevel.TimeBest = time;
        }

        // set coins
        if (ShowCoins && coins > 0)
        {
            var coinsGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Coins", true);
            GameObjectHelper.SafeSetActive(coinsGameObject, ShowCoins);

            Assert.IsNotNull(coinsGameObject, "GameOver->ShowCoins is enabled, but could not find a 'Coins' gameobject. Disable the option or fix the structure.");
            UIHelper.SetTextOnChildGameObject(coinsGameObject, "CoinsResult", coins.ToString(), true);
        }

        if (!_multiplayer)
        {
            if (firstTimePlayed)
            {
                GameObject DoubleButton = GameObjectHelper.GetChildNamedGameObject(pointsView, "DoubleButton", true);
                DoubleButton.SetActive(Reachability.Instance.IsReachable());
            }
            else
            {
                GameObject ShareButton = GameObjectHelper.GetChildNamedGameObject(pointsView, "ShareButton", true);
                ShareButton.SetActive(true);
            }
        }

        // set score
        var scoreGameObject = GameObjectHelper.GetChildNamedGameObject(_multiplayer ? multiplayerView : pointsView, "Score", true);

        GameObjectHelper.SafeSetActive(scoreGameObject, ShowScore);

        if (!firstTimePlayed)
        {
            GameObjectHelper.SafeSetActive(scoreGameObject, false);
        }

        if (!_multiplayer && firstTimePlayed)
        {
            GameObject adsObject  = GameObjectHelper.GetChildNamedGameObject(pointsView, "Ads", true);
            Text       unlockText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(pointsView, "UnlockText", true);

            if (LevelController.Instance.LastLevelInPack(currentLevel))
            {
                Pack pack     = LevelController.Instance.PackForLevel(currentLevel);
                Pack nextPack = LevelController.Packs().GetItem(pack.Number + 1);

                if (nextPack)
                {
                    nextPack.LoadData();

                    adsObject.SetActive(false);
                    unlockText.gameObject.SetActive(true);

                    unlockText.text = LocaliseText.Format("LevelCompleted.LastLevelInPack", LocaliseText.Get(nextPack.JsonData.GetString("name")));
                }
            }

            if (LevelController.Instance.LastLevelInRank(currentLevel))
            {
                Rank rank     = LevelController.Instance.RankForLevel(currentLevel);
                Rank nextRank = LevelController.Ranks().GetItem(rank.Number + 1);

                if (nextRank)
                {
                    nextRank.LoadData();

                    adsObject.SetActive(false);
                    unlockText.gameObject.SetActive(true);

                    unlockText.text = LocaliseText.Format("LevelCompleted.LastLevelInRank", LocaliseText.Get(nextRank.JsonData.GetString("name")));
                }
            }
        }

        if (ShowScore)
        {
            Assert.IsNotNull(scoreGameObject, "GameOver->ShowScore is enabled, but could not find a 'Score' gameobject. Disable the option or fix the structure.");

            UIHelper.SetTextOnChildGameObject(scoreGameObject, "ScoreResult", LocaliseText.Format("LevelCompleted.Score", "0"), true);

            AnimateScoreText(points);
        }

        if (_multiplayer)
        {
            var resultStateObject = GameObjectHelper.GetChildNamedGameObject(multiplayerView, "ResultState", true);
            GameObjectHelper.SafeSetActive(resultStateObject, true);

            string text = "";

            switch (gameState)
            {
            case ChallengeManager.GameStates.Won:
                text = LocaliseText.Get("Game.YouWon");
                break;

            case ChallengeManager.GameStates.Lost:
                text = LocaliseText.Get("Game.YouLost");
                break;

            case ChallengeManager.GameStates.Draw:
                text = LocaliseText.Get("Game.ItsDrawn");
                break;
            }

            resultStateObject.GetComponent <Text>().text = text;
        }

        if (!_multiplayer)
        {
            UpdateNeededCoins();

            LevelController.Instance.PackProgressCompleted(currentLevel);
            UnlockNextLevel();

            //

            int StartupLevels = ((CustomGameManager)CustomGameManager.Instance).StartupLevels;

            if (StartupLevels == currentLevel.Number)
            {
                GameObject adsObject = GameObjectHelper.GetChildNamedGameObject(pointsView, "Ads", true);

                Text adsText = adsObject.GetComponent <Text>();

                adsText.text                 = LocaliseText.Get("Text.PlayedAllLevels");
                adsText.fontSize             = 39;
                adsText.resizeTextForBestFit = false;

                if (!Debug.isDebugBuild)
                {
                    Flurry.Flurry.Instance.LogEvent("Game_LastLevel", new Dictionary <string, string>()
                    {
                        { "Level", currentLevel.Number.ToString() }
                    });
                    Fabric.Answers.Answers.LogCustom("Game_LastLevel", new Dictionary <string, object>()
                    {
                        { "Level", currentLevel.Number.ToString() }
                    });
                }
            }
        }

        if (!_multiplayer && firstTimePlayed)
        {
            JSONObject pointsData = new JSONObject();
            pointsData.Add("Level", currentLevel.Number.ToString());
            pointsData.Add("Language", LocaliseText.Language);
            pointsData.Add("RealLanguage", LanguageUtils.RealLanguage(LocaliseText.Language));
            pointsData.Add("Time", time.ToString());
            pointsData.Add("UsedHints", GameController.Instance.usedHintsCount);
            pointsData.Add("UserCoins", GameManager.Instance.Player.Coins);
            pointsData.Add("Words", JsonUtils.ListToArray(GameController.Instance.GetFoundWords()));
            pointsData.Add("Date", DateTimeUtils.DateTimeToISO8601(UnbiasedTime.Instance.UTCNow()));

            GameSparksManager.Instance.SendPoints(points, "LevelComplete", pointsData);
        }

        //

        GameObject completeTextGameObject = GameObjectHelper.GetChildNamedGameObject(_multiplayer ? multiplayerView : pointsView, "CompleteText", true);

        // save game state.
        GameManager.Instance.Player.UpdatePlayerPrefs();

        if (!_multiplayer)
        {
            currentLevel.UpdatePlayerPrefs();
        }

        PreferencesFactory.Save();

        GameObject NameContainer = GameObjectHelper.GetChildNamedGameObject(DialogInstance.Content, "NameContainer", true);
        GameObject LevelName     = GameObjectHelper.GetChildNamedGameObject(DialogInstance.Content, "LevelName", true);
        GameObject Results       = GameObjectHelper.GetChildNamedGameObject(DialogInstance.Content, "Results", true);
        GameObject Buttons       = GameObjectHelper.GetChildNamedGameObject(DialogInstance.Content, "Buttons", true);
        GameObject CloseButton   = GameObjectHelper.GetChildNamedGameObject(DialogInstance.Content, "Close", true);

        GameObject parent = DialogInstance.Content.transform.parent.gameObject;

        Vector3 currentScale = parent.transform.localScale;

        parent.transform.DOScale(new Vector3(0, 0, 0), 0.0f);
        NameContainer.transform.localScale          = new Vector3(0, 0, 0);
        LevelName.transform.localScale              = new Vector3(0, 0, 0);
        Results.transform.localScale                = new Vector3(0, 0, 0);
        Buttons.transform.localScale                = new Vector3(0, 0, 0);
        completeTextGameObject.transform.localScale = new Vector3(0, 0, 0);

        CloseButton.GetComponent <Image>().color = new Color(1, 1, 1, 0);

        //show dialog
        DialogInstance.Show();

        parent.transform.DOScale(currentScale, 1.0f).SetEase(Ease.OutElastic);
        NameContainer.transform.DOScale(new Vector3(1, 1, 1), 1.5f).SetDelay(0.1f).SetEase(Ease.OutElastic);
        LevelName.transform.DOScale(new Vector3(1, 1, 1), 0.8f).SetDelay(0.2f).SetEase(Ease.OutElastic);
        Results.transform.DOScale(new Vector3(1, 1, 1), 0.8f).SetDelay(0.2f).SetEase(Ease.OutElastic);
        Buttons.transform.DOScale(new Vector3(1, 1, 1), 0.8f).SetDelay(0.2f).SetEase(Ease.OutElastic);
        completeTextGameObject.transform.DOScale(new Vector3(1, 1, 1), 0.8f).SetDelay(0.35f).SetEase(Ease.OutElastic);

        CloseButton.GetComponent <Image>().DOFade(1, 0.5f).SetDelay(0.7f);

        GameObject Light = GameObjectHelper.GetChildNamedGameObject(completeTextGameObject, "Light", true);

        Light.transform.DOLocalRotate(new Vector3(0, 0, -360), 10, RotateMode.LocalAxisAdd).SetLoops(-1).SetEase(Ease.Linear);

        //TODO bug - as we increase TimesPlayedForRatingPrompt on both game start (GameManager) and level finish we can miss this comparison.
        if (GameManager.Instance.TimesPlayedForRatingPrompt == TimesPlayedBeforeRatingPrompt)
        {
            GameFeedback gameFeedback = new GameFeedback();
            gameFeedback.GameFeedbackAssumeTheyLikeOptional();
        }

#if UNITY_ANALYTICS
        // record some analytics on the level played
        if (!_multiplayer)
        {
            var values = new Dictionary <string, object>
            {
                { "score", currentLevel.Score },
                { "Coins", coins },
                { "time", time },
                { "level", currentLevel.Number }
            };
            Analytics.CustomEvent("LevelCompleted", values);
        }
#endif

#if UNITY_EDITOR
        if (!_multiplayer)
        {
            GameSparksManager.Instance.SyncProgressCoroutine();
        }
#endif

#if !UNITY_EDITOR
        AdColonyManager.Instance.RequestAd();
        AdColonyManager.Instance.RequestAd(Constants.AdColonyDoubleCoins);

        LoadInterstitialAd();
        LoadAdmobRewarderVideo();
#endif

        // co routine to periodic updates of display (don't need to do this every frame)
        if (!Mathf.Approximately(PeriodicUpdateDelay, 0))
        {
            StartCoroutine(PeriodicUpdate());
        }
    }
コード例 #23
0
    string BonusText()
    {
        string text = LocaliseText.Format("FreePrize.Text1", this.PrizeItems);

        return(text);
    }
コード例 #24
0
    /// <summary>
    /// Show a free prize dialog that gives the user coins. We default to the standard General Message window, adding any additional
    /// content as setup in the FreePrizeManager configuration.
    /// </summary>
    public DialogInstance ShowFreePrizeDialog(Action <DialogInstance> doneCallback = null)
    {
        // only allow the free prize dialog to be shown once.
        if (IsShowingFreePrizeDialog)
        {
            return(null);
        }

        IsShowingFreePrizeDialog = true;
        _prizeIsProcessed        = false;
        dialogInstance           = DialogManager.Instance.Create(ContentPrefab, null, null, null,
                                                                 runtimeAnimatorController: ContentAnimatorController);

        Sprite sprite = null;
        string text   = BonusText();

        if (prizeIsCoins && this.PrizeItems > 0)
        {
            sprite = Resources.Load <Sprite>("Images/coins");
        }

        string   DateLastFreePrizeTakeString = PreferencesFactory.GetString(Constants.KeyDateLastFreePrizeTake);
        DateTime DateLastFreePrizeTake       = UnbiasedTime.Instance.Now();

        if (!DateLastFreePrizeTakeString.Equals(""))
        {
            DateLastFreePrizeTake = DateTime.Parse(DateLastFreePrizeTakeString);
        }

        int DaysInRow = PreferencesFactory.GetInt(Constants.KeyFreePrizeTakeDaysInRow, 1);

        if (DateLastFreePrizeTake.AddDays(1).Date == UnbiasedTime.Instance.Now().Date)
        {
            DaysInRow += 1;
            PreferencesFactory.SetInt(Constants.KeyFreePrizeTakeDaysInRow, DaysInRow);
        }
        else
        { // reset
            DaysInRow = 1;
            PreferencesFactory.SetInt(Constants.KeyFreePrizeTakeDaysInRow, DaysInRow);
        }

        GameObject Days = GameObjectHelper.GetChildNamedGameObject(dialogInstance.gameObject, "Days", true);

        for (int i = 0; i < Constants.DailyBonusItems.Length; i++)
        {
            int prizeValue = Constants.DailyBonusItems[i];

            string     dayText = string.Format("Day{0}", (i + 1));
            GameObject day     = GameObjectHelper.GetChildNamedGameObject(Days, dayText, true);

            if (!day)
            {
                continue;
            }

            Text t = GameObjectHelper.GetChildNamedGameObject(day, "Text", true).GetComponent <Text>();
            t.text = prizeValue.ToString();

            if (DaysInRow - 1 > i)
            {
                GameObject image = GameObjectHelper.GetChildNamedGameObject(day, "Image", true);
                GameObjectHelper.SafeSetActive(image, true);
            }

            //			if ( DaysInRow-1 == i) {
            //				GameObject today = GameObjectHelper.GetChildNamedGameObject(day, "Today", true);
            //				GameObjectHelper.SafeSetActive (today, true);
            //
            //				GameObject dayNumber = GameObjectHelper.GetChildNamedGameObject(day, "DayNumber", true);
            //				GameObjectHelper.SafeSetActive (dayNumber, false);
            //			}

            if (DaysInRow == (i + 1))
            { // add daily bonus
                this.PrizeItems += prizeValue;

                GameObject claimButton = GameObjectHelper.GetChildNamedGameObject(dialogInstance.Content, "ClaimButton", true);

                Text claimText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(claimButton, "Text", true);

                if (prizeIsPoints)
                {
                    claimText.text = LocaliseText.Format("FreePrize.ClaimPoints", this.PrizeItems);
                }

                if (prizeIsCoins)
                {
                    claimText.text = LocaliseText.Format("FreePrize.ClaimButton", this.PrizeItems);
                }
            }
        }

        dialogInstance.Show(title: LocaliseText.Get("FreePrize.Title"), text: text, text2Key: "FreePrize.Text2",
                            doneCallback: (DialogInstance _dialogInstance) => {
            if (doneCallback != null)
            {
                doneCallback(_dialogInstance);
            }

            ShowFreePrizeDone(_dialogInstance);
        },
                            dialogButtons:
                            ContentShowsButtons
            ? DialogInstance.DialogButtonsType.Custom
            : DialogInstance.DialogButtonsType.Ok);

        GameObject ImageCoins = GameObjectHelper.GetChildNamedGameObject(dialogInstance.gameObject, "ph_Image", true);

        ImageCoins.SetActive(false);

        if (this.PrizeItems > 0 && prizeIsCoins && sprite != null)
        {
            ImageCoins.SetActive(true);
            ImageCoins.GetComponent <Image>().sprite = sprite;
        }

        StartNewCountdown();

        if (!Debug.isDebugBuild)
        {
            Fabric.Answers.Answers.LogContentView("FreePrize", "Dialog");
        }
#if !UNITY_EDITOR
        AdColonyManager.Instance.RequestAd(Constants.AdColonyDoubleDailyBonus);
        LoadAdmobRewarderVideo();
#endif

        return(dialogInstance);
    }
コード例 #25
0
    public void Refresh()
    {
        Pack pack = ((CustomGameManager)CustomGameManager.Instance).Packs.Selected;

        ItemsRange range = LevelController.PackLevelsRange(pack);

        for (int i = range.From; i < range.To + 1; i++)
        {
            Level level = GameManager.Instance.Levels.GetItem(i);
            level.LoadData();

            GameObject newObject = Instantiate(Prefab);
            newObject.transform.SetParent(transform, false);

            CustomLevelButton levelButton = newObject.GetComponent <CustomLevelButton>();
            levelButton.Context.Number = i;

            if (level.IsUnlocked)
            {
                CanvasGroup canvasGroup = GameObjectHelper.GetChildComponentOnNamedGameObject <CanvasGroup> (newObject, "PlayButton", true);
                canvasGroup.alpha = 1f;
            }

            Level nextLevel = GameManager.Instance.Levels.GetItem(i + 1);

            if (nextLevel != null && nextLevel.IsUnlocked == false && level.IsUnlocked)
            {
                Animator anim = GameObjectHelper.GetChildComponentOnNamedGameObject <Animator>(newObject, "PlayButton", true);
                anim.enabled = true;
            }

            if (level.ProgressBest > 0.9f)
            {
                Text statusText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(newObject, "Status", true);
                statusText.text = LocaliseText.Get("Text.Done");
            }

            Text text = GameObjectHelper.GetChildComponentOnNamedGameObject <Text> (newObject, "Name", true);
            text.text = LocaliseText.Format("Text.LevelNumber", i);

            GameObject previewObject = GameObjectHelper.GetChildNamedGameObject(newObject, "Preview", true);
            GameObject wordsObject   = GameObjectHelper.GetChildNamedGameObject(previewObject, "Words", true);

            string preview    = level.JsonData.GetString("preview");
            char[] characters = preview.ToCharArray();

            int index = 0;
            int angle = 360 / characters.Length;

            foreach (char _char in characters)
            {
                GameObject _charObject = Instantiate(_charPrefab, wordsObject.transform);

                Vector3 pos = Vector3Utils.RandomCircle(wordsObject.transform.position, 0.2f, angle, index);
                _charObject.transform.position   = pos;
                _charObject.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);

                GameObject _text = GameObjectHelper.GetChildNamedGameObject(_charObject, "Text", true);
                _text.GetComponent <Text> ().text = _char.ToString().ToUpper();

                index++;
            }

            buttons.Add(newObject);
        }
    }
コード例 #26
0
    private void UpdateContent()
    {
        Pack pack = LevelController.Packs().GetItem(Number);

        pack.LoadData();

        if (pack.IsUnlocked)
        {
            if (_canvasGroup == null)
            {
                _canvasGroup = GameObjectHelper.GetChildComponentOnNamedGameObject <CanvasGroup>(gameObject, "PlayButton", true);
            }

            _canvasGroup.alpha = 1f;
        }

        if (_nameText == null)
        {
            _nameText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(gameObject, "Name", true);
        }

        _nameText.text = LocaliseText.Get(pack.JsonData.GetString("name"));

        if (_statusText == null)
        {
            _statusText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(gameObject, "Status", true);
        }

        _statusText.text = LocaliseText.Format("Text.NumberLetters", pack.JsonData.GetNumber("letters"));

        if (LocaliseText.Language == "Russian")
        {
            _statusText.gameObject.SetActive(false);
        }

        if (_icon == null)
        {
            _icon = GameObjectHelper.GetChildNamedGameObject(gameObject, "Icon", true);
        }

        if (pack.Progress > 0.9f)
        {
            _icon.SetActive(true);
        }

        int points = LevelController.Instance.PointsForPack(pack);

        if (points > 0)
        {
            if (_pointsObject == null)
            {
                _pointsObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "Points", true);
            }

            _pointsObject.SetActive(true);

            if (_pointsNumber == null)
            {
                _pointsNumber = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(_pointsObject, "PointsNumber", true);
            }

            _pointsNumber.text = points.ToString();
        }
    }
コード例 #27
0
 /// <summary>
 /// Get the actual value that this LocalisableText represents, either a physical value or the localised string formatting in passed parameters
 /// </summary>
 public string FormatValue(params object[] parameters)
 {
     return(IsLocalised ? LocaliseText.Format(Data, parameters) : string.Format(Data, parameters));
 }
コード例 #28
0
    // {"noAds":true}
    // {"unlockedLevels":true}
    void PopulateData()
    {
        string text   = null;
        Sprite sprite = null;

        if (_awards.ContainsKey("noAds"))
        {
            text = LocaliseText.Get("Awards.NoAds");
        }

        if (_awards.ContainsKey("unlockedLevels"))
        {
            text = LocaliseText.Get("Awards.UnlockedLevels");
        }

        if (_awards.ContainsKey("noAds") && _awards.ContainsKey("unlockedLevels"))
        {
            text = LocaliseText.Get("Awards.NoAdsANDUnlockedLevels");
        }

        if (_awards.ContainsKey("coins"))
        {
            text   = LocaliseText.Format("Awards.Coins", (int)_awards.GetNumber("coins"));
            sprite = Resources.Load <Sprite>("Images/coin-icon");
        }

        if (_awards.ContainsKey("unlockLevel"))
        {
            text = string.Format("Unlock level with number {0}", (int)_awards.GetNumber("unlockLevel"));
        }

        if (_awards.ContainsKey("unlockPack"))
        {
            text = "Unlock pack";
        }

        if (_awards.ContainsKey("unlockAll"))
        {
            text = "Unlock entire game";
        }

        GameObject GO = gameObject.GetComponent <DialogInstance> ().Content;
        GameObject childGameObject = null;

        if (text != null)
        {
            UIHelper.SetTextOnChildGameObject(GO, "ph_Text", text, true);
        }

        childGameObject = GameObjectHelper.GetChildNamedGameObject(GO, "ph_Text", true);
        if (childGameObject != null)
        {
            childGameObject.SetActive(text != null);
        }

        if (sprite != null)
        {
            UIHelper.SetSpriteOnChildGameObject(GO, "ph_Image", sprite, true);
        }

        childGameObject = GameObjectHelper.GetChildNamedGameObject(GO, "ph_Image", true);
        if (childGameObject != null)
        {
            childGameObject.SetActive(sprite != null);
        }
    }