123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- 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<Module_InputSystem.Module_InputSystem>(true);
- }
- return inputSystem;
- }
- }
- Coroutine enableCoroutine = null;
- private SvrManager svrManager;
- public SvrManager SvrManager {
- get {
- if(svrManager == null) {
- svrManager = GetComponentInChildren<SvrManager>(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);
- }
- }
- }
|