Esempio n. 1
0
        public static void Free(IEffect obj, int freeTime = -1, EEffectGroup group = EEffectGroup.Base, EventHandler onFreeHandler = null)
        {
#if UNITY_EDITOR
            if (!m_instance.m_dic[(int)group].ContainsKey(obj.index))
            {
                Log.i(ELogType.Effect, "dont has this index=>" + obj.index + "    " + group);
                if (onFreeHandler != null)
                {
                    onFreeHandler();
                }
                return;
            }
#endif
            if (obj == null)
            {
                if (onFreeHandler != null)
                {
                    onFreeHandler();
                }
                return;
            }
            if (freeTime > 0)
            {
                WaitFree wait = null;
                if (m_instance.m_usingWaitList.Count <= 0)
                {
                    wait = new WaitFree();
                }
                else
                {
                    wait = m_instance.m_usingWaitList[0];
                    m_instance.m_usingWaitList.RemoveAt(0);
                }
                wait.waitFree    = obj;
                wait.freeHandler = onFreeHandler;
                wait.freeTime    = freeTime;
                wait.group       = group;
                if (m_instance.m_pause)
                {
                    m_instance.m_pausingWaitList.Add(wait);
                }
                else
                {
                    m_instance.m_freeWaitList.Add(wait);
                }
            }
            else
            {
                if (onFreeHandler != null)
                {
                    onFreeHandler();
                }
                m_instance.m_dic[(int)group][obj.index].Free(obj);
                obj.transform.SetParent(parent);
                if (freeHandler != null)
                {
                    freeHandler(obj.index);
                }
            }
        }
Esempio n. 2
0
        public static IEffect Get(int index, EEffectGroup group = EEffectGroup.Base)
        {
            IEffect ef;

#if UNITY_EDITOR
            if (m_instance.m_dic[(int)group].ContainsKey(index))
            {
                ef = m_instance.m_dic[(int)group][index].Get();
            }
            else
            {
                Debug.Log.i(ELogType.Effect, "LaoHan:EffectManager dont has this index;" + index + "    " + group);
                var pool = new EffectPool();
                pool.index      = index;
                pool.storeCount = 1;
                m_instance.m_dic[(int)group].Add(index, pool);
                pool.loadHandler = m_instance.loadHandler;
                pool.group       = group;
                pool.Initialize(() => { });
                ef = m_instance.m_dic[(int)group][index].Get();
            }
#else
            ef = m_instance.m_dic[(int)group][index].Get();
#endif
            if (getHandler != null)
            {
                getHandler(index);
            }
            return(ef);
        }
Esempio n. 3
0
        public static void Store(int index, int count, EEffectGroup group, int capacity = -1, EventHandler onStoreHandler = null)
        {
            var g = m_instance.m_dic[(int)group];

            if (g.ContainsKey(index))
            {
                g[index].Add(count);
                if (onStoreHandler != null)
                {
                    onStoreHandler();
                }
            }
            else
            {
                var pool = new EffectPool();
                pool.index      = index;
                pool.capacity   = capacity;
                pool.storeCount = count;
                g.Add(index, pool);
                pool.loadHandler = m_instance.loadHandler;
                pool.group       = group;
                pool.Initialize(onStoreHandler);
            }
            if (storeHandler != null)
            {
                storeHandler(index);
            }
        }
Esempio n. 4
0
        public static void Clear(EEffectGroup group)
        {
            var g = m_instance.m_dic[(int)group];

            foreach (var item in g)
            {
                if (clearHandler != null)
                {
                    clearHandler(item.Key);
                }
                item.Value.Clear();
                m_instance.destroyHandler(item.Key);
            }
        }
Esempio n. 5
0
        public static void Clear(int index, EEffectGroup group = EEffectGroup.Base)
        {
#if UNITY_EDITOR
            if (m_instance.m_dic[(int)group].ContainsKey(index))
            {
                if (clearHandler != null)
                {
                    clearHandler(index);
                }
                m_instance.m_dic[index].Clear();
                m_instance.destroyHandler(index);
            }
            else
            {
                Debug.Log.i(ELogType.Model, "Clear dont has this id:" + index + "    " + group);
            }
#else
            m_instance.m_dic[(int)group][index].Clear();
            m_instance.destroyHandler(index);
#endif
        }
Esempio n. 6
0
        public static IEffect Get(int index, Vector3 position, Quaternion rotation, Transform parent, EEffectGroup group = EEffectGroup.Base)
        {
            var obj = Get(index, group);

            if (obj != null)
            {
                obj.transform.localPosition = position;
                obj.transform.localRotation = rotation;
                obj.transform.SetParent(parent);
            }
            return(obj);
        }