chenxin
2020-12-25 01a178da6b8dd0ba4a1b44d6d09f907e943a5d12
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
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using TowerDefense.UI.HUD;
 
/**
 * 精灵升级面板
 * @Author: chenxin
 * @Date: 2020-12-11 10:59:15
 */
namespace KTGMGemClient
{
    public class ElfUpgrade : MonoBehaviour
    {
        [SerializeField]
        private Image lightImg;
 
        [SerializeField]
        private Text continueText;
 
        [SerializeField]
        private GameObject particlePrefab;
 
        private GameObject particleObj;
 
        private float startAlpha = 0.3f;
 
        private Vector3 rotation = Vector3.forward;
 
        /// <summary>
        /// 升级最低等级
        /// </summary>
        private int upgradeLevel;
 
        // Start is called before the first frame update
        private void Start()
        {
            EndlessUIStart.instance.ShowUIMask();
            particleObj = Instantiate(particlePrefab);
            particleObj.transform.SetParent(GameObject.Find("ParticleSystemObject").transform, false);
            particleObj.transform.localPosition = new Vector3(0f, 5.5f, 38.6f);
            particleObj.transform.localScale = new Vector3(2f, 2f, 2f);
            ParticleSystem ps = particleObj.transform.GetChild(0).GetComponent<ParticleSystem>();
            ps?.Play();
            Tween1();
        }
 
        private void Update()
        {
            lightImg.transform.Rotate(-rotation * 10 * Time.deltaTime);
        }
 
        private void Tween1()
        {
            continueText.color = new Color(1f, 1f, 1f, startAlpha);
            DOTween.To(
                () => continueText.color,
                (Color v) => continueText.color = v,
                new Color(1f, 1f, 1f, 1f), 0.3f)
                .SetEase(Ease.OutCubic)
                .OnComplete(Tween2);
        }
 
        private void Tween2()
        {
            DOTween.To(
                () => continueText.color,
                (Color v) => continueText.color = v,
                new Color(1f, 1f, 1f, startAlpha), 0.6f)
                .SetDelay(0.5f)
                .OnComplete(Tween1);
        }
 
        public void OnClick()
        {
            EndlessUIStart.instance.HideUIMask();
            Destroy(gameObject);
            Destroy(particleObj);
            particleObj = null;
            EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.ElfUpgradePanelClosed);
        }
 
        public void SetUpgradeLevel(int level)
        {
            if (level < 1) level = 1;
            else if (level >= ElfUpgradeData.MaxTowerLevel) level = ElfUpgradeData.MaxTowerLevel;
 
            upgradeLevel = level;
        }
 
        public int GetUpgradeLevel()
        {
            return upgradeLevel == 0 ? 1 : upgradeLevel;
        }
    }
}