wangguan
2020-11-24 a27b3510185c04eb385f5ab3ad24fd4e87a27626
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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;
 
        /// <summary>
        /// 边框
        /// </summary>
        public Image BorderImage;
 
        /// <summary>
        /// 品质底图
        /// </summary>
        public Image QualityImage;
 
        /// <summary>
        /// buff名称
        /// </summary>
        public Text Name;
 
        /// <summary>
        /// 效果描述
        /// </summary>
        public Text Effect;
 
        public event Action<int> OnSelectBuffCompleted;
 
        /// <summary>
        /// 选择的索引
        /// </summary>
        public int Index;
 
        /// <summary>
        /// 是否被选中
        /// </summary>
        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)
            {
                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;
        }
 
        /// <summary>
        /// 设置buff品质
        /// </summary>
        /// <param name="quality"></param>
        public void SetQuality(int quality)
        {
            QualityImage.sprite = Resources.Load($"{qualityPath}{quality}", typeof(Sprite)) as Sprite;
        }
 
        public void SetName(string buffName)
        {
            Name.text = buffName;
        }
 
        /// <summary>
        /// 设置buff效果描述
        /// </summary>
        /// <param name="effect"></param>
        public void SetEffect(string effect)
        {
            Effect.text = effect;
        }
 
        /// <summary>
        /// 设置品级
        /// </summary>
        /// <param name="rare"></param>
        public void SetRare(int rare)
        {
            Name.color = EndlessBuffData.GetColorByRare(rare);
        }
 
 
        /// <summary>
        /// 设置选中状态,做个缓动播放粒子特效
        /// </summary>
        /// <param name="isSelected"></param>
        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);
 
            }
        }
 
        /// <summary>
        /// 重置
        /// </summary>
        public void Reset()
        {
            IsSelected = false;
            BorderImage.gameObject.SetActive(false);
            transform.localScale = new Vector3(0.87f, 0.87f, 0.87f);
        }
    }
}