Exemplo n.º 1
0
 protected virtual void HandleEntity(ResourceCacheEntity entity, ResourceCacheBehaviourParam param)
 {
     if (entity != null && entity.Behaviour != null)
     {
         entity.Behaviour.Process(param);
     }
 }
Exemplo n.º 2
0
        public void AcquireArray(int num, List <ResourceCacheEntity> res)
        {
            if (!IsInitialized)
            {
                throw new Exception("AcquireArray Not Initialize");
            }
            res.Clear();
            if (Container.Count < num)
            {
                CreateEntity(num - Container.Count);
            }
            int index = 0;

            while (index < num)
            {
                ResourceCacheEntity entity = Container.First();
                Container.RemoveFirst();
                if (IsValid(entity))
                {
                    ResetOrigin(entity);
                    if (entity.Behaviour == null)
                    {
                        Type behaviourType = Type.GetType(GetBehaviourName());
                        Debug.Assert(behaviourType != null, "" + GetBehaviourName());
                        Debug.Assert(behaviourType != null, "null behaviourType");
                        entity.Behaviour = (ResourceCacheBehaviour)entity.GameObject.AddComponent(behaviourType);
                        entity.Behaviour.InitializeBase(this, entity);
                    }
                    entity.Behaviour.StopLifeTimer();
                    res.Add(entity);
                }
                index++;
            }
            Debug.Assert(index == num, "wrong");
        }
Exemplo n.º 3
0
 protected virtual void TimerCallback(ResourceCacheEntity entity)
 {
     if (entity != null && entity.Behaviour != null)
     {
         entity.Behaviour.PostCallback();
         ForceRelease(entity.InstanceId);
     }
 }
Exemplo n.º 4
0
        protected virtual int GenInstanceId(ResourceCacheEntity entity, int duration)
        {
            int instanceId = GetInstanceId(entity, duration);

            entity.InstanceId = instanceId;
            mAcquiredItems.Add(instanceId, entity);
            return(instanceId);
        }
Exemplo n.º 5
0
 protected virtual int GetInstanceId(ResourceCacheEntity entity, int duration)
 {
     if (entity.IsTimerOn)
     {
         return(TimerTaskQueue.Instance.AddTimer(duration, 0, TimerCallback, entity));
     }
     else
     {
         return(TimerTaskQueue.Instance.NextTimerId);
     }
 }
Exemplo n.º 6
0
        protected virtual ResourceCachePool GetEntityFromManager(int poolId, out ResourceCacheEntity entity)
        {
            entity = null;
            ResourceCachePool pool = null;

            if (mPools.ContainsKey(poolId))
            {
                pool   = mPools[poolId];
                entity = mPools[poolId].Acquire();;
            }
            return(pool);
        }
Exemplo n.º 7
0
 protected virtual void Release(int instanceId)
 {
     if (mAcquiredItems.ContainsKey(instanceId))
     {
         ResourceCacheEntity entity = mAcquiredItems[instanceId];
         if (entity.IsTimerOn)
         {
             TimerTaskQueue.Instance.DelTimer(entity.InstanceId);
         }
         mAcquiredItems.Remove(instanceId);
         ResourceCachePool pool = mPools[entity.ManagerId];
         pool.Release(entity);
     }
 }
Exemplo n.º 8
0
 public void Release(ResourceCacheEntity entity)
 {
     RemoveFromStrategy(entity.InstanceId);
     if (IsValid(entity))
     {
         entity.SetParent(Parent, false);
         if (entity.LevelIndex != LevelIndex || !CacheOn || GetLifeTime() == 0)
         {
             entity.Destroy();
         }
         else
         {
             entity.SetActive(false);
             Container.AddFirst(entity);
             entity.Behaviour.StartLifeTimer();
         }
     }
 }
Exemplo n.º 9
0
        public ResourceCacheEntity Acquire()
        {
            if (!IsInitialized)
            {
                throw new Exception("AcquireArray Not Initialize");
            }
            ResourceCacheEntity entity = null;

            if (IsInitialized && !IsLevelIgnore())
            {
                if (CanAcquire())
                {
                    AcquireArray(1, CACHE);
                    if (CACHE.Count > 0)
                    {
                        entity = CACHE[0];
                        CACHE.Clear();
                    }
                }
            }
            return(entity);
        }
Exemplo n.º 10
0
 private bool IsValid(ResourceCacheEntity entity)
 {
     return(entity != null && entity.GameObject != null);
 }