From 058ac2c9a507c91f13328ac3c341dcb500dde5a9 Mon Sep 17 00:00:00 2001 From: ALEXTANGXIAO <574809918@qq.com> Date: Fri, 11 Oct 2024 21:47:21 +0800 Subject: [PATCH] =?UTF-8?q?RemoveAllListenerByOwner=20=E5=80=92=E5=BA=8F?= =?UTF-8?q?=E7=A7=BB=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/GameEvent/ActorEventDispatcher.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs index 20332012..08d4bab7 100644 --- a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs +++ b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs @@ -96,15 +96,13 @@ namespace TEngine { if (_allEventListenerMap.TryGetValue(eventId, out var listListener)) { - for (int i = 0; i < listListener.Count; i++) + for (int i = listListener.Count - 1; i >= 0 ; i--) { if (listListener[i].IsDeleted) { Log.Info("remove delay delete eventId[{0}]", eventId); - listListener[i] = listListener[^1]; - EventRegInfo.Release(listListener[^1]); - listListener.RemoveAt(listListener.Count - 1); - i--; + EventRegInfo.Release(listListener[i]); + listListener.RemoveAt(i); } } } @@ -462,7 +460,7 @@ namespace TEngine bool isProcessing = _processEventList.Contains(eventId); bool delayDeleted = false; - for (int i = 0; i < list.Count; i++) + for (int i = list.Count - 1; i >= 0 ; i--) { var regInfo = list[i]; if (regInfo.Owner == owner) @@ -474,10 +472,8 @@ namespace TEngine } else { - list[i] = list[^1]; - EventRegInfo.Release(list[^1]); - list.RemoveAt(list.Count - 1); - i--; + EventRegInfo.Release(list[i]); + list.RemoveAt(i); } } }