RedDotMgr_KeyAsset.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. using ET;
  3. using UnityEngine;
  4. using UnityObject = UnityEngine.Object;
  5. namespace YIUIFramework
  6. {
  7. public partial class RedDotMgr
  8. {
  9. private const string RedDotKeyAssetName = "RedDotKeyAsset";
  10. private readonly Dictionary<int, RedDotKeyData> m_AllRedDotKeyData = new();
  11. public IReadOnlyDictionary<int, RedDotKeyData> AllRedDotKeyData => m_AllRedDotKeyData;
  12. private RedDotKeyAsset m_RedDotKeyAsset;
  13. /// <summary>
  14. /// 加载key
  15. /// </summary>
  16. private async ETTask<bool> LoadKeyAsset()
  17. {
  18. var loadResult = await ET.EventSystem.Instance?.YIUIInvokeEntityAsyncSafety<YIUIInvokeEntity_Load, ETTask<UnityObject>>(Entity, new YIUIInvokeEntity_Load
  19. {
  20. LoadType = typeof(RedDotKeyAsset),
  21. ResName = RedDotKeyAssetName
  22. });
  23. if (loadResult == null)
  24. {
  25. Debug.LogError($"初始化失败 没有加载到目标数据 {RedDotKeyAssetName}");
  26. return false;
  27. }
  28. m_RedDotKeyAsset = (RedDotKeyAsset)loadResult;
  29. InitKeyData();
  30. ET.EventSystem.Instance?.YIUIInvokeEntitySyncSafety(Entity, new YIUIInvokeEntity_Release
  31. {
  32. obj = loadResult
  33. });
  34. return true;
  35. }
  36. /// <summary>
  37. /// 初始化Key相关
  38. /// </summary>
  39. private void InitKeyData()
  40. {
  41. m_AllRedDotKeyData.Clear();
  42. foreach (var keyData in m_RedDotKeyAsset.AllRedDotDic.Values)
  43. {
  44. m_AllRedDotKeyData.Add(keyData.Id, keyData);
  45. }
  46. }
  47. /// <summary>
  48. /// 获取key描述
  49. /// </summary>
  50. public string GetKeyDes(int keyType)
  51. {
  52. if (!m_AllRedDotKeyData.ContainsKey(keyType))
  53. {
  54. Debug.LogError($"不存在这个key {keyType}");
  55. return "";
  56. }
  57. var keyData = m_AllRedDotKeyData[keyType];
  58. return keyData.Des;
  59. }
  60. }
  61. }