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 List<SelectBuffIcon> IconList;
|
|
public event Action<int> BuffSelectCompleted;
|
|
/// <summary>
|
/// 当前选择的索引,-1表示还未选中其中一个
|
/// </summary>
|
private int SelectedIndex = -1;
|
|
public Button SelectBtn;
|
|
public GameObject EffectPrefabObject;
|
|
private GameObject effectObj;
|
|
private Vector3[] effectPosArr = { new Vector3(-21.6f, 0, 6.6f), new Vector3(0, 0, 6.6f), new Vector3(21.6f, 0, 6.6f) };
|
|
// Start is called before the first frame update
|
private void Start()
|
{
|
for (int i = 0; i < IconList.Count; ++i)
|
{
|
IconList[i].OnSelectBuffCompleted += OnClick;
|
}
|
|
SelectBtn.onClick.AddListener(OnClickSelectBtn);
|
}
|
|
private void OnEnable()
|
{
|
SelectedIndex = -1;
|
|
for (int i = 0; i < IconList.Count; ++i)
|
{
|
IconList[i].Reset();
|
}
|
|
}
|
|
private void OnDisable()
|
{
|
if (effectObj != null)
|
Destroy(effectObj);
|
}
|
|
public void OnClick(int index)
|
{
|
// 如果点击同一个直接返回
|
if (index == SelectedIndex) return;
|
|
// 如果已经选择过了,设置一个之前选择的item
|
if (SelectedIndex != -1)
|
IconList[SelectedIndex].SetState(false);
|
|
SelectedIndex = index;
|
IconList[index].SetState(true);
|
|
//PlayEffect();
|
}
|
|
|
private void PlayEffect()
|
{
|
if (effectObj == null)
|
{
|
effectObj = Instantiate(EffectPrefabObject);
|
GameObject particleSystemObject = GameObject.Find("ParticleSystemObject");
|
effectObj.transform.SetParent(particleSystemObject.transform, false);
|
effectObj.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
|
}
|
effectObj.transform.localPosition = effectPosArr[SelectedIndex];
|
ParticleSystem ps = effectObj.transform.GetChild(0).GetComponent<ParticleSystem>();
|
ps.Play();
|
}
|
|
private void StopEffect()
|
{
|
if (effectObj != null)
|
{
|
ParticleSystem ps = effectObj.transform.GetChild(0).GetComponent<ParticleSystem>();
|
ps.Stop();
|
ps.Clear();
|
}
|
}
|
|
/// <summary>
|
/// 点击了选择按钮
|
/// </summary>
|
public void OnClickSelectBtn()
|
{
|
if (SelectedIndex == -1) return;
|
|
int index = SelectedIndex;
|
|
AudioSourceManager.Ins.Play(AudioEnum.UI);
|
|
HideBuffUI();
|
|
IconList[index].Fly();
|
EndlessRandomTower.instance.SetCountDown(true);
|
|
if (BuffSelectCompleted != null)
|
BuffSelectCompleted(index);
|
}
|
|
public void ShowBuffUI()
|
{
|
EndlessMaskUI.instance.Show();
|
gameObject.SetActive(true);
|
AudioSourceManager.Ins?.Play(AudioEnum.ChooseBuff);
|
}
|
|
public void HideBuffUI()
|
{
|
EndlessMaskUI.instance.Hide();
|
StopEffect();
|
gameObject.SetActive(false);
|
}
|
|
public void Refresh(List<EndlessBuffConfig> list)
|
{
|
for (int i = 0; i < IconList.Count; ++i)
|
{
|
IconList[i].SetIcon(list[i].Config.image);
|
IconList[i].SetQuality(list[i].Config.rare);
|
IconList[i].SetName(list[i].Config.name);
|
IconList[i].SetEffect(list[i].Config.brief);
|
IconList[i].SetRare(list[i].Config.rare);
|
IconList[i].SetIsGold(list[i].EffectType == EndlessBuffEffectType.GoldAdd);
|
}
|
}
|
}
|
}
|