This commit is contained in:
CortexCore
2024-03-31 23:31:00 +08:00
parent e179d2eb53
commit b7b89ee71a
641 changed files with 31286 additions and 22134 deletions

View File

@@ -1,10 +1,12 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BITKit.IO;
using Cysharp.Threading.Tasks;
using UnityEngine;
@@ -105,6 +107,8 @@ namespace BITKit.SceneManagement
private readonly Dictionary<string, Scene> LoadedObjects = new();
private CancellationToken _cancellationToken;
private readonly ConcurrentDictionary<string,ResourcePackage> _packages=new();
private void Awake()
{
Singleton = this;
@@ -126,8 +130,25 @@ namespace BITKit.SceneManagement
public string[] GetScenes(params string[] tags)
{
var infos = YooAssets.GetAssetInfos(tags);
return infos.Where(x=>x.Address.Split("_")[0] is "Maps").Select(x=>x.Address).ToArray();
try
{
_packages.Clear();
var list = new List<string>();
foreach (var package in YooAssetUtils.RegisteredResourcePackages)
{
foreach (var assetInfo in package.GetAssetInfos(tags))
{
list.Add(assetInfo.Address);
_packages.TryAdd(assetInfo.Address,package);
}
}
return list.ToArray();
}
catch (Exception e)
{
BIT4Log.Warning<ISceneService>(JsonHelper.Get(YooAssetUtils.RegisteredPackages) );
throw;
}
}
public async UniTask LoadSceneAsync(string sceneName, CancellationToken cancellationToken,
@@ -166,7 +187,10 @@ namespace BITKit.SceneManagement
// }
var sceneMode = UnityEngine.SceneManagement.LoadSceneMode.Single;
var handle = YooAssets.LoadSceneAsync(sceneName, sceneMode);
var package = _packages[sceneName];
var handle = package.LoadSceneAsync(sceneName, sceneMode);
while (handle.IsDone is false)
{
var progress = handle.Progress;
@@ -176,7 +200,7 @@ namespace BITKit.SceneManagement
LoadedObjects.Add(sceneName, handle.SceneObject);
OnSceneLoadProgress?.Invoke(sceneName, 1);
await Task.Delay(100, cancellationToken);
await Task.Delay(384, cancellationToken);
OnSceneLoaded?.Invoke(sceneName);
stopwatchWatcher.Stop();
// if (activateOnLoad is false)