chenxin
2020-11-14 4a083f2f3d8baf1c2630b3717d62904edcc8e24a
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
using System.Collections;
using System.Collections.Generic;
using TowerDefense.Level;
using UnityEngine;
using UnityEngine.SceneManagement;
using MoreMountains.NiceVibrations;
using UnityEngine.UI;
using DG.Tweening;
using KTGMGemClient;
using UnityEngine.Networking;
 
public class MainMenuScene : MonoBehaviour
{
    public string gemBattleScene = "GemBattle";
 
    /// <summary>
    /// 无尽模式(PVE)场景
    /// </summary>
    public string endlessGameScene = "Endless";
 
    public string loadingScene = "LoadingScene";
 
    /// <summary>
    /// 对战按钮.
    /// </summary>
    public Button combatBtn;
    /// <summary>
    /// Reference to the <see cref="LevelManager" />
    /// </summary>
    protected LevelManager m_LevelManager;
 
    /// <summary>
    /// 版本信息
    /// </summary>
    public Text versionInfo;
 
    protected bool bStartPlay = false;
    protected float nextShake = 1.5f;
 
    // Start is called before the first frame update
    void Start()
    {
        Application.targetFrameRate = 60;
        StartCoroutine(WWWReadFromFile(Application.streamingAssetsPath + "/Table/JsonVersion.txt"));
    }
 
 
    /// <summary>
    /// 对战按钮按下的反应.
    /// </summary>
    public void combatBtnDown()
    {
        MMVibrationManager.Haptic(HapticTypes.Success);
 
        // 开始缩小Button
        Sequence scaleTweenSeq = DOTween.Sequence();
        Tweener btnScale = combatBtn.transform.DOScale(0.92f, 0.15f);
        scaleTweenSeq.Append(btnScale);
    }
 
    public void combatBtnTouchOff()
    {
        combatBtn.transform.DOKill();
        combatBtn.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
    }
 
 
    /// <summary>
    /// 进入无尽模式(PVE)
    /// </summary>
    public void cooperateBtnClick()
    {
 
        AudioSourceManager.Ins?.Play(AudioEnum.UI);
 
        combatBtn.transform.DOKill();
        combatBtn.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
        this.SafelyUnsubscribe();
        GameConfig.NextSceneName = endlessGameScene;
        SceneManager.LoadScene(loadingScene);
        Application.targetFrameRate = 60;
    }
 
    /// <summary>
    /// 开始游戏相关的函数
    /// </summary>
    public void StartGame()
    {
        AudioSourceManager.Ins?.Play(AudioEnum.UI);
 
        combatBtn.transform.DOKill();
        combatBtn.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
 
 
        this.SafelyUnsubscribe();
        //Debug.Log("开始调入主场景.");
        //SceneManager.LoadScene(startGameScene);
        GameConfig.NextSceneName = gemBattleScene;
        SceneManager.LoadScene(loadingScene);
        bStartPlay = true;
        Application.targetFrameRate = 60;
    }
 
    protected void SafelyUnsubscribe()
    {
        LazyLoad();
        //m_LevelManager.levelCompleted -= Victory;
        //m_LevelManager.levelFailed -= Defeat;
    }
 
 
    /// <summary>
    /// 
    /// </summary>
    protected void LazyLoad()
    {
        if ((m_LevelManager == null) && LevelManager.instanceExists)
        {
            m_LevelManager = LevelManager.instance;
        }
    }
 
    /// <summary>
    /// 对CombatBtn做一个简单的动画.
    /// </summary>
    protected void combatBtnAnim()
    {
        RectTransform tr = this.combatBtn.GetComponent<RectTransform>();
        if (tr)
        {
            tr.DOShakeScale(0.5f, 0.3f, 3);
        }
    }
 
    protected IEnumerator WWWReadFromFile(string path)
    {
        UnityWebRequest wwwReq = UnityWebRequest.Get(path);
        yield return wwwReq.SendWebRequest();
        if (wwwReq.isHttpError || wwwReq.isNetworkError)
        {
            Debug.LogError("UnityWebRequest加载出错:" + wwwReq.error.ToString());
            yield break;
        }
 
        // 
        JsonDataCenter.SVNVERSION_INFO = wwwReq.downloadHandler.text;
    }
 
    // Update is called once per frame
    void Update()
    {
        if (versionInfo)
            versionInfo.text = JsonDataCenter.SVNVERSION_INFO;
 
        nextShake -= Time.deltaTime;
        if (nextShake < 0)
        {
            this.combatBtnAnim();
            System.Random rd = new System.Random();
            nextShake = (float)rd.NextDouble();
            nextShake *= 3.0f;
            nextShake += 2.0f;
        }
 
        if (bStartPlay)
        {
            //Debug.Log("StartPlaying.");
        }
    }
}