using System; using System.Collections; using System.Collections.Generic; using BITKit; using MeshCombineStudio; using UnityEngine; namespace BITFALL.OpenWorld { public class RuntimeChunkCombineService : MonoBehaviour { public static RuntimeChunkCombineService Singleton { get; private set; } public void Register(GameObject root) { _Roots.Add(root); _IsDirty = true; } public void UnRegister(GameObject root) { _Roots.Remove(root); _IsDirty = true; } private readonly List _Roots = new(); [SerializeField] private MeshCombiner meshCombiner; private bool _IsDirty; [SerializeReference, SubclassSelector] private ITicker ticker; private void Awake() { Singleton = this; } private void Start() { ticker.Add(Tick); destroyCancellationToken.Register(Dispose); _Roots.AddRange(meshCombiner.searchOptions.parentGOs); } private void Dispose() { ticker.Remove(Tick); } private void Tick(float obj) { if (!_IsDirty) return; meshCombiner.ClearMeshCombineJobs(); meshCombiner.searchOptions.parentGOs = _Roots.ToArray(); meshCombiner.CombineAll(); } } }