This commit is contained in:
CortexCore
2024-12-25 11:35:30 +08:00
parent 5b7ac3c361
commit b12511b825
8 changed files with 100 additions and 63 deletions

View File

@@ -18,6 +18,7 @@ namespace BITKit
{
public class BITFramework : MonoBehaviour
{
public static BITFramework Singleton { get; private set; }
private static System.Diagnostics.Stopwatch Stopwatch;
[RuntimeInitializeOnLoadMethod]
@@ -29,17 +30,6 @@ namespace BITKit
SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate);
#endif
}
// [SerializeField] private AssetReference serviceReference;
// private async void Start()
// {
// if(InitializationState is not InitializationState.None)return;
// InitializationState = InitializationState.Initializing;
// var asyncOperationHandle = serviceReference.LoadAssetAsync<GameObject>();
// await UniTask.WaitUntil(() => asyncOperationHandle.IsDone);
// DontDestroyOnLoad(Instantiate(asyncOperationHandle.Result));
// Stopwatch.Stop();
// BIT4Log.Log<BITFramework>($"BITFramework加载完成,耗时:{Stopwatch.ElapsedMilliseconds}ms");
// }
[SerializeReference, SubclassSelector] private IReference addressableName;
[SerializeReference, SubclassSelector] private IReference packageName = new Reference("DefaultPackage");
@@ -69,6 +59,7 @@ namespace BITKit
private Action<string> _setProgressLabel;
private async void Start()
{
Singleton = this;
try
{
#if UNITY_EDITOR
@@ -151,10 +142,18 @@ namespace BITKit
}
}
#endif
if (isOffline)
#if UNITY_5_3_OR_NEWER
if (IsEditorSimulateMode is false && isOffline)
{
initParameters = new OfflinePlayModeParameters();
}
#else
if (isOffline)
{
initParameters = new OfflinePlayModeParameters();
}
#endif
InitializationOperation initOperation = null;
try
@@ -312,30 +311,7 @@ namespace BITKit
YooAssetUtils.RegisterPackage(packageName.Value);
YooAssetUtils.RegisterResourcePackage(package);
if (loadEntryScene.Allow)
{
_progressLabel.text="正在加载场景...";
try
{
await package.LoadSceneAsync(loadEntryScene.Value);
_progressLabel.text="场景加载完成...";
}
catch (Exception e)
{
Debug.LogException(e);
await UniTask.NextFrame();
_progressLabel.text = e.Message;
}
}
else
{
_progressLabel.text="未找到默认场景,正在加载场景[1]";
SceneManager.LoadScene(1);
}
if (document)
Destroy(document);
await AfterInit(package);
}
catch (Exception e)
{
@@ -343,9 +319,35 @@ namespace BITKit
_progressBar.value =0;
_progressLabel.text = e.Message;
}
}
private async UniTask AfterInit(ResourcePackage package)
{
if (loadEntryScene.Allow)
{
_progressLabel.text="正在加载场景...";
try
{
await package.LoadSceneAsync(loadEntryScene.Value);
_progressLabel.text="场景加载完成...";
}
catch (Exception e)
{
Debug.LogException(e);
await UniTask.NextFrame();
_progressLabel.text = e.Message;
}
}
else
{
_progressLabel.text="未找到默认场景,正在加载场景[1]";
SceneManager.LoadScene(1);
}
if (document)
Destroy(document);
}
private void OnDestroy()
{
#if UNITY_EDITOR