Beispiel #1
0
    public void Init(DRHeroShop drHeroShop, Action <UIHeroShop_PanelHero> onSelectCallback)
    {
        this.drHeroShop = drHeroShop;

        this.gameObject.GetOrAddComponent <Button>();

        FocusButton focusButton = this.gameObject.GetComponent <FocusButton>();

        focusButton.OnSelectListener += (sender, button) => {
            onSelectCallback(this);
        };

        textName.text = drHeroShop.Name;
        textDes.text  = drHeroShop.Des;

        string assetName = AssetUtility.GetUISpriteAsset(drHeroShop.AssetName);

        GameEntry.Resource.LoadAsset(assetName, new LoadAssetCallbacks(
                                         (_assetName, _asset, _duration, _userData) => {
            imgHero.sprite = ((GameObject)_asset).GetComponent <SpriteRenderer>().sprite;
        },
                                         (string _assetName, LoadResourceStatus status, string errorMessage, object userData) => {
            Log.Warning("error:" + errorMessage);
        }
                                         ));
    }
    /// <summary>
    /// 购买英雄
    /// </summary>
    /// <param name="drHeroShop"></param>
    public bool BuyHero(DRHeroShop drHeroShop)
    {
        int gold = PlayerData.Gold;

        if (gold <= drHeroShop.Price)
        {
            GameEntry.UI.OpenDialog(new DialogParams()
            {
                Title   = GameEntry.Localization.GetString("Alert.OperateFail"),
                Message = GameEntry.Localization.GetString("Message.GoldNotEnough"),
            });

            return(false);
        }
        else
        {
            PlayerData.Gold = gold - drHeroShop.Price;
            PlayerData.AddHero(drHeroShop.Id);

            GameEntry.UI.OpenDialog(new DialogParams()
            {
                Title   = GameEntry.Localization.GetString("Alert.OperateSuccess"),
                Message = GameEntry.Localization.GetString("Message.BuySuccess"),
            });

            return(true);
        }
    }
    /// <summary>
    /// 点击英雄面板
    /// </summary>
    public void OnHeroPanelClick(UIHeroShop_PanelHero heroPanel)
    {
        currentSelectHeroPanel = heroPanel;
        DRHeroShop drHeroShop = heroPanel.GetHeroShop();

        // 显示/隐藏购买按钮
        if (PlayerData.HasHero(drHeroShop.Id))
        {
            buttonBuy.SetActive(false);
            string boughtText = GameEntry.Localization.GetString("HeroShop.Bought");

            // 显示/隐藏出战按钮
            if (PlayerData.CurrentFightHeroID != drHeroShop.Id)
            {
                buttonFight.SetActive(true);
                textPrice.text = $"{boughtText}";
            }
            else
            {
                buttonFight.SetActive(false);

                string fightText = GameEntry.Localization.GetString("HeroShop.Fight");
                textPrice.text = $"{boughtText},{fightText}";
            }
        }
        else
        {
            buttonBuy.SetActive(true);
            buttonFight.SetActive(false);
            string goldText = GameEntry.Localization.GetString("Message.Gold");
            textPrice.text = $"{drHeroShop.Price}{goldText}";
        }
    }
 /// <summary>
 /// 设置出战英雄
 /// </summary>
 /// <param name="drHeroShop"></param>
 public void SetFightHero(DRHeroShop drHeroShop)
 {
     PlayerData.SetFightHero(drHeroShop.Id);
 }