PageManagerComp.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Unity.VisualScripting;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace Plugins.CxShine.page
  5. {
  6. public class PageManagerComp : MonoBehaviour
  7. {
  8. public static PageManagerComp singleton;
  9. public GameObject pageContainer;
  10. public string pagePrefabLocation;
  11. public GameObject FirstPagePrefab;
  12. public GameObject gameObject3dContainer;
  13. public GameObject debugButton;
  14. public string debugWindowPrefabPath;
  15. public void HideUI()
  16. {
  17. pageContainer.SetActive(false);
  18. }
  19. public void DisplayUI()
  20. {
  21. pageContainer.SetActive(true);
  22. }
  23. private void Awake()
  24. {
  25. gameObject.SetActive(true);
  26. }
  27. private void Start()
  28. {
  29. singleton = this;
  30. OpenPage(FirstPagePrefab);
  31. // 如果有配置调试按钮界面的话
  32. if (debugButton != null)
  33. debugButton.GetOrAddComponent<Button>().onClick.AddListener(() =>
  34. {
  35. //
  36. Debug.Log("打开调试页面" + debugWindowPrefabPath);
  37. OpenPage(debugWindowPrefabPath, true);
  38. });
  39. }
  40. public GameObject OpenPage(string prefabPageName, bool isShowAnim = false)
  41. {
  42. var directionLocation = pagePrefabLocation + "/" + prefabPageName;
  43. Debug.Log("开始打开页面:" + directionLocation);
  44. return OpenPage(Resources.Load<GameObject>(directionLocation));
  45. }
  46. public GameObject OpenPage(GameObject go, bool isShowAnim = false)
  47. {
  48. var newPage = Instantiate(go);
  49. var pageComp = newPage.GetOrAddComponent<PageComp>();
  50. pageComp.showAnim(isShowAnim);
  51. pageComp.pageName = go.name;
  52. // pagePanel.set parent
  53. newPage.transform.SetParent(pageContainer.transform, false);
  54. return newPage;
  55. }
  56. }
  57. }