增加aa加载包和重做标签系统包
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 加载可寻址资源目录
|
||||
/// </summary>
|
||||
public class AACatalog {
|
||||
public readonly string filePath;
|
||||
public Action<float> OnProgress;
|
||||
public Action<string> OnError;
|
||||
public Action OnComplete;
|
||||
|
||||
/// <summary> 加载可寻址资源目录 </summary>
|
||||
public AACatalog(string filePath, Action OnComplete = null) {
|
||||
this.filePath = filePath;
|
||||
this.OnComplete = OnComplete;
|
||||
}
|
||||
/// <summary> 获取异步句柄 </summary>
|
||||
public AsyncOperationHandle<IResourceLocator> Handle() {
|
||||
return Addressables.LoadContentCatalogAsync(filePath, true);
|
||||
}
|
||||
/// <summary> 加载目录 </summary>
|
||||
public async void Load() => await ALoad();
|
||||
/// <summary> 加载目录 </summary>
|
||||
public async Task ALoad() {
|
||||
AsyncOperationHandle<IResourceLocator> handle = Handle();
|
||||
if (handle.Status == AsyncOperationStatus.Failed) {
|
||||
OnError?.Invoke($"无法加载资源目录!({filePath})"); return;
|
||||
}
|
||||
while (!handle.IsDone) {
|
||||
float downloadProgress = handle.GetDownloadStatus().Percent;
|
||||
float loadProgress = handle.PercentComplete;
|
||||
float totalProgress = (downloadProgress + loadProgress) / 2.0f;
|
||||
// Debug.Log($"下载进度: {downloadProgress * 100}% , 加载进度: {loadProgress * 100}% , 总进度: {totalProgress * 100}%");
|
||||
OnProgress?.Invoke(totalProgress);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
OnComplete?.Invoke();
|
||||
}
|
||||
/// <summary> 加载目录 </summary>
|
||||
public IEnumerator ILoad() {
|
||||
AsyncOperationHandle<IResourceLocator> handle = Handle();
|
||||
if (handle.Status == AsyncOperationStatus.Failed) {
|
||||
OnError?.Invoke($"无法加载资源目录!({filePath})");
|
||||
yield break;
|
||||
}
|
||||
while (!handle.IsDone) {
|
||||
float downloadProgress = handle.GetDownloadStatus().Percent;
|
||||
float loadProgress = handle.PercentComplete;
|
||||
float totalProgress = (downloadProgress + loadProgress) / 2.0f;
|
||||
OnProgress?.Invoke(totalProgress);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
OnComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdf535680c5435444845cfa205c9619f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 从目录加载场景
|
||||
/// </summary>
|
||||
public class AACatalogToScene {
|
||||
public enum Progress { Catalog, Label, Scene }
|
||||
public readonly string filePath;
|
||||
public readonly string sceneName;
|
||||
public readonly LoadSceneMode loadSceneMode;
|
||||
public readonly bool activateOnLoad;
|
||||
public Action<float, Progress> OnProgress;
|
||||
public Action<string> OnError;
|
||||
public Action OnComplete;
|
||||
|
||||
/// <summary> 加载可寻址资源目录 </summary>
|
||||
public AACatalogToScene(string filePath, string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single, bool activateOnLoad = true) {
|
||||
this.filePath = filePath;
|
||||
this.sceneName = sceneName;
|
||||
this.loadSceneMode = loadSceneMode;
|
||||
this.activateOnLoad = activateOnLoad;
|
||||
}
|
||||
/// <summary> 从目录加载场景 </summary>
|
||||
public async void Load() => await ALoad();
|
||||
/// <summary> 从目录加载场景 </summary>
|
||||
public async Task ALoad() {
|
||||
AACatalog catalog = new AACatalog(filePath);
|
||||
catalog.OnProgress = (value) => { OnProgress?.Invoke(value, Progress.Catalog); };
|
||||
catalog.OnError = OnError;
|
||||
await catalog.ALoad();
|
||||
AAScene aaScene = new AAScene(sceneName, loadSceneMode, activateOnLoad);
|
||||
aaScene.OnProgress = (value) => { OnProgress?.Invoke(value, Progress.Scene); };
|
||||
aaScene.OnError = OnError;
|
||||
aaScene.OnComplete = OnComplete;
|
||||
await aaScene.ALoad();
|
||||
}
|
||||
/// <summary> 从目录加载场景 </summary>
|
||||
public IEnumerator ILoad() {
|
||||
AACatalog catalog = new AACatalog(filePath);
|
||||
catalog.OnProgress = (value) => { OnProgress?.Invoke(value, Progress.Catalog); };
|
||||
catalog.OnError = OnError;
|
||||
yield return catalog.ILoad();
|
||||
AAScene aaScene = new AAScene(sceneName, loadSceneMode, activateOnLoad);
|
||||
aaScene.OnProgress = (value) => { OnProgress?.Invoke(value, Progress.Scene); };
|
||||
aaScene.OnError = OnError;
|
||||
aaScene.OnComplete = OnComplete;
|
||||
yield return aaScene.ILoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8003e83f422c6e4797a12c63bf25406
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 按标签加载可寻址资源
|
||||
/// </summary>
|
||||
public class AALabel<T> {
|
||||
public readonly string label;
|
||||
public Action<float> OnProgress;
|
||||
public Action<string> OnError;
|
||||
public Action<T> OnComplete;
|
||||
public T result;
|
||||
|
||||
/// <summary> 按标签加载可寻址资源 </summary>
|
||||
public AALabel(string label, Action<T> OnComplete = null) {
|
||||
this.label = label;
|
||||
this.OnComplete = OnComplete;
|
||||
}
|
||||
/// <summary> 获取异步句柄 </summary>
|
||||
public AsyncOperationHandle<T> Handle() {
|
||||
return Addressables.LoadAssetAsync<T>(label);
|
||||
}
|
||||
/// <summary> 加载资源 </summary>
|
||||
public async void Load() => await ALoad();
|
||||
/// <summary> 加载资源 </summary>
|
||||
public async Task ALoad() {
|
||||
AsyncOperationHandle<T> handle = Handle();
|
||||
if (handle.Status == AsyncOperationStatus.Failed) {
|
||||
OnError?.Invoke($"无法加载资源!(label={label} , type={typeof(T)})"); return;
|
||||
}
|
||||
while (!handle.IsDone) {
|
||||
float downloadProgress = handle.GetDownloadStatus().Percent;
|
||||
float loadProgress = handle.PercentComplete;
|
||||
float totalProgress = (downloadProgress + loadProgress) / 2.0f;
|
||||
// Debug.Log($"下载进度: {downloadProgress * 100}% , 加载进度: {loadProgress * 100}% , 总进度: {totalProgress * 100}%");
|
||||
OnProgress?.Invoke(totalProgress);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
OnComplete?.Invoke(handle.Result);
|
||||
}
|
||||
/// <summary> 加载资源 </summary>
|
||||
public IEnumerator ILoad() {
|
||||
AsyncOperationHandle<T> handle = Handle();
|
||||
if (handle.Status == AsyncOperationStatus.Failed) {
|
||||
OnError?.Invoke($"无法加载资源!(label={label} , type={typeof(T)})"); yield break;
|
||||
}
|
||||
while (!handle.IsDone) {
|
||||
float downloadProgress = handle.GetDownloadStatus().Percent;
|
||||
float loadProgress = handle.PercentComplete;
|
||||
float totalProgress = (downloadProgress + loadProgress) / 2.0f;
|
||||
OnProgress?.Invoke(totalProgress);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
result = handle.Result;
|
||||
OnComplete?.Invoke(handle.Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05c642602f45beb4391c7dbbd6b78968
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceProviders;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 加载可寻址场景
|
||||
/// </summary>
|
||||
public class AAScene {
|
||||
public readonly string name;
|
||||
public readonly LoadSceneMode loadSceneMode;
|
||||
public readonly bool activateOnLoad;
|
||||
public Action<float> OnProgress;
|
||||
public Action<string> OnError;
|
||||
public Action OnComplete;
|
||||
|
||||
/// <summary> 加载可寻址场景 </summary>
|
||||
public AAScene(string name, LoadSceneMode loadSceneMode = LoadSceneMode.Single, bool activateOnLoad = true) {
|
||||
this.name = name;
|
||||
this.loadSceneMode = loadSceneMode;
|
||||
this.activateOnLoad = activateOnLoad;
|
||||
}
|
||||
/// <summary> 获取异步句柄 </summary>
|
||||
public AsyncOperationHandle<SceneInstance> Handle() {
|
||||
return Addressables.LoadSceneAsync(name, loadSceneMode, activateOnLoad);
|
||||
}
|
||||
/// <summary> 加载场景 </summary>
|
||||
public async void Load() => await ALoad();
|
||||
/// <summary> 加载场景 </summary>
|
||||
public async Task ALoad() {
|
||||
AsyncOperationHandle<SceneInstance> handle = Handle();
|
||||
if (handle.Status == AsyncOperationStatus.Failed) {
|
||||
OnError?.Invoke($"无法加载场景!({name})"); return;
|
||||
}
|
||||
while (!handle.IsDone) {
|
||||
float downloadProgress = handle.GetDownloadStatus().Percent;
|
||||
float loadProgress = handle.PercentComplete;
|
||||
float totalProgress = (downloadProgress + loadProgress) / 2.0f;
|
||||
// Debug.Log($"下载进度: {downloadProgress * 100}% , 加载进度: {loadProgress * 100}% , 总进度: {totalProgress * 100}%");
|
||||
OnProgress?.Invoke(totalProgress);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
OnComplete?.Invoke();
|
||||
}
|
||||
/// <summary> 加载场景 </summary>
|
||||
public IEnumerator ILoad() {
|
||||
AsyncOperationHandle<SceneInstance> handle = Handle();
|
||||
if (handle.Status == AsyncOperationStatus.Failed) {
|
||||
OnError?.Invoke($"无法加载场景!({name})"); yield break;
|
||||
}
|
||||
while (!handle.IsDone) {
|
||||
float downloadProgress = handle.GetDownloadStatus().Percent;
|
||||
float loadProgress = handle.PercentComplete;
|
||||
float totalProgress = (downloadProgress + loadProgress) / 2.0f;
|
||||
OnProgress?.Invoke(totalProgress);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
OnComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68519b916d961c745aeba6680a8cafe3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "MuHua.AALoading",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26f33ddf2c81134458ea0d2283ffaaaa
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user