using ET; using System; using System.Collections.Generic; using UnityEngine; namespace ET { public class UIEventComponentAwakeSystem : AwakeSystem { public override void Awake(UIEventComponent self) { UIEventComponent.Instance = self; //GameObject uiRoot = GameObject.Find("/Global/UI"); //ReferenceCollector referenceCollector = uiRoot.GetComponent(); //self.UILayers.Add((int)UILayer.Hidden, referenceCollector.Get(UILayer.Hidden.ToString()).transform); //self.UILayers.Add((int)UILayer.Low, referenceCollector.Get(UILayer.Low.ToString()).transform); //self.UILayers.Add((int)UILayer.Mid, referenceCollector.Get(UILayer.Mid.ToString()).transform); //self.UILayers.Add((int)UILayer.High, referenceCollector.Get(UILayer.High.ToString()).transform); var uiEvents = Game.EventSystem.GetTypes(typeof(UIEventAttribute)); foreach (Type type in uiEvents) { object[] attrs = type.GetCustomAttributes(typeof(UIEventAttribute), false); if (attrs.Length == 0) { continue; } UIEventAttribute uiEventAttribute = attrs[0] as UIEventAttribute; AUIEvent aUIEvent = Activator.CreateInstance(type) as AUIEvent; self.UIEvents.Add(uiEventAttribute.UIType, aUIEvent); } } } /// /// 管理所有UI GameObject 以及UI事件 /// public static class UIEventComponentSystem { public static async ETTask OnCreate(this UIEventComponent self, FUIComponent uiComponent, string uiType) { try { FUI ui = await self.UIEvents[uiType].OnCreate(uiComponent); //UILayer uiLayer = ui.GameObject.GetComponent().UILayer; //ui.GameObject.transform.SetParent(self.UILayers[(int)uiLayer]); return ui; } catch (Exception e) { throw new Exception($"on create ui error: {uiType}", e); } } public static void OnRemove(this UIEventComponent self, FUIComponent uiComponent, string uiType) { try { self.UIEvents[uiType].OnRemove(uiComponent); } catch (Exception e) { throw new Exception($"on remove ui error: {uiType}", e); } } } }