River Jiang
2020-10-21 9ecea6fd1dc5c53d670f7e0400210522bda5586d
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
using Core.Utilities;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using MoreMountains.NiceVibrations;
using TowerDefense.Level;
using KTGMGemClient;
 
/// <summary>
/// 无尽模式用自己的EndlessUIStart
/// </summary>
public class EndlessUIStart : Singleton<EndlessUIStart>
{
    public TextMeshProUGUI countDownTextNew = null;
 
    public TextMeshProUGUI timeTextNew = null;
 
    public TextMeshProUGUI timeStatic = null;
 
    /// <summary>
    /// 结算界面
    /// </summary>
    public GameObject SettlementUI;
 
    /// <summary>
    /// 倒计时整体的背景图片Mask
    /// </summary>
    public Image uiStartMssk = null;
 
    public AudioSource bgMusic;
 
    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;
 
    private bool isPause;
 
    // 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);
        EndlessBuffSelect.instance.HideBuffUI();
        EndlessBossHPManager.instance.HideHP();
        SettlementUI.SetActive(false);
    }
 
    /// <summary>
    /// 当前游戏局的开始时间.
    /// </summary>
    public float GameStartTime
    {
        get { return 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:" + 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);
            }
        }
    }
 
    public void Pause()
    {
        isPause = true;
    }
 
    public void Restart()
    {
        isPause = false;
    }
 
    public bool IsGameRunning { get { return !isPause; } }
 
    // Update is called once per frame
    void Update()
    {
        if (isPause) return;
 
        if (bGameStart)
        {
            startTime += Time.deltaTime;
            timeTextNew.text = ConvertTime((float)Math.Ceiling(startTime));
        }
 
        if (!bFirstLoaded && !bGameStart)
        {
            bFirstLoaded = true;
            secToDo = 4;
        }
 
        if (bFirstLoaded && !bGameStart)
        {
            secToDo -= Time.deltaTime;
 
            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);
                }
            }
 
            // 开启游戏,且隐藏中间的数字.
            if (secToDo <= 0)
            {
                uiStartMssk.gameObject.SetActive(false);
                countDownTextNew.text = "";
                bGameStart = true;
                // 开始关卡
                EndlessLevelManager.instance.StartLevel();
                timeTextNew.gameObject.SetActive(true);
 
                // 开始播放背景音乐.
                if (bgMusic != null)
                    bgMusic.Play();
            }
        }
    }
}