Exemplo n.º 1
0
        /// <summary>
        /// 添加组件
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="name">游戏物体名称</param>
        public static T AddUIComponentNotCreate <T>(this Entity self, string name) where T : Entity, IAwake, IOnEnable
        {
            Type type           = typeof(T);
            T    component_inst = self.AddChild <T>();

            UIManagerComponent.Instance.pathMap[component_inst.Id] = name;

            self.RecordUIComponent(name, type, component_inst);
            self.SetLength(self.GetLength() + 1);
            return(component_inst);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加组件
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="path">路径</param>
        public static T AddUIComponent <T>(this Entity self, string path = "") where T : Entity, IAwake, IOnCreate, IOnEnable
        {
            Type type           = typeof(T);
            T    component_inst = self.AddChild <T>();

            UIManagerComponent.Instance.pathMap[component_inst.Id] = path;

            self.RecordUIComponent(path, type, component_inst);
            Game.EventSystem.Publish(new UIEventType.AddComponent()
            {
                Path = path, entity = component_inst
            });
            UIEventSystem.Instance.OnCreate(component_inst);
            self.SetLength(self.GetLength() + 1);
            return(component_inst);
        }