using System; using System.Collections; using System.Collections.Generic; using Cysharp.Threading.Tasks; using UnityEngine; using Sirenix.OdinInspector; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.Serialization; public class NLDSceneManager : MonoBehaviour { public static NLDSceneManager instance; [FormerlySerializedAs("_sceneObjects")] [ReadOnly] [HideInInspector] [SerializeField] public List sceneObjects = new(); [ReadOnly] [SerializeField] [HideInInspector] public List allSceneSurfaceData = new(); [HideInInspector] [SerializeField] private bool _allSurface; public bool UseAllSurface { get => _allSurface; set { if (_allSurface != value) { _allSurface = value; foreach (var sceneObj in sceneObjects) { if(sceneObj) sceneObj.UseSurface = value; } } } } private Dictionary> _sceneObjTypeDic = new(); private Dictionary _sceneSurfaceDataDic = new(); public void Refresh() { _sceneObjTypeDic.Clear(); foreach (var sObj in sceneObjects) { if (sObj == null) continue; var type = sObj.sceneObjectType; if (_sceneObjTypeDic.TryGetValue(type, out var list)) { list.Add(sObj); } else { list = new(); list.Add(sObj); _sceneObjTypeDic.Add(type, list); } } _sceneSurfaceDataDic.Clear(); foreach (var surfaceData in allSceneSurfaceData) { _sceneSurfaceDataDic.TryAdd(surfaceData.renderInfo, surfaceData); } } private void Awake() { instance = this; Refresh(); } private void OnDestroy() { instance = null; } public List GetSceneObjectsByType(ESceneObjectType type) { return _sceneObjTypeDic.GetValueOrDefault(type); } public SceneSurfaceData GetSurfaceData(SceneObjectRenderInfo renderInfo) { return _sceneSurfaceDataDic.GetValueOrDefault(renderInfo); } }