using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
public class FullScreenBattleWin : UIBase
|
{
|
|
// 组件引用
|
public Transform mountPoint;
|
|
private BattleRootNode battleRootNode = null;
|
|
|
private BattleField battleField;
|
|
[SerializeField]
|
private Button btnSpeed;
|
|
[SerializeField]
|
private Text textSpeed;
|
|
[SerializeField]
|
private Button btnPass;
|
|
[SerializeField]
|
private Button btnPause;
|
|
public RendererAdjuster buttonsAdjuster;
|
|
// 生命周期
|
protected override void InitComponent()
|
{
|
base.InitComponent();
|
// 初始化组件引用 绑定按钮等UI组件事件
|
|
btnSpeed.AddListener(ChangeSpeed);
|
|
btnPass.AddListener(OnClickPass);
|
|
btnPause.AddListener(OnClickPause);
|
}
|
|
private void OnClickPause()
|
{
|
if (null == battleField)
|
return;
|
|
battleField.IsPause = !battleField.IsPause;
|
}
|
|
private void OnClickPass()
|
{
|
if (null == battleField)
|
return;
|
|
battleField.ForceFinish();
|
}
|
|
private void ChangeSpeed()
|
{
|
if (null == battleField)
|
return;
|
|
BattleManager.Instance.speedIndex = (BattleManager.Instance.speedIndex + 1) % BattleManager.Instance.speedGear.Length;
|
battleField.SetSpeedRatio(BattleManager.Instance.speedGear[BattleManager.Instance.speedIndex]);
|
textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString();
|
}
|
|
protected override void OnPreOpen()
|
{
|
base.OnPreOpen();
|
// SetBattleField(BattleManager.Instance.storyBattleField);
|
BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField;
|
|
UIManager.Instance.CloseWindow<MainWin>();
|
}
|
|
protected override void OnPreClose()
|
{
|
base.OnPreClose();
|
UIManager.Instance.CloseWindow<BattleHUDWin>();
|
BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField;
|
|
UIManager.Instance.OpenWindow<MainWin>(0);
|
}
|
|
private void OnCreateBattleField(string arg1, BattleField field)
|
{
|
if (field.GetType() == battleField.GetType())
|
{
|
SetBattleField(field);
|
}
|
}
|
|
protected override void OnOpen()
|
{
|
base.OnOpen();
|
}
|
|
protected override void OnClose()
|
{
|
base.OnClose();
|
|
if (battleRootNode != null)
|
{
|
battleRootNode.transform.SetParent(Launch.Instance.transform);
|
battleRootNode.transform.localPosition = new Vector3(-10000, -10000, 0);
|
}
|
|
battleField = null;
|
}
|
|
protected override void NextFrameAfterOpen()
|
{
|
base.NextFrameAfterOpen();
|
}
|
|
protected override void CompleteClose()
|
{
|
base.CompleteClose();
|
}
|
|
public void SetBattleField(BattleField _battleField)
|
{
|
battleField = _battleField;
|
if (battleRootNode != null)
|
{
|
battleRootNode.transform.localPosition = Vector3.zero;
|
battleRootNode.transform.SetParent(Launch.Instance.transform);
|
}
|
|
battleRootNode = battleField.battleRootNode;
|
|
battleRootNode.transform.SetParent(mountPoint);
|
battleRootNode.transform.localPosition = Vector3.zero;
|
battleRootNode.transform.localScale = Vector3.one;
|
|
BattleHUDWin ui = UIManager.Instance.GetUI<BattleHUDWin>();
|
|
if (null == ui)
|
{
|
ui = UIManager.Instance.OpenWindow<BattleHUDWin>();
|
}
|
|
ui.SetBattleField(battleField);
|
battleField.UpdateCanvas(canvas);
|
buttonsAdjuster.SetSortingOrder(BattleConst.ActiveHeroActionSortingOrder);
|
|
textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString();
|
}
|
}
|