using System; using System.Collections; using System.Collections.Generic; using System.Linq; using Cysharp.Threading.Tasks; using UnityEngine; using Sirenix.OdinInspector; using UnityEditor; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.Serialization; public class NLDSceneManager : MonoBehaviour { public const string ART_NAME = "Art"; 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; } } } } [SerializeField] [HideInInspector] private Transform _art; public Transform Art { get { if (_art == null) { var scene = gameObject.scene; var roots = scene.GetRootGameObjects(); var artGo = roots.FirstOrDefault(r => r.name == ART_NAME); if (artGo == null) { artGo = ObjectFactory.CreateGameObject(scene, HideFlags.None, ART_NAME); } _art = artGo.transform; } return _art; } } 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); } }