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";
///
/// 无尽模式(PVE)场景
///
public string endlessGameScene = "Endless";
public string loadingScene = "LoadingScene";
///
/// 对战按钮.
///
public Button combatBtn;
///
/// Reference to the
///
protected LevelManager m_LevelManager;
///
/// 版本信息
///
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"));
}
///
/// 对战按钮按下的反应.
///
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);
}
///
/// 进入无尽模式(PVE)
///
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;
}
///
/// 开始游戏相关的函数
///
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;
}
///
///
///
protected void LazyLoad()
{
if ((m_LevelManager == null) && LevelManager.instanceExists)
{
m_LevelManager = LevelManager.instance;
}
}
///
/// 对CombatBtn做一个简单的动画.
///
protected void combatBtnAnim()
{
RectTransform tr = this.combatBtn.GetComponent();
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.");
}
}
}