- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg) - LoginPanel: InputField placeholder本地化、字体颜色保持 - HistoryPanel: 用时数据本地化、placeholder本地化 - RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建) - AppraiseWindowBase: 评价等级本地化、操作消息重建 - EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized - StudentOperateRecorder: 新增InjectOperateMsgLocalized方法 - LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选 - 字体切换时保留颜色和verticalOverflow
148 lines
4.7 KiB
C#
148 lines
4.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using XFramework;
|
|
|
|
/// <summary>
|
|
/// 拖拽展示所有的数据框
|
|
/// </summary>
|
|
public class EditorContentCtrl : MonoBehaviour
|
|
{
|
|
public GameObject childPrefab;
|
|
Dictionary<string, IconBase> iconDic = new Dictionary<string, IconBase>();
|
|
[Header("需要更新图标样式时勾选")]
|
|
public bool needSprite;
|
|
[Header("内部数据时勾选 否则加载外部数据")]
|
|
public bool buildInSprite;
|
|
public Dictionary<string, IconBase> children { get { return iconDic; } }
|
|
/// <summary>
|
|
/// 创建一系列子物体 加载外部UI资源时 使用await等待资源加载完成 内部资源无需等待
|
|
/// </summary>
|
|
/// <param name="carsName">子物体预制件名称</param>
|
|
public async void CreatChildren(string[] carsName,UnityAction CreatOverEvent=null)
|
|
{
|
|
if (needSprite&& !buildInSprite)//需要加载外部多个资源时
|
|
{
|
|
string[] paths = new string[carsName.Length];
|
|
for (int i = 0; i < carsName.Length; i++)
|
|
{
|
|
paths[i] = StreamingAssetsManager.GetPath($"{carsName[i]}_Tex");
|
|
}
|
|
Sprite [] sprites= await OutSpriteLoader.LoadSprites(paths);
|
|
for (int i = 0; i < carsName.Length; i++)
|
|
{
|
|
IconBase icon = GetIcon(carsName[i]);
|
|
icon.SetSprite(sprites[i]);
|
|
CreatOverAndInitIcon(carsName[i],null,icon);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < carsName.Length; i++)
|
|
{
|
|
if (CreatOverEvent != null && i == carsName.Length - 1)//最后一个加载完成后 触发加载完成事件
|
|
{
|
|
AddChild(carsName[i], null);
|
|
//Debug.Log("开始加载最后一张图片");
|
|
}
|
|
else
|
|
AddChild(carsName[i]);
|
|
}
|
|
}
|
|
CreatOverEvent?.Invoke();
|
|
}
|
|
|
|
|
|
|
|
//名称重复时不生成新的元素 用新元素的数据覆盖原有的数据
|
|
public async void AddChild(string childName,object initMsg=null)
|
|
{
|
|
//Debug.Log(childName);
|
|
IconBase iconBase = GetIcon(childName);
|
|
if (needSprite)
|
|
{
|
|
Sprite sprite;
|
|
if (buildInSprite)
|
|
{
|
|
sprite = Resources.Load<Sprite>(ResourcesManager.GetPath(childName));
|
|
}
|
|
else
|
|
{
|
|
string path = StreamingAssetsManager.GetPath($"{childName}_Tex");
|
|
sprite = await OutSpriteLoader.LoadSprite(path);
|
|
}
|
|
iconBase.SetSprite(sprite);
|
|
}
|
|
CreatOverAndInitIcon(childName, initMsg, iconBase);
|
|
//createOver?.Invoke();
|
|
}
|
|
|
|
//图标创建完成 加入字典 设置初始化数据
|
|
private void CreatOverAndInitIcon(string childName, object initMsg, IconBase iconBase)
|
|
{
|
|
iconDic[childName] = iconBase;
|
|
iconBase.SetName(childName);
|
|
if (initMsg != null)
|
|
iconBase.SetUpdateIconMsg(initMsg);
|
|
}
|
|
|
|
//获取一个图标实例 优先从字典中获取避免重复 字典中不存在时创建
|
|
private IconBase GetIcon(string childName)
|
|
{
|
|
IconBase iconBase;
|
|
if (iconDic.ContainsKey(childName))
|
|
iconBase = iconDic[childName];
|
|
else
|
|
iconBase = Instantiate<GameObject>(childPrefab, this.transform).GetComponent<IconBase>();
|
|
return iconBase;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除一个元素
|
|
/// </summary>
|
|
/// <param name="childName"></param>
|
|
public void RemoveChild(string childName)
|
|
{
|
|
if (!iconDic.ContainsKey(childName)) return;
|
|
GameObject.Destroy(iconDic[childName].gameObject);
|
|
iconDic.Remove(childName);
|
|
DBManager.Instance.DeleteABMsg(childName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除所有元素
|
|
/// </summary>
|
|
public void RemoveAll()
|
|
{
|
|
foreach (var item in iconDic)
|
|
{
|
|
Destroy(item.Value.gameObject);
|
|
}
|
|
iconDic.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化图标
|
|
/// </summary>
|
|
/// <typeparam name="TKey">图标创建时指定的唯一标识类</typeparam>
|
|
/// <typeparam name="TValue">图标初始化数据类</typeparam>
|
|
/// <param name="msgDic">数据集合</param>
|
|
public void SetInitMsg<TKey,TValue>(Dictionary<TKey, TValue> msgDic)
|
|
{
|
|
if (msgDic != null)
|
|
{
|
|
foreach (var item in msgDic)
|
|
{
|
|
if (iconDic.ContainsKey(item.Key.ToString()))
|
|
{
|
|
iconDic[item.Key.ToString()].SetUpdateIconMsg(item.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|