示例#1
0
        public static IClass Get(string name, EClassGroup group = EClassGroup.Base)
        {
            bool   has   = false;
            int    index = 0;
            IClass cls;
            var    g = m_instance.m_dic[(int)group];

            foreach (var item in g)
            {
                if (name == item.Value.typeName)
                {
                    has   = true;
                    index = item.Key;
                }
            }
            if (has)
            {
                cls = g[index].GetObject();
            }
            else
            {
                Type type = Type.GetType(name);
                g.Add(index, new ClassPool(type, 1, group));
                cls = g[index].GetObject();
            }
            if (getHandler != null)
            {
                getHandler(cls.GetType());
            }
            return(cls);
        }
示例#2
0
        public void Clear(EClassGroup group)
        {
            var g = m_instance.m_dic[(int)group];

            foreach (var item in g)
            {
                clearHandler(item.Value.type);
                item.Value.Clear();
            }
        }
示例#3
0
        public void Clear <T>(EClassGroup group)
        {
            var  g     = m_instance.m_dic[(int)group];
            Type type  = typeof(T);
            int  index = type.MetadataToken;

            g[index].Clear();
            if (clearHandler != null)
            {
                clearHandler(type);
            }
        }
示例#4
0
        public static void Store(Type type, int count, EClassGroup group = EClassGroup.Base)
        {
            int index = type.MetadataToken;
            var g     = m_instance.m_dic[(int)group];

            if (g.ContainsKey(index))
            {
                g[index].Store(count);
            }
            else
            {
                g.Add(index, new ClassPool(type, count, group));
            }
            if (storeHandler != null)
            {
                storeHandler(type);
            }
        }
示例#5
0
        public ClassPool(Type type, int count, EClassGroup group)
        {
#if UNITY_EDITOR
            storeCount = count;
#endif
            this.group    = group;
            index         = type.MetadataToken;
            this.type     = type;
            this.typeName = type.Name;
            freeList      = new List <IClass>(count);
            for (int i = 0; i < count; i++)
            {
                var cla = Activator.CreateInstance(type) as IClass;
                freeList.Add(cla);
#if UNITY_EDITOR
                allList.Add(cla);
#endif
            }
        }
示例#6
0
        public static void Free(IClass obj, EClassGroup group = EClassGroup.Base)
        {
            if (obj == null || m_instance == null)
            {
                return;
            }
            int       index = (int)obj.GetType().MetadataToken;
            var       g     = m_instance.m_dic[(int)group];
            ClassPool pool;

            if (g.TryGetValue(index, out pool))
            {
                pool.FreeObject(obj);
            }
            else
            {
                Log.i(ELogType.Class, "LaoHan: freeObject dont has this type =>" + obj.GetType());
            }
            if (freeHandler != null)
            {
                freeHandler(obj.GetType());
            }
        }
示例#7
0
        public static T Get <T>(EClassGroup group = EClassGroup.Base) where T : IClass
        {
            Type      type = typeof(T);
            IClass    cls;
            int       index = type.MetadataToken;
            var       g     = m_instance.m_dic[(int)group];
            ClassPool pool;

            if (g.TryGetValue(index, out pool))
            {
                cls = pool.GetObject();
            }
            else
            {
                g.Add(index, new ClassPool(type, 1, group));
                cls = g[index].GetObject();
            }
            if (getHandler != null)
            {
                getHandler(cls.GetType());
            }
            return((T)cls);
        }
示例#8
0
        public static void Store <T>(int count, EClassGroup group = EClassGroup.Base)
        {
            Type type = typeof(T);

            Store(type, count, group);
        }