1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using UnityEngine;
- using static ScenesManager;
- namespace SC.XR.Unity
- {
- public abstract class RemoteSingleton<T> : MonoBehaviour where T : MonoBehaviour
- {
- public GameObject[] Prefab;
- [HideInInspector]
- public List<GameObject> window=new List<GameObject>();
- private static T instance;
- private static object lockObj = new object();
- public static T Instance
- {
- get
- {
- return instance;
- }
- }
- public virtual void Awake()
- {
- instance = (T)FindObjectOfType(typeof(T));
- ScenesManager.Instance.initWindow(this.gameObject);
- }
- public virtual void initShow()
- {
- if(Prefab!=null&& window.Count<=0)
- {
- for (int i = 0; i < Prefab.Length; i++)
- {
- window.Add(GameObject.Instantiate(Prefab[i], this.transform));
- window[window.Count - 1].name = Prefab[i].name;
- }
- }
- SceneType stp = (SceneType)System.Enum.Parse(typeof(SceneType), this.gameObject.name.Split('(')[0]);
- int codeint = stp.GetHashCode() / 10000;
- if(codeint!=50)
- {
- for (int i = 0; i < window.Count; i++)
- {
- window[i].SetActive(false);
- }
- if (window.Count > 0)
- window[0].SetActive(true);
- }
- }
- public void gotoWindow(SceneType sc)
- {
- SceneType stp = (SceneType)System.Enum.Parse(typeof(SceneType), this.name.Split('(')[0]);
- int idx = sc - stp- 1000;
- Debug.Log("gotoWindow = "+idx);
- for (int i = 0; i < window.Count; i++)
- {
- if(i== idx)
- {
- window[i].SetActive(true);
- }else
- {
- window[i].SetActive(false);
- }
- }
- }
- }
- }
|