/// <summary> /// 将脚本绑定的响应事件注册到网络管理器 /// </summary> private void EnableHandlers() { foreach (KeyValuePair <ProtoID, NetworkEventHandler> pair in m_HandlerPairs) { NetworkChangeManager.RegisterWeak(pair.Key, pair.Value); } }
/// <summary> /// 添加脚本对象要处理的网络协议Id及其响应方法 /// </summary> /// <param name="id">协议Id</param> /// <param name="handler">进行响应的方法</param> protected void AddNetworkHandler(ProtoID id, NetworkEventHandler handler) { m_HandlerPairs.Add(new KeyValuePair <ProtoID, NetworkEventHandler> (id, handler)); // 如果脚本处于启用状态,要实时向网络管理器注册事件响应 if (this.enabled) { NetworkChangeManager.RegisterWeak(id, handler); } }
public void RegisterCallBack(ProtoID _protoId, NetworkEventHandler _callback) { NetworkChangeManager.RegisterWeak(_protoId, _callback); }