RemoteSingleton.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. namespace SC.XR.Unity
  8. {
  9. public abstract class RemoteSingleton<T> : MonoBehaviour where T : MonoBehaviour
  10. {
  11. public GameObject[] Prefab;
  12. [HideInInspector]
  13. public List<GameObject> window=new List<GameObject>();
  14. private static T instance;
  15. private static object lockObj = new object();
  16. public static T Instance
  17. {
  18. get
  19. {
  20. return instance;
  21. }
  22. }
  23. public virtual void Awake()
  24. {
  25. instance = (T)FindObjectOfType(typeof(T));
  26. ScenesManager.Instance.initWindow(this.gameObject);
  27. }
  28. public virtual void initShow()
  29. {
  30. if(Prefab!=null&& window.Count<=0)
  31. {
  32. for (int i = 0; i < Prefab.Length; i++)
  33. {
  34. window.Add(GameObject.Instantiate(Prefab[i], this.transform));
  35. window[window.Count - 1].name = Prefab[i].name;
  36. }
  37. }
  38. }
  39. }
  40. }