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 GameObject EffectPrefabObject;
|
|
private GameObject effectObj;
|
|
public void Init()
|
{
|
LazyLoad();
|
levelManager.LevelCompleted -= Victory;
|
levelManager.LevelCompleted += Victory;
|
}
|
|
/// <summary>
|
/// 回到主界面的功能,暂时也使用重新开启新关卡.
|
/// </summary>
|
public void ReturnToMainMenu()
|
{
|
// 清空所有Tween数据:
|
DOTween.Clear();
|
EndlessUIStart.bFirstLoaded = false;
|
EndlessUIStart.bGameStart = false;
|
|
TowerPlacementGridEndless.GRID_OPENCASH = 200;
|
|
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();
|
ShowGameOverPanel();
|
//panelUI.SetPlayEffectAC(PlayEffect);
|
//GameObject.Find("UICamera/BottomCanvas").GetComponent<Canvas>().enabled = false;
|
|
EndlessUIStart.instance.GameOver();
|
return;
|
|
// RefreshFinalWave();
|
// RefreshPropList();
|
// SettlementUI.SetActive(true);
|
// PlayEffect();
|
}
|
|
private void ShowGameOverPanel()
|
{
|
EndlessRandomTower.instance.SetCountDown(false);
|
EndlessRandomTower.instance.SetPS(false);
|
|
GameObject go = Instantiate(Resources.Load<GameObject>("Prefabs/GameOverPanel"), GameObject.Find("UICamera/BottomCanvas").transform);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.GameOverEnd, GameOverEnd);
|
}
|
|
private void GameOverEnd()
|
{
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.GameOverEnd, GameOverEnd);
|
ShowFinalPanel();
|
}
|
|
private void ShowFinalPanel()
|
{
|
GameObject go = Instantiate(Resources.Load<GameObject>("UI/Final/FinalPanel"), GameObject.Find("UICamera/BottomCanvas").transform);
|
FinalPanel panelUI = go.GetComponent<FinalPanel>();
|
int level = EndlessLevelManager.instance.CurrentLevel;
|
int wave = EndlessLevelManager.instance.WaveManager.CurrentWaveIndex;
|
|
if (GameConfig.IsNewbieStart)
|
{
|
//panelUI.SetData($"{EndlessLevelManager.instance.CurrentLevel - EndlessPortData.NewbieTotalLevel}关 {EndlessLevelManager.instance.WaveManager.CurrentWaveIndex}波", EndlessScoreData.CurrentSocre);
|
level = EndlessLevelManager.instance.CurrentLevel - EndlessPortData.NewbieTotalLevel;
|
Debug.Log($"新手开始玩的,实际关卡:{EndlessLevelManager.instance.CurrentLevel} 新手关卡:{EndlessPortData.NewbieTotalLevel}");
|
}
|
else
|
{
|
//panelUI.SetData($"{EndlessLevelManager.instance.CurrentLevel}关 {EndlessLevelManager.instance.WaveManager.CurrentWaveIndex}波", EndlessScoreData.CurrentSocre);
|
}
|
panelUI.SetData($"{level}关 {wave}波", EndlessScoreData.CurrentSocre);
|
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessCompletedPort, level, wave);
|
}
|
|
private void PlayEffect()
|
{
|
if (effectObj == null)
|
{
|
effectObj = Instantiate(EffectPrefabObject);
|
GameObject particleSystemObject = GameObject.Find("ParticleSystemObject");
|
effectObj.transform.SetParent(particleSystemObject.transform, false);
|
effectObj.transform.localPosition = new Vector3(0, -51.6f, 36.6f);
|
effectObj.transform.localScale = new Vector3(6, 6, 6);
|
}
|
|
ParticleSystem ps = effectObj.transform.GetChild(0).GetComponent<ParticleSystem>();
|
ps.Play();
|
}
|
|
/// <summary>
|
/// Occurs when the level is sucessfully completed
|
/// </summary>
|
protected void Victory()
|
{
|
++GameConfig.GameCompletedCount;
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessLevelCompleted);
|
EndlessUIStart.instance.Pause();
|
|
ShowPanel();
|
|
// int showFavorite = PlayerPrefs.GetInt("GemBattleFavorite");
|
|
// if (showFavorite == 0)
|
// {
|
// GameObject go = Instantiate(Resources.Load<GameObject>("UI/Favorite/FavoritePanel"), this.transform.parent.parent);
|
// FavoritePanelUI panelUI = go.GetComponent<FavoritePanelUI>();
|
// panelUI.SetAC(ShowPanel);
|
|
// }
|
// else
|
// {
|
// ShowPanel();
|
// }
|
}
|
|
private void ShowPanel()
|
{
|
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();
|
if (levelManager != null)
|
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();
|
}
|
}
|
}
|