using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; using DG.Tweening; /** * 无尽模式选择buff * @Author: chenxin * @Date: 2020-10-15 17:00:26 */ namespace KTGMGemClient { public class SelectBuffIcon : MonoBehaviour { public Image Icon; /// /// 边框 /// public Image BorderImage; /// /// 品质底图 /// public Image QualityImage; /// /// buff名称 /// public Text Name; /// /// 效果描述 /// public Text Effect; public event Action OnSelectBuffCompleted; /// /// 选择的索引 /// public int Index; /// /// 是否被选中 /// public bool IsSelected { get; set; } private string iconPath = "UI/Endless/BuffIcon/"; private string qualityPath = "UI/Endless/BuffQuality/"; public ParticleSystem myPS;//播放粒子特效 GameObject psParent; private void Start() { if (psParent == null && myPS != null) { psParent = myPS.transform.parent.gameObject; } } public void OnClick() { AudioSourceManager.Ins.Play(AudioEnum.ChooseBuff); if (OnSelectBuffCompleted != null) OnSelectBuffCompleted(Index); } public void SetIcon(int resId) { Icon.sprite = Resources.Load($"{iconPath}{resId}", typeof(Sprite)) as Sprite; } /// /// 设置buff品质 /// /// public void SetQuality(int quality) { QualityImage.sprite = Resources.Load($"{qualityPath}{quality}", typeof(Sprite)) as Sprite; } public void SetName(string buffName) { Name.text = buffName; } /// /// 设置buff效果描述 /// /// public void SetEffect(string effect) { Effect.text = effect; } /// /// 设置品级 /// /// public void SetRare(int rare) { Name.color = EndlessBuffData.GetColorByRare(rare); } /// /// 设置选中状态,做个缓动播放粒子特效 /// /// public void SetState(bool selected) { if (selected == IsSelected) return; IsSelected = selected; BorderImage.gameObject.SetActive(selected); if (selected) { DOTween.To(() => transform.localScale, (v) => transform.localScale = v, new Vector3(1f, 1f, 1f), 0.15f); if (!psParent.activeSelf) psParent.SetActive(true); myPS?.Play(); } else { DOTween.To(() => transform.localScale, (v) => transform.localScale = v, new Vector3(0.87f, 0.87f, 0.87f), 0.15f); myPS?.Stop(); if (psParent.activeSelf) psParent.SetActive(false); } } /// /// 重置 /// public void Reset() { IsSelected = false; BorderImage.gameObject.SetActive(false); transform.localScale = new Vector3(0.87f, 0.87f, 0.87f); } } }