using System.Collections; using System.Linq; using UnityEngine; using UnityEngine.UI; public class ControlManager : MonoBehaviour { public static ControlManager Instance; public GraphicRaycaster commandPanel; /// /// 退出房间倒计时 /// 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().UpdateLinkedTransform = true; } if (Input.GetKeyDown(KeyCode.L)) { ReceiveCommand.instance.transform.GetChild(0).gameObject.SetActive(true); // ReceiveCommand.instance.transform.GetChild(0).GetComponent().UpdateLinkedTransform = true; } if (Input.GetKeyDown(KeyCode.N)) { EndofRoom(); } } /// /// 房间开始暂停 /// /// public void StopOperation(bool isPause) { UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects().ToList().ForEach(a => { a.GetComponentsInChildren(true).ToList().ForEach(b => { b.enabled = !isPause; }); }); commandPanel.enabled = !isPause; } /// /// 退出房间 /// 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(); } }