async Task <UIComponent> AddWindow(string winName, GameObject go = null) { var type = World.Instance.GetComponentType($"View_{winName}Component"); if (type == null) { Debug.LogError($"找不到对应类型---View_{winName}Component"); return(null); } //生成窗口 var component = World.Main.GetComponent <UIManagerComponent>().Entity .AddChild(type, IDGenerater.GetID(winName)) as UIComponent; if (component == null) { return(null); } component.Connect <UIComponent>(); if (go == null) { go = await Create(winName); } //初始化窗口 component.rectTransform = go.transform as RectTransform; //如果有动画组件就挂载动画组件 if (go.TryGetComponent <UISetting>(out var uiSetting)) { component.Entity.AddComponent <UIAnimaComponent>().From(uiSetting); component.ModuleUI = uiSetting.ModuleUI; go.SetActive(uiSetting.Active); Object.Destroy(uiSetting); } component.ViewName = winName; UiItems.Add(winName, component); UiItemsType.Add(type, component); if (BaseIndex == -1) { BaseIndex = go.transform.GetSiblingIndex(); } //调用这个窗口的初始化系统 World.Instance.RunSystemOfTagType(SystemType.UICreate, component.Entity); return(component); }
public YuoEntity() { Components = new Dictionary <Type, YuoComponent>(); ChildComponents = new MultiMap <Type, YuoComponent>(); Children = new List <Main.Ecs.YuoEntity>(); //EntityComponent为基础组件,无法移除,不会显示在组件列表中,但当销毁时会自动移除 //可以通过获取EntityComponent是否为null来判断Entity是否释放 EntityData = new EntityComponent(); EntityData.Entity = this; EntityData.Id = IDGenerater.GetID(this); World.Instance.AddComponet(this, EntityData); World.Instance.RegisterEntity(this); }
public void Awake() { _allSystem = new(); if (Instance != null) { _dontInit = true; Destroy(gameObject); return; } _entities = new(); components = new(); systemsOfTag = new(); systemsOfComponent = new(); Instance = this; DontDestroyOnLoad(gameObject); //系统初始化必须放在所有初始化之前 Initialization(); //基本核心组件挂载的实体 Main = new YuoEntity(0); Main.EntityName = "核心组件"; AddComponet(Main, IDGenerater.Instance); //添加一个场景实体 var scene = new YuoEntity(IDGenerater.GetID(IDGenerater.IDType.Scene, 0)); scene.EntityName = "默认场景"; AllScenes.Add(scene); scene.AddComponent <SceneComponent>(); }