本地化
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace AibisDream.Framework
|
||||
{
|
||||
@@ -69,5 +72,39 @@ namespace AibisDream.Framework
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static T LoadAddressableSync<T>(string key)
|
||||
{
|
||||
T result = default;
|
||||
var operation = Addressables.LoadAssetAsync<T>(key);
|
||||
|
||||
// 运行协程等待加载完成
|
||||
GameManager.Instance.StartCoroutine(LoadCoroutine(operation, loadedObject => result = loadedObject));
|
||||
|
||||
// 等待协程完成(阻塞主线程)
|
||||
while (!operation.IsDone)
|
||||
{
|
||||
// 主动让出一帧
|
||||
System.Threading.Thread.Sleep(1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IEnumerator LoadCoroutine<T>(AsyncOperationHandle<T> operation, Action<T> onComplete)
|
||||
{
|
||||
yield return operation;
|
||||
|
||||
if (operation.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
onComplete?.Invoke(operation.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Failed to load addressable");
|
||||
}
|
||||
|
||||
Addressables.Release(operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user