123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- 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<Module_DetectorSystem>("Prefabs/DetectorSystem");
- instance = GameObject.Instantiate(prefab);
- instance.Init();
- }
- }
- }
- return instance;
- }
- }
-
- private List<SCBaseDetector> m_SCDetectorList;
- public List<SCBaseDetector> SCDetectorList
- {
- get
- {
- if (m_SCDetectorList == null)
- {
- m_SCDetectorList = new List<SCBaseDetector>();
- SCBaseDetector[] scBaseDetectorList = GetComponentsInChildren<SCBaseDetector>(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<T>(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<SCBaseDetector>(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;
- }
- }
- }
|