using System.Collections.Generic;
|
using UnityEngine.UI;
|
using UnityEngine;
|
using TowerDefense.Level;
|
|
/**
|
* 无尽模式buff预览
|
* @Author: chenxin
|
* @Date: 2020-11-12 10:01:36
|
*/
|
namespace KTGMGemClient
|
{
|
public class EndlessBuffPreview : MonoBehaviour
|
{
|
/// <summary>
|
/// buff预览界面
|
/// </summary>
|
public GameObject Panel;
|
|
public GameObject Content;
|
|
/// <summary>
|
/// buff预览界面返回按钮
|
/// </summary>
|
public Button BackBtn;
|
|
/// <summary>
|
/// 未获得buff提示文字
|
/// </summary>
|
public Text NoBuffText;
|
|
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);
|
Panel.SetActive(false);
|
}
|
|
public void OnClick()
|
{
|
if (GameConfig.IsNewbie) return;
|
|
ShowBuffPreview();
|
}
|
|
private void Refresh()
|
{
|
if (!Panel.activeInHierarchy) return;
|
|
ClearContent();
|
|
List<EndlessBuffConfig> buffList = EndlessBuffManager.instance.BuffList;
|
|
if (buffList.Count == 0)
|
{
|
NoBuffText.gameObject.SetActive(true);
|
return;
|
}
|
|
NoBuffText.gameObject.SetActive(false);
|
|
for (int i = 0; i < buffList.Count; ++i)
|
{
|
GameObject prefab = Resources.Load<GameObject>("UI/BuffPreview/BuffItem");
|
GameObject item = Instantiate(prefab);
|
item.transform.SetParent(Content.transform, false);
|
|
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);
|
}
|
}
|
|
private void ClearContent()
|
{
|
for (int i = Content.transform.childCount - 1; i >= 0; --i)
|
{
|
Destroy(Content.transform.GetChild(i).gameObject);
|
}
|
}
|
|
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();
|
|
}
|
}
|
}
|