using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using Core.Utilities;
|
using System;
|
|
/**
|
* 选择buff脚本
|
* @Author: chenxin
|
* @Date: 2020-10-19 15:55:46
|
*/
|
namespace KTGMGemClient
|
{
|
public class EndlessBuffSelect : Singleton<EndlessBuffSelect>
|
{
|
public Text Prompt;
|
|
public List<SelectBuffIcon> IconList;
|
|
public List<Sprite> SpriteList;
|
|
/// <summary>
|
/// buff是否选中完成
|
/// </summary>
|
private bool isCompleted;
|
|
public event Action<int> BuffSelectCompleted;
|
|
private int SelectedIndex;
|
|
// Start is called before the first frame update
|
private void Start()
|
{
|
for (int i = 0; i < IconList.Count; ++i)
|
{
|
IconList[i].OnSelectBuffCompleted += OnClick;
|
}
|
}
|
|
private void OnEnable()
|
{
|
isCompleted = false;
|
Prompt.text = "点击选择buff";
|
|
for (int i = 0; i < IconList.Count; ++i)
|
{
|
IconList[i].SetIcon(SpriteList[i]);
|
IconList[i].SetState(EndlessBuffSelectState.Normal);
|
}
|
}
|
|
public void OnClick(int index)
|
{
|
if (isCompleted) return;
|
|
isCompleted = true;
|
SelectedIndex = index;
|
Prompt.text = "选择buff成功";
|
|
for (int i = 0; i < IconList.Count; ++i)
|
{
|
if (index == i)
|
IconList[i].SetState(EndlessBuffSelectState.Selected);
|
else
|
IconList[i].SetState(EndlessBuffSelectState.Unselected);
|
}
|
|
StartCoroutine(DelayToClose());
|
}
|
|
public void ShowBuffUI()
|
{
|
gameObject.SetActive(true);
|
}
|
|
public void HideBuffUI()
|
{
|
gameObject.SetActive(false);
|
}
|
|
private IEnumerator DelayToClose()
|
{
|
yield return new WaitForSeconds(0.5f);
|
HideBuffUI();
|
|
if (BuffSelectCompleted != null)
|
BuffSelectCompleted(SelectedIndex);
|
}
|
|
public void Refresh(List<EndlessBuffConfig> list)
|
{
|
for (int i = 0; i < IconList.Count; ++i)
|
{
|
IconList[i].SetName(list[i].Config.name);
|
IconList[i].SetEffect(list[i].Config.brief);
|
IconList[i].SetRare(list[i].Config.rare);
|
}
|
}
|
}
|
}
|