예제 #1
0
        private static void Sync_Status(byte[] obj)
        {
            try
            {
                sync_Status.init(obj);
                Dictionary <long, EntityComp> comps = EntityCompFactory.Instance.GetComponentsInUse <SyncTransComp>();
                foreach (var aoiTtrans in sync_Status.status.Values)
                {
                    EntityComp comp = null;
                    if (comps.TryGetValue(aoiTtrans.aoiId, out comp))
                    {
                        (comp as SyncTransComp).Sync(aoiTtrans);
                    }

                    EntityBehavior behavior = EntityBehaviorManager.GetEntity(aoiTtrans.aoiId);
                    if (behavior != null)
                    {
                        behavior.SetEntityTrans(aoiTtrans);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
        public EntityComp GetEntityComp <T>()
            where T : EntityComp
        {
            Type       type      = typeof(T);
            EntityComp entitycmp = null;

            if (entitiesCompList.TryGetValue(type, out entitycmp))
            {
                return(entitycmp);
            }
            return(entitycmp);
        }
        private void RemoveEntityComp(Type type)
        {
            if (!entitiesCompList.ContainsKey(type))
            {
                Debug.Log("entity not contain comp named " + name);
                return;
            }
            EntityComp comp = entitiesCompList[type];

            comp.Remove();
            EntityCompFactory.Instance.Recycle(AoiId, comp);
            entitiesCompList.Remove(type);
        }
        public EntityComp AddEntityComp <T>(long aoiId)
            where T : EntityComp
        {
            Type type = typeof(T);

            EntityComp entitycomp = null;

            if (!entitiesCompList.TryGetValue(type, out entitycomp))
            {
                entitycomp = EntityCompFactory.Instance.Get <T>(aoiId) as EntityComp;
                entitiesCompList.Add(type, entitycomp);
            }
            return(entitycomp);
        }
예제 #5
0
        /// <summary>
        /// 回收EntityComp
        /// </summary>
        /// <param name="protoData"></param>
        public void Recycle(long aoiId, EntityComp comp)
        {
            if (comp == null)
            {
                return;
            }
            Type protoType = comp.GetType();

            comp.Recycle();
            Dictionary <long, EntityComp> comps = null;

            if (compListMap.TryGetValue(comp.GetType(), out comps))
            {
                comps.Remove(aoiId);
            }
        }
예제 #6
0
        public T Get <T>(long aoiId)
            where T : EntityComp
        {
            EntityComp protoData          = null;
            Type       protoType          = typeof(T);
            RecyclePool <EntityComp> pool = null;

            if (poolMap.TryGetValue(protoType, out pool))
            {
                protoData = pool.Alloc();
                Dictionary <long, EntityComp> comps = null;
                if (compListMap.TryGetValue(typeof(T), out comps))
                {
                    comps.Add(aoiId, protoData);
                }
            }
            return((T)protoData);
        }