123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class BuyItem : MonoBehaviour
- {
- public Sprite[] bgSprites;
- public Image bg;
- public Text titleTxt;
- public Price price;
- public GameObject icon;
- public Image iconImage;
- public Animator iconAnim;
- public Text numTxt;
- public Button btn;
- public GameObject craftContainer;
- void Awake()
- {
- btn.onClick.AddListener(OnSelect);
- }
- void OnDestroy()
- {
- btn.onClick.RemoveAllListeners();
- }
- private BuyItemData data;
- public void Init(BuyItemData data)
- {
- this.data = data;
- titleTxt.text = data.GetName();
- Sprite iconSprite = data.GetIcon();
- if(iconSprite != null)
- {
- iconImage.enabled = true;
- iconImage.sprite = iconSprite;
- }
- else
- {
- iconImage.enabled = false;
- }
- if(data.GetAmount() > 1)
- {
- numTxt.text = NumberUtil.AddThousandSplit(data.GetAmount());
- numTxt.enabled = true;
- if(data.GetItemType() == BuyUtil.ItemType.Coin)
- iconAnim.Play("BuyItemIconCoin");
- else if(data.GetItemType() == BuyUtil.ItemType.Diam)
- iconAnim.Play("BuyItemIconDiam");
- }
- else
- {
- numTxt.enabled = false;
- }
- if(data.GetModel() == 0)
- {
- craftContainer.SetActive(false);
- icon.SetActive(true);
- }
- else
- {
- craftContainer.SetActive(true);
- Craft craft = null;
- if(craftContainer.transform.childCount == 0)
- {
- craft = CraftFactory.CreateCraft(data.GetModel());
- PopUpManager.AddToMainCanvas(craft.gameObject, craftContainer.transform);
- craft.transform.localEulerAngles = new Vector3(0, 0, 0);
- craft.transform.localPosition = Vector3.zero;
- }
- else
- {
- craft = craftContainer.transform.GetChild(0).GetComponent<Craft>();
- }
- if(data.GetHalo() != 0)
- {
- craft.SetHalo(data.GetHalo());
- }
- icon.SetActive(false);
- }
- UpdatePrice();
- }
- public void UpdatePrice()
- {
- if(data.GetState() == BuyUtil.ItemState.Sell)
- bg.sprite = bgSprites[0];
- else if(data.GetState() == BuyUtil.ItemState.Bought)
- bg.sprite = bgSprites[1];
- else if(data.GetState() == BuyUtil.ItemState.Equiped)
- bg.sprite = bgSprites[2];
- price.SetPrice(data.GetCurrency(), data.GetPrice(), data.GetState());
- }
- private void OnSelect()
- {
- DealBuyItem(data);
- }
- public static void DealBuyItem(BuyItemData data)
- {
- if(data.GetState() == BuyUtil.ItemState.Bought)
- {
- if(data.GetItemType() == BuyUtil.ItemType.Halo)
- HaloManager.GetInstance().Equip(StringUtil.ToInt(data.GetItemId()), 1);
- else if(data.GetItemType() == BuyUtil.ItemType.Skin)
- SkinManager.GetInstance().Equip(StringUtil.ToInt(data.GetItemId()), data.GetCraftId(), data.GetCraftId());
- }
- else if(data.GetState() == BuyUtil.ItemState.Equiped)
- {
- if(data.GetItemType() == BuyUtil.ItemType.Halo)
- HaloManager.GetInstance().Equip(StringUtil.ToInt(data.GetItemId()), 0);
- else if(data.GetItemType() == BuyUtil.ItemType.Skin)
- SkinManager.GetInstance().Equip(StringUtil.ToInt(data.GetItemId()), 0, data.GetCraftId());
- }
- else if(data.GetState() == BuyUtil.ItemState.Sell)
- {
- if(data.GetItemType() == BuyUtil.ItemType.Diam || data.GetItemType() == BuyUtil.ItemType.VIP)
- {
- }
- else
- {
- BuyConfirmPanel panel = BuyConfirmPanel.Show(data);
- string info = "";
- if(data.GetItemType() == BuyUtil.ItemType.Coin)
- {
- info = Language.GetStr("BuyCoin", "buyInfo");
- info = info.Replace("%NUM%", data.GetAmount().ToString());
- }
- else
- {
- info = Language.GetStr("Shop", "buyInfo");
- info = info.Replace("%NAME%", data.GetName());
- }
- panel.info.text = info;
- }
- }
- }
-
- }
|