12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class PowerIcon : MonoBehaviour
- {
- public bool isCrystalPowerIcon;
- public Image darkImage;
- public Image lightImage;
- public Image activatingImage;
- public Text priceTxt;
- private BattleController battleController;
- private Power power;
- private bool activating;
- public Sprite defaultIcon;
- public void init(BattleController battleController)
- {
- this.battleController = battleController;
- SetPower(power);
- }
- public void Show()
- {
- transform.localScale = new Vector3(1f, 1f, 1f);
- }
- public void Hide()
- {
- transform.localScale = Vector3.zero;
- }
- public void SetPower(Power power)
- {
- this.power = power;
- if (power != null)
- {
- if(power.GetIcon() != null)
- {
- lightImage.sprite = darkImage.sprite = power.GetIcon();
- priceTxt.text = power.crystalNeed > 0 ? power.crystalNeed.ToString() : "";
- }
- activating = power.isActivating;
- }
- else
- {
- if(!isCrystalPowerIcon && defaultIcon != null)
- {
- lightImage.sprite = darkImage.sprite = defaultIcon;
- }
- activating = false;
- }
- activatingImage.enabled = activating;
- transform.localScale = power != null ? Vector3.one : Vector3.zero;
- }
-
- public void OnClick()
- {
- if(battleController.GetCtrlCraft() != null && power != null)
- {
- if(battleController.AttempUsePower(power.GetId()))
- {
- DGAnalytics.CustomEvent ("Pow"+power.GetId());
- }
- }
- }
- // Update is called once per frame
- void FixedUpdate ()
- {
- if(power != null)
- {
- if(power.isActivating != activating)
- {
- activating = power.isActivating;
- activatingImage.enabled = activating;
- }
- if(!power.IsCoolDown())
- {
- lightImage.fillAmount = power.GetCDTime()/power.GetCDDuration();
- }
- else if(lightImage.fillAmount < 1f)
- {
- lightImage.fillAmount = 1f;
- }
- }
- }
-
- }
|