using SC.XR.Unity; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using SC.XR.Unity.Module_InputSystem; namespace SC.XR.Unity.Module_ShadowSystem { public class Module_ShadowSystem : SCModuleMono { public static Module_ShadowSystem Instant; public bool EnableInutSystem = true; public bool EnableSvrCamera = true; public SlamSettings SlamSettings; public DeviceParam Device; public bool ShowDebugLog; bool isStart = false; public bool IsRunning { get; private set; } public bool Initialized { get; private set; } private Module_InputSystem.Module_InputSystem inputSystem; public Module_InputSystem.Module_InputSystem InputSystem { get { if(inputSystem == null) { inputSystem = GetComponentInChildren(true); } return inputSystem; } } Coroutine enableCoroutine = null; private SvrManager svrManager; public SvrManager SvrManager { get { if(svrManager == null) { svrManager = GetComponentInChildren(true); } return svrManager; } } private Coroutine updateWaitForEndOfFrame = null; #region MonoBehavior Driver void Awake() { ModuleInit(false); } void OnEnable() { if(updateWaitForEndOfFrame == null) { updateWaitForEndOfFrame = StartCoroutine(UpdateWaitForEndOfFrame()); } if(isStart == true) { ModuleStart(); } } void Start() { isStart = true; ModuleStart(); } void Update() { ModuleUpdate(); } void LateUpdate() { ModuleLateUpdate(); } void OnApplicationPause(bool pause) { if(isStart) { if(pause) { ModuleStop(); } else { ModuleStart(); } } } IEnumerator UpdateWaitForEndOfFrame() { while(true) { yield return new WaitForEndOfFrame(); if(InputSystem && InputSystem.IsModuleStarted) { InputSystem.ModuleEndOfFrame(); } } } void OnDisable() { if(updateWaitForEndOfFrame != null) { StopCoroutine(updateWaitForEndOfFrame); } ModuleStop(); } void OnDestroy() { ModuleDestroy(); isStart = false; } #endregion #region Module Behavoir public override void OnSCAwake() { base.OnSCAwake(); if(Instant != null) { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); Instant = this; DebugMy.isShowNormalLog = ShowDebugLog; SvrManager?.gameObject.SetActive(false); AddModule(InputSystem); //if(SlamModel && SlamModel.IsUseOtherSlam == true) { // if(SvrManager) { // DebugMy.Log("SlamModel.IsUseOtherSlam == true! Disable SVR", this); // SvrManager.gameObject.SetActive(false); // } // Debug.Log("Slam: Other"); //} else { // if(SvrManager) { // SvrManager.gameObject.SetActive(true); // } // Debug.Log("Slam: SVR"); //} if(Device) { Debug.Log("Device: " + Device.Current.type); } else { Debug.Log("Device: No DeviceParam"); } } public override void OnSCStart() { base.OnSCStart(); if(EnableInutSystem) { InputSystem?.ModuleStart(); } if(EnableSvrCamera) { SvrManager?.gameObject.SetActive(true); } if(enableCoroutine == null) { enableCoroutine = StartCoroutine(Running()); } } public override void OnSCDisable() { base.OnSCDisable(); IsRunning = false; //不能操作 灭屏唤醒否则起不来 //SvrManager?.gameObject.SetActive(false); } public override void OnSCDestroy() { base.OnSCDestroy(); StopAllCoroutines(); SvrManager?.gameObject.SetActive(false); } #endregion IEnumerator Running() { ///SLam model if(SvrManager && SvrManager.gameObject.activeSelf) { while(SvrManager.IsRunning == false) { yield return new WaitUntil(() => SvrManager.IsRunning == true); } } //if(Inputsystem && Inputsystem.gameObject.activeSelf) { // while(Inputsystem.GetComponent < Input > Initialize == false) { // yield return new WaitUntil(() => Inputsystem.Initialize == true); // } // //DebugMy.Log("InputSystem model Initialize !", this); //} IsRunning = true; DebugMy.Log("ShadowSystem Module IsRuning !", this); } } }