using System.Collections; using System.Collections.Generic; using UnityEngine; namespace SC.XR.Unity.Module_DetectorSystem { public class Module_DetectorSystem : SCModuleMono { private static Module_DetectorSystem instance; private static object lockObj = new object(); public static Module_DetectorSystem Instance { get { if (instance == null) { lock (lockObj) { if (instance == null) { Module_DetectorSystem prefab = Resources.Load("Prefabs/DetectorSystem"); instance = GameObject.Instantiate(prefab); instance.Init(); } } } return instance; } } private List m_SCDetectorList; public List SCDetectorList { get { if (m_SCDetectorList == null) { m_SCDetectorList = new List(); SCBaseDetector[] scBaseDetectorList = GetComponentsInChildren(true); foreach (var baseDetector in scBaseDetectorList) { m_SCDetectorList.Add(baseDetector); } } return m_SCDetectorList; } } private bool activeBatteryDetector = false; private bool activeLanguageDetector = false; private bool activeNoNetworkDetector = false; private bool activeNoticeDetector = false; private bool activeRecorderDetector = false; private bool activeVolumeDetector = false; public override void OnSCAwake() { base.OnSCAwake(); instance = this; if (API_Module_SDKConfiguration.HasKey("Module_DetectorSystem", "ActiveBatteryDetector")) { activeBatteryDetector = API_Module_SDKConfiguration.GetBool("Module_DetectorSystem", "ActiveBatteryDetector", 0); } if (API_Module_SDKConfiguration.HasKey("Module_DetectorSystem", "ActiveLanguageDetector")) { activeLanguageDetector = API_Module_SDKConfiguration.GetBool("Module_DetectorSystem", "ActiveLanguageDetector", 0); } if (API_Module_SDKConfiguration.HasKey("Module_DetectorSystem", "ActiveNoNetworkDetector")) { activeNoNetworkDetector = API_Module_SDKConfiguration.GetBool("Module_DetectorSystem", "ActiveNoNetworkDetector", 0); } if (API_Module_SDKConfiguration.HasKey("Module_DetectorSystem", "ActiveNoticeDetector")) { activeNoticeDetector = API_Module_SDKConfiguration.GetBool("Module_DetectorSystem", "ActiveNoticeDetector", 0); } if (API_Module_SDKConfiguration.HasKey("Module_DetectorSystem", "ActiveRecorderDetector")) { activeRecorderDetector = API_Module_SDKConfiguration.GetBool("Module_DetectorSystem", "ActiveRecorderDetector", 0); } if (API_Module_SDKConfiguration.HasKey("Module_DetectorSystem", "ActiveVolumeDetector")) { activeVolumeDetector = API_Module_SDKConfiguration.GetBool("Module_DetectorSystem", "ActiveVolumeDetector", 0); } foreach (var detector in SCDetectorList) { if (GetFlag(detector.detectorType)) { AddModule(detector); } } } public override void OnSCStart() { base.OnSCStart(); SetActiveSCDetector(SCDetectorType.Battery, activeBatteryDetector); SetActiveSCDetector(SCDetectorType.Language, activeLanguageDetector); SetActiveSCDetector(SCDetectorType.NoNetwork, activeNoNetworkDetector); SetActiveSCDetector(SCDetectorType.Notice, activeNoticeDetector); SetActiveSCDetector(SCDetectorType.Recorder, activeRecorderDetector); SetActiveSCDetector(SCDetectorType.Volume, activeVolumeDetector); } public T GetSCBaseDetector(SCDetectorType type) where T : SCBaseDetector { foreach (var baseDetector in SCDetectorList) { if (type == baseDetector.detectorType) { return (T)baseDetector; } } return null; } public void SetActiveSCDetector(SCDetectorType type, bool active) { SCBaseDetector baseDetector = GetSCBaseDetector(type); if (baseDetector == null) return; SetFlag(type, active); if (active) { baseDetector.ModuleStart(); } else { baseDetector.ModuleStop(); } } private bool GetFlag(SCDetectorType type) { switch (type) { case SCDetectorType.Battery: return activeBatteryDetector; case SCDetectorType.Language: return activeLanguageDetector; case SCDetectorType.NoNetwork: return activeNoNetworkDetector; case SCDetectorType.Notice: return activeNoticeDetector; case SCDetectorType.Recorder: return activeRecorderDetector; case SCDetectorType.Volume: return activeVolumeDetector; default: return false; } } private void SetFlag(SCDetectorType type, bool active) { switch (type) { case SCDetectorType.Battery: activeBatteryDetector = active; break; case SCDetectorType.Language: break; case SCDetectorType.NoNetwork: activeNoNetworkDetector = active; break; case SCDetectorType.Notice: activeNoticeDetector = active; break; case SCDetectorType.Recorder: activeRecorderDetector = active; break; case SCDetectorType.Volume: activeVolumeDetector = active; break; } } private void Init() { instance.transform.SetParent(Module_SDKSystem.Module_SDKSystem.Instance.transform); instance.transform.name = "DetectorSystem"; instance.transform.position = Vector3.zero; instance.transform.rotation = Quaternion.identity; instance.transform.localScale = Vector3.one; } } }