示例#1
0
文件: Entity.cs 项目: ALunGame/LCECS
        //删除组件
        public void RemoveCom(string typeName)
        {
            if (!IdComDict.ContainsKey(typeName))
            {
                return;
            }

            //调用函数
            BaseCom com = IdComDict[typeName];

            if (com.IsActive)
            {
                com.Disable();
            }

            //清除数据
            IdComDict.Remove(typeName);
        }
示例#2
0
文件: Entity.cs 项目: ALunGame/LCECS
        //添加组件
        public void AddCom(BaseCom com)
        {
            string fullName = com.GetType().FullName;

            if (IdComDict.ContainsKey(fullName))
            {
                return;
            }

            //调用函数
            if (!com.IsActive)
            {
                com.Enable();
            }

            //保存数据
            IdComDict.Add(fullName, com);
        }
示例#3
0
文件: Entity.cs 项目: ALunGame/LCECS
        //删除组件
        public void RemoveCom <T>() where T : BaseCom
        {
            string typeName = typeof(T).Name;

            if (!IdComDict.ContainsKey(typeName))
            {
                return;
            }

            //调用函数
            BaseCom com = IdComDict[typeName];

            if (com.IsActive)
            {
                com.Disable();
            }

            //清除数据
            IdComDict.Remove(typeName);
        }
示例#4
0
        //检测实体是否处理符合条件
        public bool CheckEntity(Entity entity)
        {
            //是否需要检测
            bool check = true;

            //需要监听的组件列表
            List <BaseCom> listenComs = new List <BaseCom>();

            //实体关闭
            if (entity.IsEnable == false)
            {
                check = false;
            }
            else
            {
                for (int i = 0; i < ListenComs.Count; i++)
                {
                    string  typeName = ListenComs[i].FullName;
                    BaseCom com      = entity.GetCom(typeName);

                    //没有这个组件直接返回(因为组件没有删除,只有激活于禁用)
                    if (com == null)
                    {
                        return(false);
                    }
                    else
                    {
                        //组件被禁用了
                        if (com.IsActive == false)
                        {
                            check = false;
                            break;
                        }
                        else
                        {
                            listenComs.Add(com);
                        }
                    }
                }
            }

            int entityId = entity.GetHashCode();

            //需要检测
            if (check)
            {
                if (!IdHandleComsDict.ContainsKey(entityId))
                {
                    IdHandleComsDict.Add(entityId, listenComs);
                }
            }
            else
            {
                if (IdHandleComsDict.ContainsKey(entityId))
                {
                    IdHandleComsDict.Remove(entityId);
                }
            }

            //编辑器辅助显示用
#if UNITY_EDITOR
            if (check)
            {
                entity.Systems.Add(this.GetType().Name);
            }
            else
            {
                entity.Systems.Remove(this.GetType().Name);
            }
#endif

            return(check);
        }
示例#5
0
 protected static T GetCom <T>(BaseCom baseCom) where T : BaseCom
 {
     return(baseCom as T);
 }