- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg) - LoginPanel: InputField placeholder本地化、字体颜色保持 - HistoryPanel: 用时数据本地化、placeholder本地化 - RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建) - AppraiseWindowBase: 评价等级本地化、操作消息重建 - EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized - StudentOperateRecorder: 新增InjectOperateMsgLocalized方法 - LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选 - 字体切换时保留颜色和verticalOverflow
173 lines
5.9 KiB
C#
173 lines
5.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.Networking;
|
|
using XFramework;
|
|
|
|
public static class OutSpriteLoader
|
|
{
|
|
|
|
public static Dictionary<string, Sprite> loadedSpriteDic = new Dictionary<string, Sprite>();
|
|
public static Dictionary<string, Texture2D> loadedTextureDic = new Dictionary<string, Texture2D>();
|
|
|
|
//public async Task<Texture> LoadTexture(string path)
|
|
//{
|
|
// //if (OutTextureManager.loadedTexture.ContainsKey(path))
|
|
// // loadedAction?.Invoke(OutTextureManager.loadedTexture[path]);
|
|
// //else
|
|
// //{
|
|
// var request = UnityWebRequestTexture.GetTexture(path);
|
|
// await request;
|
|
// Texture texture=null;
|
|
// if (DownloadHandlerTexture.GetContent(request) != null)
|
|
// {
|
|
// texture = DownloadHandlerTexture.GetContent(request);
|
|
// OutTextureManager.loadedTexture.Add(path, texture);
|
|
// }
|
|
// else
|
|
// {
|
|
// Debug.Log("图片加载失败,请确认名称是否正确");
|
|
// }
|
|
// //loadedAction?.Invoke(texture);
|
|
// //}
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 加载多张图片
|
|
/// </summary>
|
|
/// <param name="paths"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Texture2D []> LoadTexture(string [] paths)
|
|
{
|
|
Texture2D[] textures = new Texture2D[paths.Length];
|
|
Dictionary<string, Task<Texture2D>> allTasksDic = new Dictionary<string, Task<Texture2D>>();
|
|
for (int i = 0; i < paths.Length; i++)
|
|
{
|
|
if (string.IsNullOrEmpty(paths[i]))
|
|
{
|
|
textures[i] = default(Texture2D);
|
|
}
|
|
else if (loadedTextureDic.ContainsKey(paths[i]))
|
|
{
|
|
textures[i] = loadedTextureDic[paths[i]];
|
|
}
|
|
else if(!allTasksDic.ContainsKey(paths[i]))
|
|
{
|
|
allTasksDic.Add(paths[i], LoadAsyncTexture(paths[i]));
|
|
}
|
|
}
|
|
await Task.WhenAll(allTasksDic.Values);//等待所有需要加载的图片完成加载
|
|
for (int i = 0; i < paths.Length; i++)
|
|
{
|
|
if (!string.IsNullOrEmpty(paths[i]) && allTasksDic.ContainsKey(paths[i]))
|
|
textures[i] = allTasksDic[paths[i]].Result;
|
|
}
|
|
return textures;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载一张图片
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Texture2D> LoadTexture(string path)
|
|
{
|
|
if (string.IsNullOrEmpty(path))
|
|
return default(Texture2D);
|
|
if (loadedTextureDic.ContainsKey(path))
|
|
return loadedTextureDic[path];
|
|
var task = LoadAsyncTexture(path);
|
|
Task<Texture2D> t = await Task.WhenAny(task);
|
|
return t.Result;
|
|
}
|
|
|
|
|
|
public static async Task<Sprite[]> LoadSprites(string[] paths)
|
|
{
|
|
Sprite[] sprites = new Sprite[paths.Length];
|
|
Dictionary<string, Task<Sprite>> allTasksDic = new Dictionary<string, Task<Sprite>>();
|
|
for (int i = 0; i < paths.Length; i++)
|
|
{
|
|
if (string.IsNullOrEmpty(paths[i]))
|
|
{
|
|
sprites[i] = GetDefultSprite();
|
|
}
|
|
else if (loadedSpriteDic.ContainsKey(paths[i]))
|
|
{
|
|
sprites[i] = loadedSpriteDic[paths[i]];
|
|
}
|
|
else if (!allTasksDic.ContainsKey(paths[i]))
|
|
{
|
|
allTasksDic.Add(paths[i], LoadAsyncSprite(paths[i]));
|
|
}
|
|
}
|
|
await Task.WhenAll(allTasksDic.Values);//等待所有需要加载的图片完成加载
|
|
for (int i = 0; i < paths.Length; i++)
|
|
{
|
|
if (!string.IsNullOrEmpty(paths[i]) && allTasksDic.ContainsKey(paths[i]))
|
|
sprites[i] = allTasksDic[paths[i]].Result;
|
|
}
|
|
return sprites;
|
|
}
|
|
|
|
public static async Task<Sprite> LoadSprite(string path)
|
|
{
|
|
if (string.IsNullOrEmpty(path))//无效路径返回一个默认的图标
|
|
{
|
|
return GetDefultSprite();
|
|
}
|
|
if (loadedSpriteDic.ContainsKey(path))
|
|
return loadedSpriteDic[path];
|
|
var task = LoadAsyncSprite(path);
|
|
Task<Sprite> t = await Task.WhenAny(task);
|
|
return t.Result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取一个默认的Sprite"?" 避免出现空图标
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
static Sprite GetDefultSprite()
|
|
{
|
|
if (!loadedSpriteDic.ContainsKey("defaultSprite"))
|
|
{
|
|
Texture2D tex = new Texture2D(2, 2);
|
|
tex.LoadImage(null);
|
|
Vector2 pivot = new Vector2(0.5f, 0.5f);
|
|
Sprite sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), pivot, 100.0f);
|
|
loadedSpriteDic.Add("defaultSprite", sprite);
|
|
}
|
|
return loadedSpriteDic["defaultSprite"];
|
|
}
|
|
|
|
|
|
static async Task<Sprite> LoadAsyncSprite(string url)
|
|
{
|
|
//string path = Path.Combine(Application.streamingAssetsPath, url + end);
|
|
var getRequest = UnityWebRequest.Get(url);
|
|
await getRequest.SendWebRequest();
|
|
byte[] imgData = getRequest.downloadHandler.data;
|
|
Texture2D tex = new Texture2D(2, 2);
|
|
tex.LoadImage(imgData);
|
|
Vector2 pivot = new Vector2(0.5f, 0.5f);
|
|
Sprite sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), pivot, 100.0f);
|
|
loadedSpriteDic.Add(url, sprite);
|
|
return sprite;
|
|
}
|
|
|
|
|
|
static async Task<Texture2D> LoadAsyncTexture(string url)
|
|
{
|
|
//string path = Path.Combine(Application.streamingAssetsPath, url + end);
|
|
var getRequest = UnityWebRequestTexture.GetTexture(url);
|
|
await getRequest.SendWebRequest();
|
|
Texture2D tex = DownloadHandlerTexture.GetContent(getRequest);
|
|
loadedTextureDic.Add(url, tex);
|
|
return tex;
|
|
}
|
|
|
|
}
|