unityzgy/Assets/Scripts/PublicTool/AssetsManager.cs
ayuan9957 1481c1c6f3 fix: 统一装备图标 + 评估翻译 + 警告清理 + 连续训练修复
- EditorContentCtrl: 统一使用carIcon.png作为所有装备图标
- TransportScoreCtrl: 添加LanguageChanged订阅实时翻译最短耗时/转运耗时
- AppraiseSliderCtrl: 评价指标名称用Get()翻译
- WaitResultPanel: 评价等级用Get()翻译避免先闪中文
- EditorAppraiser: 厂区距离提示中厂区名称先Get()翻译
- GameObjectManager: 距离提示用Get()翻译
- StudentSub2EditorPanel: Text_terrainName同步+实时翻译, SetPromptLocalized
- StudentSub1EditorPanel: 地形名SetFormatted+DisplayName实时翻译
- Subject1EditorCtrl: InitCarIcon用RemoveAll+CreatChildren重建
- Subject2EditorCtrl: 编辑想定设置地形下拉框, CreatOnMapCar回退装备列表图标
- SubStart: 车辆列表为空时回退CameraPos定位相机
- StreamingAssetsManager: 移除GetPath中Debug.LogWarning
- 5吨火炮拆装车_Tex替换为统一图标
- 新增评估因素/分组错误翻译条目
- 所有UI预制体verticalOverflow改为Overflow
2026-08-04 14:10:01 +08:00

136 lines
4.2 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Threading.Tasks;
using System.Threading;
using UnityEngine.Networking;
using System.Collections;
using UnityEngine.Events;
/// <summary>
/// 与Editor/GenerateAssetsConfig 配合使用 快速获取资源整路径
/// </summary>
namespace XFramework
{
public class ResourcesManager
{
static ResourcesManager()
{
//txt>dic
Load();
}
//记录预制件名称以及其对应的预制件路径
static private Dictionary<string, string> dic = new Dictionary<string, string>();
static private void Load()
{
//加载配置文件,文本类型
TextAsset textAsset = Resources.
Load<TextAsset>("ResMap");
if (textAsset == null)
{
Debug.LogError("未生成ResMap,确定不使用RM功能时可忽略");
return;
}
string mapText = textAsset.text;
//读配置文件 对文本逐行读取
StringReader reader = new StringReader(mapText);
string line = null;
while ((line = reader.ReadLine()) != null)
{
string[] keyValue = line.Split('=');
dic.Add(keyValue[0], keyValue[1]);
}
}
//需要调用的方法 key value
static private string GetValue(string key)
{
if (dic.ContainsKey(key))
{ return dic[key]; }
Debug.LogError($"ResMap中不存在{key}");
return null;
}
////路径》得到对象 【预制件】 path=BaseMeleeAttackSkill
//public static async Task<Object> Load(string path)
//{
// //Skill/BaseMeleeAttackSkill
// ResourceRequest request = Resources.LoadAsync<Object>(GetValue(path));
// await request;
// return request.asset;
//}
public static T Load<T>(string resName) where T :Object
{
return Resources.Load<T>(GetValue(resName));
}
//获取资源完整路径
public static string GetPath(string prefabName)
{
return GetValue(prefabName);
}
}
public class StreamingAssetsManager
{
static string streamingAssetaPath; //移动平台待测试
static StreamingAssetsManager()
{
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
streamingAssetaPath = Application.streamingAssetsPath;
#elif UNITY_ANDROID || UNITY_IPHONE
streamingAssetaPath = Application.persistentDataPath;
#endif
//txt>dic
Load();
}
//记录预制件名称以及其对应的预制件路径
static private Dictionary<string, string> dic = new Dictionary<string, string>();
//加载本地配置文件
static private void Load()
{
//加载配置文件,文本类型
string mapText = File.ReadAllText(streamingAssetaPath + "/SAMap.txt");
//读配置文件 对文本逐行读取
StringReader reader = new StringReader(mapText);
string line = null;
while ((line = reader.ReadLine()) != null)
{
string[] keyValue = line.Split('=');
dic.Add(keyValue[0], keyValue[1]);
}
}
/// <summary>
/// 获取完整路径
/// </summary>
/// <param name="assetsName"></param>
/// <returns></returns>
public static string GetPath(string assetsName)
{
if (dic.ContainsKey(assetsName))
{
return $"{streamingAssetaPath}/{dic[assetsName]}";
}
else
{
return null;
}
}
public IEnumerator Load<T>(string url,UnityAction<T> loaded) where T: Object
{
UnityWebRequest webRequest = UnityWebRequest.Get(url);
yield return webRequest.SendWebRequest();
if (webRequest.isDone&& webRequest.error == null)
{
//loaded.Invoke(webRequest.downloadHandler.)
}
}
}
}