1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System.Collections.Generic;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- public static partial class UIKeys
- {
- private static Dictionary<string, UIKey> _nameToKeys;
- private static Dictionary<UIKey, UILayer> _uikeyToLayerMap;
- public static UIKey NameToKey(string uiName)
- {
- if (string.IsNullOrEmpty(uiName))
- return null;
- if (_nameToKeys == null)
- {
- _nameToKeys = new Dictionary<string, UIKey>();
- }
- if (_nameToKeys.TryGetValue(uiName, out UIKey key))
- {
- return key;
- }
- var property = typeof(UIKeys).GetProperty(uiName, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.IgnoreCase);
- if (property != null)
- {
- key = property.GetValue(null) as UIKey;
- _nameToKeys.Add(uiName, key);
- return key;
- }
- XGame.Log.Error($"找不到UIKey. uiName:{uiName}");
- return null;
- }
- public static UILayer GetLayer(UIKey uikey)
- {
- if (_uikeyToLayerMap == null)
- {
- _uikeyToLayerMap = new Dictionary<UIKey, UILayer>();
- }
- if (_uikeyToLayerMap.TryGetValue(uikey, out var layer))
- {
- return layer;
- }
- layer = UILayer.Normal;
- var property = uikey.UIViewType.GetProperty("Layer", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.IgnoreCase);
- if (property != null)
- {
- layer = (UILayer)property.GetValue(null);
- }
- _uikeyToLayerMap.Add(uikey, layer);
- return layer;
- }
- public static void Dispose()
- {
- _nameToKeys?.Clear();
- _nameToKeys = null;
- _uikeyToLayerMap?.Clear();
- _uikeyToLayerMap = null;
- }
- }
- }
|