UINestedKeys.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections.Generic;
  2. using XGame.Framework.UI;
  3. namespace FL.FGUI
  4. {
  5. public static partial class UINestedKeys
  6. {
  7. private static Dictionary<string, UIKey> _nameToKeys;
  8. public static UIKey NameToKey(string uiName)
  9. {
  10. if (_nameToKeys == null)
  11. {
  12. _nameToKeys = new Dictionary<string, UIKey>();
  13. }
  14. if (_nameToKeys.TryGetValue(uiName, out UIKey key))
  15. {
  16. return key;
  17. }
  18. var property = typeof(UIKeys).GetProperty(uiName, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.IgnoreCase);
  19. if (property != null)
  20. {
  21. key = property.GetValue(null) as UIKey;
  22. _nameToKeys.Add(uiName, key);
  23. return key;
  24. }
  25. XGame.Log.Error($"找不到UINestedKey. uiName:{uiName}");
  26. return default;
  27. }
  28. public static void Dispose()
  29. {
  30. _nameToKeys?.Clear();
  31. _nameToKeys = null;
  32. }
  33. }
  34. }