Пример #1
0
    //删除操作
    public void Remove(List <LinkedListNode <IShareThingHandle> > removes)
    {
        IShareThingHandle oldLast = Get();

        foreach (LinkedListNode <IShareThingHandle> node in removes)
        {
            node.Value.m_shareThing = null;
            m_handles.Remove(node);
        }

        //处理回调,一定要放在位置操作之后
        IShareThingHandle last = Get();

        if (oldLast != last)
        {
            if (last != null)
            {
                last.OnLast(oldLast);
            }
            if (oldLast.m_shareThing != null)//注意这里要判断下,有可能就是被删除的那个
            {
                oldLast.OnOverlay();
            }
            if (oldLast.m_removeIfOverlay)
            {
                m_handles.Remove(oldLast);
            }
        }
        if (m_handles.Count == 0)
        {
            oldLast.OnEmpty();
        }
    }
Пример #2
0
    //删除操作
    public void Remove(IShareThingHandle handle)
    {
        IShareThingHandle oldLast = Get();

        handle.m_shareThing = null;
        if (!m_handles.Remove(handle))
        {
            Debuger.LogError("删除不了,不在管理器中");
            return;
        }

        //处理回调,一定要放在位置操作之后
        IShareThingHandle last = Get();

        if (oldLast != last)
        {
            if (last != null)
            {
                last.OnLast(oldLast);
            }
            if (oldLast.m_shareThing != null)//注意这里要判断下,有可能就是被删除的那个
            {
                oldLast.OnOverlay();
            }
            if (oldLast.m_removeIfOverlay)
            {
                m_handles.Remove(oldLast);
            }
        }
        if (m_handles.Count == 0)
        {
            handle.OnEmpty();
        }
    }
Пример #3
0
    //修改操作,默认是放在同优先级后面(先出),addAfter =false那么就放前(慢出)
    public void Change(IShareThingHandle handle, int priority, bool after = true)
    {
        IShareThingHandle oldLast = Get();

        if (!m_handles.Remove(handle))
        {
            Debuger.LogError("改变不了优先级,不在管理器中");
            return;
        }

        //按照插入同优先级的最后面
        handle.m_priority = priority;
        LinkedListNode <IShareThingHandle> node = m_handles.Last;

        if (node == null)
        {
            m_handles.AddLast(handle);
        }
        else
        {
            do
            {
                if (after == true && node.Value.m_priority <= priority)//插入到优先级后面
                {
                    m_handles.AddAfter(node, handle);
                    break;
                }
                else if (after == false && node.Value.m_priority < priority)//插入到优先级前
                {
                    m_handles.AddAfter(node, handle);
                    break;
                }
                else if (node.Previous == null)
                {
                    m_handles.AddBefore(node, handle);
                    break;
                }

                node = node.Previous;
            } while (true);
        }

        //处理回调,一定要放在位置操作之后
        IShareThingHandle last = Get();

        if (oldLast != last)
        {
            last.OnLast(oldLast);
            oldLast.OnOverlay();
            if (oldLast.m_removeIfOverlay)
            {
                m_handles.Remove(oldLast);
            }
        }
        if (m_handles.Count == 0)
        {
            handle.OnEmpty();
        }
    }
Пример #4
0
    //删除操作,onCheckRemove返回true则删除,注意onCheckRemove中不能有其他的增删改操作,这里是从前往后遍历,这样可以防止这个过程中多次OnLast
    public void Remove(Func <IShareThingHandle, bool> onCheckRemove)
    {
        if (m_handles.Count == 0)
        {
            return;
        }
        IShareThingHandle oldLast = Get();

        LinkedListNode <IShareThingHandle> node = m_handles.First;
        LinkedListNode <IShareThingHandle> temp;

        while (node != null)
        {
            temp = node.Next;
            if (onCheckRemove(node.Value))
            {
                m_handles.Remove(node);
                node.Value.m_shareThing = null;
            }
            node = temp;
        }

        //处理回调,一定要放在位置操作之后
        IShareThingHandle last = Get();

        if (oldLast != last)
        {
            if (last != null)
            {
                last.OnLast(oldLast);
            }
            if (oldLast.m_shareThing != null)//注意这里要判断下,有可能就是被删除的那个
            {
                oldLast.OnOverlay();
            }
            if (oldLast.m_removeIfOverlay)
            {
                m_handles.Remove(oldLast);
            }
        }
        if (m_handles.Count == 0)
        {
            oldLast.OnEmpty();
        }
    }
Пример #5
0
    //清空操作
    public void Clear()
    {
        if (m_handles.Count == 0)
        {
            return;
        }

        IShareThingHandle last = Get();
        LinkedListNode <IShareThingHandle> node = m_handles.First;

        while (node != null)
        {
            node.Value.m_shareThing = null;
            node = node.Next;
        }
        m_handles.Clear();

        //处理回调,一定要放在位置操作之后
        if (last != null)
        {
            last.OnEmpty();
        }
    }
Пример #6
0
    //增加操作,如果已经在里面了,那么changeIfExist=true时Change(),否则报个错
    public void Add(IShareThingHandle handle, int priority = 0, bool changeIfExist = false, bool removeIfOverlay = false)
    {
        //
        if (handle.m_shareThing != null)
        {
            if (handle.m_shareThing != this)
            {
                Debuger.LogError("逻辑错误handle的shareThing不一样");
                return;
            }
            if (!changeIfExist)
            {
                Debuger.LogError("已经在shareThing里面了");
                return;
            }
            Change(handle, priority);
            return;
        }

        IShareThingHandle oldLast = Get();

        //这里检错下,如果太多,说明可能有忘记释放的地方
        if (m_handles.Count > Check_Leak_Count)
        {
            Debuger.LogError("共享资源管理器中操作数太多。type=" + handle.GetType().ToString());
        }

        handle.m_shareThing      = this;
        handle.m_priority        = priority;
        handle.m_removeIfOverlay = removeIfOverlay;

        //按照插入同优先级的最后面
        LinkedListNode <IShareThingHandle> node = m_handles.Last;

        if (node == null)
        {
            m_handles.AddLast(handle);
        }
        else
        {
            do
            {
                if (node.Value.m_priority <= priority)
                {
                    m_handles.AddAfter(node, handle);
                    break;
                }
                else if (node.Previous == null)
                {
                    m_handles.AddBefore(node, handle);
                    break;
                }
                node = node.Previous;
            }while(true);
        }

        //处理回调,一定要放在位置操作之后
        if (Get() == handle)
        {
            handle.OnLast(oldLast);
            if (oldLast != null)
            {
                oldLast.OnOverlay();
                if (oldLast.m_removeIfOverlay)
                {
                    m_handles.Remove(oldLast);
                }
            }
            if (m_handles.Count == 0)
            {
                handle.OnEmpty();
            }
        }
    }