EllanJiang / GameFramework

This is literally a game framework, based on Unity game engine. It encapsulates commonly used game modules during development, and, to a large degree, standardises the process, enhances the development speed and ensures the product quality.
https://GameFramework.cn
MIT License
5.97k stars 1.45k forks source link

事件分发机制严重缺陷 #75

Open wazazhang opened 2 months ago

wazazhang commented 2 months ago

以下是改进的代码 就这水平就别出来丢人了

    private readonly List<Event> m_EventsFuckJiangYin = new List<Event>();

    /// <summary>
    /// 事件池轮询。
    /// </summary>
    /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
    /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
    public void Update(float elapseSeconds, float realElapseSeconds)
    {
        lock (m_Events)
        {
            m_EventsFuckJiangYin.AddRange(m_Events);
            m_Events.Clear();
        }
        try
        {
            for (int i = 0; i < m_EventsFuckJiangYin.Count; i++)
            {
                Event eventNode = m_EventsFuckJiangYin[i];
                HandleEvent(eventNode.Sender, eventNode.EventArgs);
                ReferencePool.Release(eventNode);
            }
        }
        finally
        {
            m_EventsFuckJiangYin.Clear();
        }
    }