FormM.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class FormM : MonoBehaviour {
  5. // 初始化窗口列表
  6. private static List<MyForm> formList = new();
  7. private void Start() {
  8. formList = new List<MyForm>(FindObjectsOfType<MyForm>());
  9. Debug.Log("找到了 " + formList.Count + " 个窗口");
  10. // 针对窗口的初始化状态,确保只有一个窗口正在显示中
  11. foreach (MyForm form in formList) {
  12. if (form.defaultShow) _currentForm = form;
  13. }
  14. foreach (MyForm form in formList) {
  15. form.isShowing = (_currentForm != null && _currentForm.name == form.name);
  16. }
  17. }
  18. // 管理当前窗口
  19. private static MyForm _currentForm = null;
  20. public static MyForm currentForm {
  21. get { return _currentForm; }
  22. set {
  23. if (value == _currentForm) return;
  24. _currentForm = value;
  25. // 激活或隐藏窗口
  26. foreach (MyForm form in formList) {
  27. form.isShowing = (value != null && value.name == form.name);
  28. }
  29. }
  30. }
  31. }