chenxin
2020-10-27 38136a34de9aa36bf15ec7471abd56e2cba6c26f
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
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/";
 
        private void Start()
        {
 
        }
 
        public void OnClick()
        {
            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;
 
            if (selected)
                DOTween.To(() => transform.localScale, (v) => transform.localScale = v, new Vector3(1f, 1f, 1f), 0.15f);
            else
                DOTween.To(() => transform.localScale, (v) => transform.localScale = v, new Vector3(0.87f, 0.87f, 0.87f), 0.15f);
        }
 
        /// <summary>
        /// 重置
        /// </summary>
        public void Reset()
        {
            transform.localScale = new Vector3(0.87f, 0.87f, 0.87f);
        }
    }
}