| | |
| | | using UnityEngine.UI; |
| | | using System.Collections; |
| | | using TowerDefense.Level; |
| | | using System.Collections.Generic; |
| | | using UnityEngine.UI; |
| | | using UnityEngine; |
| | | using TowerDefense.Level; |
| | | |
| | | /** |
| | | * 无尽模式buff预览 |
| | |
| | | { |
| | | public class EndlessBuffPreview : MonoBehaviour |
| | | { |
| | | /// <summary> |
| | | /// buff预览界面 |
| | | /// </summary> |
| | | public GameObject Panel; |
| | | |
| | | private bool isShow; |
| | | public GameObject Content; |
| | | |
| | | private string iconPath = "UI/Endless/BuffPreviewIcon/buff_"; |
| | | /// <summary> |
| | | /// buff预览界面返回按钮 |
| | | /// </summary> |
| | | public Button BackBtn; |
| | | |
| | | public List<GameObject> ItemList; |
| | | /// <summary> |
| | | /// 未获得buff提示文字 |
| | | /// </summary> |
| | | public Text NoBuffText; |
| | | |
| | | public List<Image> IconList; |
| | | |
| | | public List<Text> TextList; |
| | | |
| | | private string[] elementNameArr = { "火", "水", "木" }; |
| | | private float preTimeScale; |
| | | |
| | | // Start is called before the first frame update |
| | | private void Start() |
| | | { |
| | | GetComponent<Button>().onClick.AddListener(OnClick); |
| | | BackBtn.onClick.AddListener(HideBuffPreview); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.EndlessBuffRefresh, Refresh); |
| | | ShowPanel(); |
| | | Panel.SetActive(false); |
| | | } |
| | | |
| | | public void OnClick() |
| | | { |
| | | ShowPanel(); |
| | | } |
| | | if (GameConfig.IsNewbie) return; |
| | | |
| | | private void ShowPanel() |
| | | { |
| | | if (isShow) |
| | | Refresh(); |
| | | Panel.SetActive(isShow); |
| | | isShow = !isShow; |
| | | ShowBuffPreview(); |
| | | } |
| | | |
| | | private void Refresh() |
| | | { |
| | | if (!Panel.activeInHierarchy) return; |
| | | |
| | | ClearContent(); |
| | | |
| | | List<EndlessBuffConfig> buffList = EndlessBuffManager.instance.BuffList; |
| | | // 0.火 1.水 2.木 |
| | | int[] addArr = { 0, 0, 0 }; |
| | | |
| | | if (buffList.Count == 0) |
| | | { |
| | | NoBuffText.gameObject.SetActive(true); |
| | | return; |
| | | } |
| | | |
| | | NoBuffText.gameObject.SetActive(false); |
| | | |
| | | for (int i = 0; i < buffList.Count; ++i) |
| | | { |
| | | // 只统计了加攻击力的 |
| | | if (buffList[i].EffectType != EndlessBuffEffectType.AttackAdd) continue; |
| | | GameObject prefab = Resources.Load<GameObject>("UI/BuffPreview/BuffItem"); |
| | | GameObject item = Instantiate(prefab); |
| | | item.transform.SetParent(Content.transform, false); |
| | | |
| | | switch (buffList[i].UseTarget) |
| | | { |
| | | case EndlessBuffUseTarget.All: |
| | | addArr[0] += (int)buffList[i].Config.buff_effect[1]; |
| | | addArr[1] += (int)buffList[i].Config.buff_effect[1]; |
| | | addArr[2] += (int)buffList[i].Config.buff_effect[1]; |
| | | break; |
| | | case EndlessBuffUseTarget.Element: |
| | | addArr[(int)buffList[i].Config.target_type[1] - 1] += (int)buffList[i].Config.buff_effect[1]; |
| | | break; |
| | | case EndlessBuffUseTarget.Designated: |
| | | break; |
| | | } |
| | | SelectBuffIcon buffSelect = item.GetComponent<SelectBuffIcon>(); |
| | | buffSelect.SetIcon(buffList[i].Config.image); |
| | | buffSelect.SetQuality(buffList[i].Config.rare); |
| | | buffSelect.SetName(buffList[i].Config.name); |
| | | buffSelect.SetEffect(buffList[i].Config.brief); |
| | | buffSelect.SetRare(buffList[i].Config.rare); |
| | | } |
| | | } |
| | | |
| | | int count = 0; |
| | | |
| | | for (int i = 0; i < addArr.Length; ++i) |
| | | private void ClearContent() |
| | | { |
| | | for (int i = Content.transform.childCount - 1; i >= 0; --i) |
| | | { |
| | | if (addArr[i] == 0) continue; |
| | | |
| | | ItemList[count].SetActive(true); |
| | | Sprite sp = Resources.Load<Sprite>($"{iconPath}{i + 1}"); |
| | | IconList[count].sprite = sp; |
| | | TextList[count].text = $"{elementNameArr[i]}精灵攻击+{addArr[i]}%"; |
| | | ++count; |
| | | Destroy(Content.transform.GetChild(i).gameObject); |
| | | } |
| | | } |
| | | |
| | | for (; count < 3; ++count) |
| | | { |
| | | ItemList[count].SetActive(false); |
| | | } |
| | | private void ShowBuffPreview() |
| | | { |
| | | preTimeScale = Time.timeScale; |
| | | Time.timeScale = 0; |
| | | Panel.SetActive(true); |
| | | Refresh(); |
| | | AudioSourceManager.Ins.StopBGAudio(); |
| | | } |
| | | |
| | | private void HideBuffPreview() |
| | | { |
| | | Time.timeScale = preTimeScale; |
| | | Panel.SetActive(false); |
| | | AudioSourceManager.Ins.RestartBGAudio(); |
| | | |
| | | } |
| | | } |
| | | } |