chenxin
2020-11-25 b2722bf84115092dcf61a0f612b737c20eb11f27
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
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Core.Utilities;
 
/**
 * 无尽模式boss控制器
 * @Author: chenxin
 * @Date: 2020-10-30 16:40:54
 */
namespace KTGMGemClient
{
    public class EndlessBossCtrl : Singleton<EndlessBossCtrl>
    {
        /// <summary>
        /// boss动作
        /// </summary>
        public Animator BossAnimator;
 
        /// <summary>
        /// 动作状态
        /// </summary>
        public EndlessBossActionState ActionState { get; set; }
 
        public Image Title;
 
        private string titlePath = "UI/Endless/SkillTitle/";
 
        public ParticleSystem deadPS, deadMoney;
 
        // Start is called before the first frame update
        private void Start()
        {
            ColorVal = 0;
            EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessBossSkillGlintTitle, Glint);
        }
 
        // Update is called once per frame
        private void Update()
        {
 
        }
 
        private void Glint(int skillType)
        {
            Title.sprite = Resources.Load<Sprite>($"{titlePath}{skillType}");
            //设置一个DOTween队列
            Sequence flashSeq = DOTween.Sequence();
            Color c = Title.color;
            c.a = 0;
            Title.color = c;
            Title.gameObject.SetActive(true);
 
            flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 1, 0.3f));
            flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 0, 0.15f));
            flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 1, 0.3f));
            flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 0, 0.15f));
            flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 1, 0.3f));
            flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 0, 0.15f));
            flashSeq.AppendCallback(() => { EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessBossSkillGlintTitleCompleted); });
        }
 
        private float ColorVal
        {
            get { return Title.color.a; }
            set
            {
                Title.gameObject.SetActive(value != 0);
                Color c = Title.color;
                c.a = value;
                Title.color = c;
            }
        }
 
        /// <summary>
        /// 帧事件
        /// </summary>
        /// <param name="frameName"></param>
        public void FireAnimationEvent(string frameName)
        {
            if (frameName == "summonEnd")
            {
                EventCenter.Ins.BroadCast((int)EventType.EndlessBossSummonEnd);
                // 召唤动作结束后自动切换到站立状态
                ChangeState(EndlessBossActionState.Standing);
            }
            else if (frameName == "death")
            {
                BossAnimator.speed = 0;
                EventCenter.Ins.BroadCast((int)EventType.EndlessBossDeathActionEnd);
            }
        }
 
        /// <summary>
        /// 切换状态
        /// </summary>
        /// <param name="newState"></param>
        public void ChangeState(EndlessBossActionState newState)
        {
            ActionState = newState;
 
            if (newState == EndlessBossActionState.Standing || newState == EndlessBossActionState.Summon)
                BossAnimator.speed = 1;
            else if (newState == EndlessBossActionState.Death)
            {
                //Debug.Log("BOSS死亡特效");
                //播放特效
                deadPS.Play();
                deadMoney.Play();
            }
            BossAnimator.SetInteger("State", (int)newState);
 
 
        }
    }
}