1118OPSSNew/Assets/Zion/Scripts/GameScene/ControlManager.cs

85 lines
2.2 KiB
C#

using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class ControlManager : MonoBehaviour
{
public static ControlManager Instance;
public GraphicRaycaster commandPanel;
/// <summary>
/// 退出房间倒计时
/// </summary>
public int countDown = 5;
public Text countDownText;
public GameObject countDownObj;
private void Awake()
{
Init();
}
private void Init()
{
Instance = this;
GameManage.Instance.SetPauseAction(StopOperation);
GameManage.Instance.SetCloseAction(EndofRoom);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.K))
{
CommandPanel.Instance.gameObject.SetActive(true);
//CommandPanel.Instance.gameObject.GetComponent<RadialView>().UpdateLinkedTransform = true;
}
if (Input.GetKeyDown(KeyCode.L))
{
ReceiveCommand.instance.transform.GetChild(0).gameObject.SetActive(true);
// ReceiveCommand.instance.transform.GetChild(0).GetComponent<RadialView>().UpdateLinkedTransform = true;
}
if (Input.GetKeyDown(KeyCode.N))
{
EndofRoom();
}
}
/// <summary>
/// 房间开始暂停
/// </summary>
/// <param name="isPause"></param>
public void StopOperation(bool isPause)
{
UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects().ToList().ForEach(a =>
{
a.GetComponentsInChildren<BoxCollider>(true).ToList().ForEach(b =>
{
b.enabled = !isPause;
});
});
commandPanel.enabled = !isPause;
}
/// <summary>
/// 退出房间
/// </summary>
public void EndofRoom()
{
StartCoroutine(CoundDown());
}
IEnumerator CoundDown()
{
countDownObj.SetActive(true);
while (countDown >= 0)
{
countDownText.text = "倒计时:" + countDown.ToString() + " 秒";
countDown--;
yield return new WaitForSeconds(1);
}
countDownObj.SetActive(false);
GameManage.Instance.Quit();
}
}