1
This commit is contained in:
@@ -60,7 +60,7 @@ namespace BITKit.OpenWorld
|
||||
#if UNITY_EDITOR
|
||||
[BIT]
|
||||
#endif
|
||||
private void CalculateBounds()
|
||||
public void CalculateBounds()
|
||||
{
|
||||
if (TryGetComponent<Collider>(out var _collider))
|
||||
{
|
||||
|
@@ -25,7 +25,6 @@ namespace BITKit.OpenWorld
|
||||
private readonly ConcurrentDictionary<int, IWorldChunkObject> dictionary=new();
|
||||
|
||||
[SerializeReference, SubclassSelector] private ITicker ticker;
|
||||
[SerializeReference, SubclassSelector] private ISceneService sceneService;
|
||||
[SerializeField, ReadOnly] private int count;
|
||||
[SerializeField, ReadOnly] private int tickTaskCount;
|
||||
[SerializeField] private bool drawBounds;
|
||||
@@ -42,24 +41,13 @@ namespace BITKit.OpenWorld
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
sceneService?.RegisterLoadTaskAsync(LoadTask);
|
||||
ticker.Add(OnTick);
|
||||
destroyCancellationToken.Register(Dispose);
|
||||
_quadtree = new QuadtreeRoot<IWorldChunkObject, Node<IWorldChunkObject>>(transform.position, size);
|
||||
_camera = Camera.main;
|
||||
}
|
||||
private async UniTask LoadTask()
|
||||
{
|
||||
var frame=0;
|
||||
while (count is 0 || frame++<32)
|
||||
{
|
||||
if (destroyCancellationToken.IsCancellationRequested) return;
|
||||
await UniTask.NextFrame();
|
||||
}
|
||||
}
|
||||
protected virtual void Dispose()
|
||||
{
|
||||
sceneService?.UnRegisterLoadTaskAsync(LoadTask);
|
||||
ticker.Remove(OnTick);
|
||||
_registerQueue.Clear();
|
||||
_unregisterQueue.Clear();
|
||||
|
@@ -14,6 +14,7 @@ namespace BITKit.OpenWorld
|
||||
{
|
||||
public class WorldTerrainBehaviour : MonoBehaviour,IWorldChunkObject
|
||||
{
|
||||
public static UniTaskCompletionSource WaitUntilInitialized = new();
|
||||
[SerializeReference, SubclassSelector] private IReference sceneName;
|
||||
[SerializeField] private Vector3 size;
|
||||
[SerializeField] private Vector3 position;
|
||||
@@ -26,7 +27,15 @@ namespace BITKit.OpenWorld
|
||||
var stopWatcher = new System.Diagnostics.Stopwatch();
|
||||
stopWatcher.Start();
|
||||
_sceneHandle = YooAssets.LoadSceneAsync(sceneName.Value,LoadSceneMode.Additive,priority:8);
|
||||
await _sceneHandle;
|
||||
try
|
||||
{
|
||||
await _sceneHandle.WithCancellation(destroyCancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
stopWatcher.Stop();
|
||||
Debug.Log($"加载场景 {sceneName.Value} 耗时 {stopWatcher.ElapsedMilliseconds}ms");
|
||||
}
|
||||
|
Reference in New Issue
Block a user