Example #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);
        }
Example #2
0
 /// <summary>
 /// 移除组件回调方法
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="path"></param>
 static void InnerRemoveUIComponent(this Entity self, Entity component, string path)
 {
     if (component != null)
     {
         self.GetCompoennts()[path].Remove(component.GetType());
         self.SetLength(self.GetLength() - 1);
         if (self.GetCompoennts()[path].Count <= 0)
         {
             self.GetCompoennts().Remove(path);
         }
     }
 }
Example #3
0
        public static void BeforeOnDestroy(this Entity self)
        {
            var keys1 = self.GetCompoennts().Keys.ToList();

            for (int i = keys1.Count - 1; i >= 0; i--)
            {
                if (self.GetCompoennts()[keys1[i]] != null)
                {
                    var keys2 = self.GetCompoennts()[keys1[i]].Keys.ToList();
                    for (int j = keys2.Count - 1; j >= 0; j--)
                    {
                        var component = self.GetCompoennts()[keys1[i]][keys2[j]];
                        component.BeforeOnDestroy();
                        UIEventSystem.Instance.OnDestroy(component);
                    }
                }
            }
            self.SetLength(self.GetLength() - 1);
            if (self.GetLength() <= 0)
            {
                if (UIManagerComponent.Instance.pathMap.TryGetValue(self.Id, out var path))
                {
                    self.Parent.InnerRemoveUIComponent(self, path);
                }
                else
                {
                    Log.Info("Close window here, type name: " + self.GetType().Name);
                }
            }
            else
            {
                Log.Error("OnDestroy fail, length != 0");
            }
            UIManagerComponent.Instance.componentsMap.Remove(self.Id);
            UIManagerComponent.Instance.lengthMap.Remove(self.Id);
            UIManagerComponent.Instance.pathMap.Remove(self.Id);
            self.Dispose();
        }
Example #4
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);
        }