1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Core;
- namespace KairoEngine.Multiplayer
- {
- public static class NetMsgEvents
- {
- public static Dictionary<string, System.Action<string, int, uint, NetMsg>> list = new Dictionary<string, System.Action<string, int, uint, NetMsg>>();
-
- public static void StartListening(string title, System.Action<string, int, uint, NetMsg> listener)
- {
- System.Action<string, int, uint, NetMsg> action = null;
- if (list.TryGetValue(title, out action))
- {
- action += listener;
- list[title] = action;
- }
- else
- {
- action += listener;
- list.Add(title, action);
- }
- }
- public static void StopListening(string title, System.Action<string, int, uint, NetMsg> listener)
- {
- System.Action<string, int, uint, NetMsg> action = null;
- if (list.TryGetValue(title, out action))
- {
- action -= listener;
- list[title] = action;
- }
- }
- public static void Trigger(string title, string msg, int clientId, uint code, NetMsg netMsg)
- {
- System.Action<string, int, uint, NetMsg> action = null;
- if (list.TryGetValue(title, out action))
- {
- if(action != null) action(msg, clientId, code, netMsg);
- }
- }
- }
- }
|