using UnityEngine;
|
using UnityEngine.UI;
|
using TowerDefense.UI.HUD;
|
using DG.Tweening;
|
using TowerDefense.Towers.Placement;
|
using UnityEngine.SceneManagement;
|
using TowerDefense.Level;
|
|
/**
|
* 无尽模式结算
|
* @Author: chenxin
|
* @Date: 2020-10-19 17:11:03
|
*/
|
namespace KTGMGemClient
|
{
|
public class EndlessSettlement : MonoBehaviour
|
{
|
public AudioClip VictoryAudio;
|
|
public AudioSource AudioSource;
|
|
/// <summary>
|
/// Name of level select screen
|
/// </summary>
|
public string menuSceneName = "MainManuScene";
|
|
/// <summary>
|
/// Reference to the <see cref="EndlessLevelManager" />
|
/// </summary>
|
protected EndlessLevelManager levelManager;
|
|
/// <summary>
|
/// 最终波次文本
|
/// </summary>
|
public Text FinalWaveText;
|
|
/// <summary>
|
/// 道具列表UI
|
/// </summary>
|
public GameObject PropListUI;
|
|
public GameObject SettlementUI;
|
|
public void Init()
|
{
|
LazyLoad();
|
levelManager.LevelCompleted -= Victory;
|
levelManager.LevelCompleted += Victory;
|
}
|
|
/// <summary>
|
/// 回到主界面的功能,暂时也使用重新开启新关卡.
|
/// </summary>
|
public void ReturnToMainMenu()
|
{
|
if (GameConfig.IsNewbieGuideCompleted)
|
GameConfig.IsNewbie = false;
|
|
// 清空所有Tween数据:
|
DOTween.Clear();
|
EndlessUIStart.bFirstLoaded = false;
|
EndlessUIStart.bGameStart = false;
|
|
TowerPlacementGridEndless.GRID_OPENCASH = 100;
|
|
SafelyUnsubscribe();
|
SceneManager.LoadScene(menuSceneName);
|
}
|
|
/// <summary>
|
/// Shows the end game screen
|
/// </summary>
|
protected void OpenEndGameScreen(bool victory)
|
{
|
if (!EndlessGameUI.instanceExists) return;
|
|
if (EndlessGameUI.instance.state == EndlessGameUI.State.Building)
|
EndlessGameUI.instance.CancelGhostPlacement();
|
|
RefreshFinalWave();
|
RefreshPropList();
|
SettlementUI.SetActive(true);
|
}
|
|
/// <summary>
|
/// Occurs when the level is sucessfully completed
|
/// </summary>
|
protected void Victory()
|
{
|
EndlessUIStart.instance.Pause();
|
OpenEndGameScreen(true);
|
if (VictoryAudio != null && AudioSource != null)
|
AudioSource.PlayOneShot(VictoryAudio);
|
}
|
|
/// <summary>
|
/// Safely unsubscribes from <see cref="EndlessLevelManager" /> events.
|
/// </summary>
|
protected void OnDestroy()
|
{
|
SafelyUnsubscribe();
|
if (EndlessGameUI.instanceExists)
|
EndlessGameUI.instance.Unpause();
|
}
|
|
// <summary>
|
/// Ensure that <see cref="EndlessLevelManager" /> events are unsubscribed from when necessary
|
/// </summary>
|
protected void SafelyUnsubscribe()
|
{
|
LazyLoad();
|
levelManager.LevelCompleted -= Victory;
|
}
|
|
/// <summary>
|
/// Ensure <see cref="EndlessLevelManager" /> is not null
|
/// </summary>
|
protected void LazyLoad()
|
{
|
if (levelManager == null && EndlessLevelManager.instanceExists)
|
levelManager = EndlessLevelManager.instance;
|
}
|
|
/// <summary>
|
/// 刷新最终波次信息
|
/// </summary>
|
/// <param name="level">关卡等级</param>
|
/// <param name="wave">波次</param>
|
private void RefreshFinalWave()
|
{
|
int level = EndlessLevelManager.instance.CurrentLevel;
|
int wave = EndlessLevelManager.instance.WaveManager.CurrentWaveIndex;
|
|
FinalWaveText.text = $"最终波次:第{level}关,第{wave}波";
|
}
|
|
private void RefreshPropList()
|
{
|
EndlessSettlementPropList list = PropListUI.GetComponent<EndlessSettlementPropList>();
|
list.RefreshList();
|
}
|
}
|
}
|