using System.Collections.Generic; namespace ColdMint.scripts.map.room; /// /// Room event Manager /// 房间事件管理器 /// public static class RoomEventManager { /// /// The event of entering the room /// 进入房间的事件 /// private static Dictionary? _enterRoomEventHandlers; /// /// Exit the room event /// 退出房间的事件 /// private static Dictionary? _exitRoomEventHandlers; /// /// Register the event handler that enters the room /// 注册进入房间的事件处理器 /// /// /// public static bool RegisterEnterRoomEventHandler(IEnterRoomEventHandler enterRoomEventHandler) { var id = enterRoomEventHandler.GetId(); if (_enterRoomEventHandlers != null) return _enterRoomEventHandlers.TryAdd(id, enterRoomEventHandler); _enterRoomEventHandlers = new Dictionary { { id, enterRoomEventHandler } }; return true; } /// /// Gets the event that entered the room /// 获取进入房间的事件 /// /// /// public static IEnterRoomEventHandler? GetEnterRoomEventHandler(string id) { return _enterRoomEventHandlers != null && _enterRoomEventHandlers.TryGetValue(id, out var enterRoomEventHandler) ? enterRoomEventHandler : null; } /// /// Unregister the room entry event /// 取消注册进入房间事件 /// /// /// public static bool UnRegisterEnterRoomEventHandler(string id) { return _enterRoomEventHandlers != null && _enterRoomEventHandlers.Remove(id); } /// /// Unregister for exit room events /// 取消注册退出房间事件 /// /// /// public static bool UnRegisterExitRoomEventHandler(string id) { return _exitRoomEventHandlers != null && _exitRoomEventHandlers.Remove(id); } /// /// Gets the event to exit the room /// 获取退出房间的事件 /// /// /// public static IExitRoomEventHandler? GetExitRoomEventHandler(string id) { return _exitRoomEventHandlers != null && _exitRoomEventHandlers.TryGetValue(id, out var exitRoomEventHandler) ? exitRoomEventHandler : null; } /// /// Sign up to exit the room's event handler /// 注册退出房间的事件处理器 /// /// /// public static bool RegisterExitRoomEventHandler(IExitRoomEventHandler exitRoomEventHandler) { var id = exitRoomEventHandler.GetId(); if (_exitRoomEventHandlers != null) return _exitRoomEventHandlers.TryAdd(id, exitRoomEventHandler); _exitRoomEventHandlers = new Dictionary { { id, exitRoomEventHandler } }; return true; } }