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 = "Endless2D";
|
|
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.");
|
}
|
}
|
}
|