RemoteSingleton.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. using static ScenesManager;
  8. namespace SC.XR.Unity
  9. {
  10. public abstract class RemoteSingleton<T> : MonoBehaviour where T : MonoBehaviour
  11. {
  12. public GameObject[] Prefab;
  13. [HideInInspector]
  14. public List<GameObject> window=new List<GameObject>();
  15. private static T instance;
  16. private static object lockObj = new object();
  17. public static T Instance
  18. {
  19. get
  20. {
  21. return instance;
  22. }
  23. }
  24. public virtual void Awake()
  25. {
  26. instance = (T)FindObjectOfType(typeof(T));
  27. ScenesManager.Instance.initWindow(this.gameObject);
  28. }
  29. public virtual void initShow()
  30. {
  31. if(Prefab!=null&& window.Count<=0)
  32. {
  33. for (int i = 0; i < Prefab.Length; i++)
  34. {
  35. window.Add(GameObject.Instantiate(Prefab[i], this.transform));
  36. window[window.Count - 1].name = Prefab[i].name;
  37. }
  38. }
  39. SceneType stp = (SceneType)System.Enum.Parse(typeof(SceneType), this.gameObject.name.Split('(')[0]);
  40. int codeint = stp.GetHashCode() / 10000;
  41. if(codeint!=50)
  42. {
  43. for (int i = 0; i < window.Count; i++)
  44. {
  45. window[i].SetActive(false);
  46. }
  47. if (window.Count > 0)
  48. window[0].SetActive(true);
  49. }
  50. }
  51. public void gotoWindow(SceneType sc)
  52. {
  53. SceneType stp = (SceneType)System.Enum.Parse(typeof(SceneType), this.name.Split('(')[0]);
  54. int idx = sc - stp- 1000;
  55. Debug.Log("gotoWindow = "+idx);
  56. for (int i = 0; i < window.Count; i++)
  57. {
  58. if(i== idx)
  59. {
  60. window[i].SetActive(true);
  61. }else
  62. {
  63. window[i].SetActive(false);
  64. }
  65. }
  66. }
  67. }
  68. }