Beispiel #1
0
        public void StepCollect()
        {
            ++collectedIndex;
            for (int i = 0; i < collectStep; ++i)
            {
                collectedIndex += i;
                if (collectedIndex >= count)
                {
                    collectedIndex = -1;
                    return;
                }

                var node = list[collectedIndex];
                if (!node.bObjectType)
                {
                    continue;
                }

                var    objNode = node as PoolNode <object>;
                object o       = objNode.obj;
                if (o != null && o.Equals(null))
                {
                    objNode.obj = null;
                    StackDataMapping <object> .InstanceGet(this).Remove(o, collectedIndex);
                }
            }
        }
Beispiel #2
0
        public bool GetDataExistRef <T>(T o, out int index)
        {
            index = -1;
#if UNITY_EDITOR
            Type dataType       = TypeTraits <T> .type;
            Type dataOriginType = o.GetType();
            if (!TypeChecker.IsValueType(dataOriginType) && dataType != objType)
            {
                Debugger.LogError("strict object type required, got :" + dataOriginType);
                return(false);
            }
#endif
            return(StackDataMapping <T> .InstanceGet(this).TryGetValue(o, out index));
        }
Beispiel #3
0
 private void RemoveMapping(LuaObjectPool objPool, int pos)
 {
     if (bObjectType)
     {
         if (obj != null)
         {
             StackDataMapping <object> .InstanceGet(objPool).Remove(obj, pos);
         }
     }
     else
     {
         StackDataMapping <T> .InstanceGet(objPool).Remove(obj, pos);
     }
 }
Beispiel #4
0
            public static StackDataMapping <T> InstanceGet(LuaObjectPool luaObjectPool)
            {
#if !MULTI_STATE
                _instance = _instance ?? new StackDataMapping <T>(luaObjectPool);
                return(_instance);
#else
                StackDataMapping <T> _instance = null;
                if (!_instanceGroup.TryGetValue(luaObjectPool, out _instance) || _instance == null)
                {
                    _instance = new StackDataMapping <T>(luaObjectPool);
                    _instanceGroup[luaObjectPool] = _instance;
                }

                return(_instance);
#endif
            }
Beispiel #5
0
        public bool Add <T>(T obj, out int pos)
        {
            NodeBase node = null;

            pos = -1;

            var head = PoolNode <T> .head;

            if (head.index != 0)
            {
                pos  = head.index;
                node = list[pos];
                var gNode = node as PoolNode <T>;
                gNode.obj     = obj;
                gNode.eleType = obj.GetType();
                head.index    = node.index;
            }
            else
            {
                if (count == list.Length)
                {
                    EnsureCapacity(count + 1);
                }
                pos       = count;
                node      = new PoolNode <T>(pos, obj);
                list[pos] = node;
                count++;
            }

#if UNITY_EDITOR
            Type dataType = TypeTraits <T> .type;
            if (node.bObjectType && dataType != objType)
            {
                Debugger.LogError("strict object type required, got :" + node.eleType);
                return(false);
            }
#endif
            StackDataMapping <T> .InstanceGet(this).Add(obj, pos);

            return(true);
        }