chenxin
2020-10-22 85f0d13945f3aef5aef1b3c1b47c77cea0514c17
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
using Core.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using TowerDefense.UI.HUD;
using UnityEngine;
using UnityEngine.UI;
using MoreMountains.NiceVibrations;
using TowerDefense.Level;
using DG.Tweening;
 
public class UIStart : Singleton<UIStart>
{
    public BuildSidebar buildSideBar = null;
    public TextMeshProUGUI countDownTextNew = null;
    public TextMeshProUGUI timeTextNew = null;
    public TextMeshProUGUI timeStatic = null;
    public Image bossPic = null;    // 对应的Boss图片
    public Image uiStartMssk = null;// 倒计时整体的背景图片Mask
 
    /// <summary>
    /// 怪物刷新加速。
    /// </summary>
    public Image firstSpeedBg;
    public Image firstSpeedCent;
    public Image secondSpeedBg;
    public Image secondSpeedCent;
 
 
    public AudioSource bgMusic;
    public static float Max_GameTime = 50f;// 每一局的最长时间,用于界面显示倒计时.
 
    public static bool bFirstLoaded = false;
    public static bool bGameStart = false;
    protected float secToDo = 3f;
 
    protected float startTime = 0.0f;
    protected bool bossCreate = false;
 
    protected bool[] bVibrate;
 
    // Start is called before the first frame update
    void Start()
    {
        bVibrate = new bool[4];
        bVibrate[0] = bVibrate[1] = bVibrate[2] = bVibrate[3] = false;
        
        // 设置为顶层渲染:
        countDownTextNew.transform.SetAsLastSibling();
 
        if (timeStatic )
        {
            timeStatic.gameObject.SetActive(false);
            //timeTextNew.gameObject.SetActive(false);
            bossPic.gameObject.SetActive(false);
        }
 
        if( firstSpeedBg)
        {
            firstSpeedBg.gameObject.SetActive(false);
            secondSpeedBg.gameObject.SetActive(false);
        }
    }
 
    /// <summary>
    /// 当前游戏局的开始时间.
    /// </summary>
    public float gameStartTime
    {
        get { return this.startTime;  }
    }
 
    protected string convertSec( float sec)
    {
        if (sec < 10)
            return "0" + Math.Floor( sec ).ToString();
        else
            return Math.Floor(sec).ToString();
    }
    /// <summary>
    /// 把当前的秒数变成字符串.
    /// </summary>
    /// <param name="sec"></param>
    /// <returns></returns>
    protected string convertTime( float sec)
    {
        if( sec < 60)
        {
            return "00:" + this.convertSec( sec );
        }
        else
        {
            float min = sec / 60;
            if (min < 10)
            {
                return  "0" + Math.Floor(min).ToString() + ":" + convertSec( sec % 60 );
            }
            else
            {
                return Math.Floor(min).ToString() + ":" + convertSec( sec % 60);
            }
        }
    }
 
    /// <summary>
    /// 设置第一次加速.
    /// </summary>
    public void SetFirstSpeedUp()
    {
        firstSpeedBg.gameObject.SetActive(true);
        firstSpeedBg.color = new Color(1, 1, 1, 0);
        firstSpeedCent.color = new Color(1, 1, 1, 0);
        //设置一个DOTween队列
        Sequence seq = DOTween.Sequence();
 
        seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 1), 0.3f));
        seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 1), 0.3f));
        seq.AppendInterval(0.2f);
        seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 0.2f), 0.25f));
        seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 0.2f), 0.25f));
        seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 1.0f), 0.25f));
        seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 1.0f), 0.25f));
        seq.AppendInterval(0.2f);
        seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 0.2f), 0.25f));
        seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 0.2f), 0.25f));
        seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 1.0f), 0.25f));
        seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 1.0f), 0.25f));
        seq.AppendInterval(0.2f);
        seq.Append(firstSpeedCent.DOColor(new Color(1, 1, 1, 0), 0.5f));
 
    }
 
    /// <summary>
    /// 设置第二次加速
    /// </summary>
    public void SetSecondSpeedUp()
    {
        firstSpeedBg.gameObject.SetActive(false);
        secondSpeedBg.gameObject.SetActive(true);
 
        secondSpeedBg.gameObject.SetActive(true);
        secondSpeedBg.color = new Color(1, 1, 1, 0);
        secondSpeedCent.color = new Color(1, 1, 1, 0);
        //设置一个DOTween队列
        Sequence seq = DOTween.Sequence();
 
        seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 1), 0.3f));
        seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 1), 0.3f));
        seq.AppendInterval(0.2f);
        seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 0.2f), 0.25f));
        seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 0.2f), 0.25f));
        seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 1.0f), 0.25f));
        seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 1.0f), 0.25f));
        seq.AppendInterval(0.2f);
        seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 0.2f), 0.25f));
        seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 0.2f), 0.25f));
        seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 1.0f), 0.25f));
        seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 1.0f), 0.25f));
        seq.AppendInterval(0.2f);
        seq.Append(secondSpeedCent.DOColor(new Color(1, 1, 1, 0), 0.5f));
 
    }
 
    // Update is called once per frame
    void Update()
    {
        if( bGameStart)
        {
            
            startTime += Time.deltaTime;
            float finalTime = startTime; // Max_GameTime - startTime;
            /*if (finalTime <= 0)
            {
                if( !bossCreate)
                {
                    bossCreate = true;
                    AgentInsManager.instance.moveAllAgentToCenter();
                }
                finalTime = 0;
            }*/
            this.timeTextNew.text = this.convertTime( (float)Math.Ceiling( finalTime ) );
            
        }
 
        if ((!bFirstLoaded)&&(!bGameStart))
        {
            bFirstLoaded = true;
            secToDo = 4;
        }
        if(bFirstLoaded && (!bGameStart))
        {
            secToDo -= (Time.deltaTime * 1.0f); // 放慢时间用于调试
            if (secToDo >= 3)
            {
                countDownTextNew.text = "3";
                if( !bVibrate[3])
                {
                    bVibrate[3] = true;
                    MMVibrationManager.Haptic(HapticTypes.SoftImpact);
                }
            }
            else if (secToDo >= 2)
            {
                countDownTextNew.text = "2";
                if( !bVibrate[2])
                {
                    bVibrate[2] = true;
                    MMVibrationManager.Haptic(HapticTypes.MediumImpact);
                }
            }
            else if (secToDo >= 1)
            {
                countDownTextNew.text = "1";
                if( !bVibrate[1])
                {
                    bVibrate[1] = true;
                    MMVibrationManager.Haptic(HapticTypes.HeavyImpact);
                }
            }
            else if (secToDo < 1)
            {
                countDownTextNew.text = "GO!";
                if( !bVibrate[0])
                {
                    bVibrate[0] = true;
                    MMVibrationManager.Haptic(HapticTypes.HeavyImpact);
                }
                uiStartMssk.gameObject.SetActive(false);
            }
            // 开启游戏,且隐藏中间的数字.
            if( secToDo <= 0)
            {
                if (this.buildSideBar)
                {
                    buildSideBar.StartWaveButtonPressed();
                }
                countDownTextNew.text = "";
 
                // 双方兵线都开始出兵.
                LevelManager.instance.BuildingCompleted();
                OpponentMgr.instance.StartWaves();
                
                timeTextNew.gameObject.SetActive(true);
                //timeStatic.gameObject.SetActive(true);
                //bossPic.gameObject.SetActive(true);
 
                bGameStart = true;
 
                // 开始播放背景音乐.
                if (bgMusic != null)
                    bgMusic.Play();
            }
        }
    }
}