本地化问题修改

This commit is contained in:
2025-05-09 18:54:30 +08:00
parent 107a6cbc4b
commit e7b30e25e5
17 changed files with 635 additions and 210 deletions
@@ -13,7 +13,7 @@ namespace AibisDream.Framework
{
#if UNITY_EDITOR
if (!sprite) return "";
// 先读Psd的路径
string psdPath = AssetDatabase.GetAssetPath(sprite);
var psdResPath = GetResourcePath(psdPath);
@@ -28,13 +28,12 @@ namespace AibisDream.Framework
// 提取文件名(不包括扩展名)
var purePath = psdResPath.Substring(0, lastDotIndex);
// 添加后缀
return purePath + "/" + sprite.name;
#else
return null;
#endif
}
private static string GetResourcePath(string absolutePath)
@@ -42,15 +41,7 @@ namespace AibisDream.Framework
const string resourcesFolderName = "Resources/";
int index = absolutePath.IndexOf(resourcesFolderName, StringComparison.Ordinal);
if (index >= 0)
{
// 获取 "Resources/" 之后的部分
return absolutePath.Substring(index + resourcesFolderName.Length);
}
else
{
return absolutePath;
}
return index >= 0 ? absolutePath[(index + resourcesFolderName.Length)..] : absolutePath;
}
public static Sprite LoadSpriteFromPsd(string path)
@@ -58,7 +49,7 @@ namespace AibisDream.Framework
int lastIndex = path.LastIndexOf('/');
string spriteName = path.Substring(lastIndex + 1);
string resPath = path.Substring(0, lastIndex);
// 加载
var sprites = Resources.LoadAll<Sprite>(resPath);
@@ -72,39 +63,14 @@ namespace AibisDream.Framework
return null;
}
public static T LoadAddressableSync<T>(string key)
public static T LoadAssetSync<T>(string key) where T : UnityEngine.Object
{
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);
}
operation.WaitForCompletion();
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);
return operation.Result;
}
}
}