ScenesManager.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using SC.XR.Unity;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class ScenesManager
  7. {
  8. public enum mType
  9. {
  10. LogoInt = 1,
  11. LoginInt = 2,
  12. ShowChoose = 3,
  13. ShowXunJian = 4,
  14. ShowRTC = 5,
  15. ShowZhiDao = 6,
  16. publicInt = 7
  17. }
  18. public enum SceneType
  19. {
  20. GameStartLogo = 10001,
  21. ShowLogin = 20001,
  22. ShowChoose = 30001,
  23. ShowXunJian = 40001,
  24. ShowXJ = 41001,
  25. ShowDH = 41002,
  26. ShowRTC = 50001,
  27. ShowZhiDao = 50001,
  28. PopPublic = 70001,
  29. }
  30. private static ScenesManager instance;
  31. public static ScenesManager Instance
  32. {
  33. get
  34. {
  35. if (instance == null)
  36. {
  37. instance = new ScenesManager();
  38. }
  39. return instance;
  40. }
  41. }
  42. public List<SceneInfo> windows = new List<SceneInfo>();
  43. public Dictionary<int, List<SceneInfo>> dlglist = new Dictionary<int, List<SceneInfo>>();
  44. public void initWindow(GameObject window)
  45. {
  46. SceneInfo sceneInfo = window.AddComponent<SceneInfo>();
  47. SceneType stp = (SceneType)System.Enum.Parse(typeof(SceneType), window.name.Split('(')[0]);
  48. sceneInfo.setType(stp);
  49. int codeint = stp.GetHashCode() / 10000 ;
  50. if(stp.GetHashCode()-(codeint*10000)==1)
  51. {
  52. windows.Add(sceneInfo);
  53. // window.SetActive(false);
  54. }
  55. else
  56. {
  57. if(dlglist.ContainsKey(codeint))
  58. {
  59. List<SceneInfo> dlg = dlglist[codeint];
  60. dlg.Add(sceneInfo);
  61. dlglist[codeint]=dlg;
  62. }
  63. else
  64. {
  65. List<SceneInfo> dlg = new List<SceneInfo>();
  66. dlg.Add(sceneInfo);
  67. dlglist.Add(codeint,dlg);
  68. }
  69. }
  70. }
  71. public void showWindow(SceneType sceneType)
  72. {
  73. for (int i = 0; i < windows.Count; i++)
  74. {
  75. int codeint = windows[i]._sceneType.GetHashCode() / 10000;
  76. if (windows[i]._sceneType==sceneType|| codeint== mType.publicInt.GetHashCode())
  77. {
  78. windows[i].gameObject.SetActive(true);
  79. MonoBehaviour alist= windows[i].GetComponent<MonoBehaviour>();
  80. Type t = Type.GetType(alist.name);
  81. System.Reflection.MethodInfo md = t.GetMethod("initShow");
  82. if (md != null)
  83. {
  84. md.Invoke(alist,null);
  85. }
  86. }
  87. else
  88. {
  89. windows[i].gameObject.SetActive(false);
  90. }
  91. }
  92. }
  93. public void initPopUp()
  94. {
  95. for (int i = 0; i < dlglist[mType.publicInt.GetHashCode()].Count; i++)
  96. {
  97. dlglist[mType.publicInt.GetHashCode()][i].gameObject.SetActive(false);
  98. }
  99. }
  100. private PopPublic _popPublic;
  101. public PopPublic popPublic
  102. {
  103. get {
  104. if(!_popPublic)
  105. {
  106. for (int i = 0; i < dlglist[mType.publicInt.GetHashCode()].Count; i++)
  107. {
  108. PopPublic ppc = dlglist[mType.publicInt.GetHashCode()][i].GetComponent<PopPublic>();
  109. if (ppc)
  110. _popPublic= ppc;
  111. }
  112. }
  113. return _popPublic;
  114. }
  115. }
  116. public void showPop()
  117. {
  118. popPublic.gameObject.SetActive(true);
  119. }
  120. }