protected override void OnInit() { // 事件 EventDispatcher eDispatcher = EventDispatcher.GetInstance(); eDispatcher.RegisterEvent <AppType>(eEventType.Connected, EventNetworkConnected); eDispatcher.RegisterEvent <AppType>(eEventType.Disconnect, EventNetworkDisconnect); MessagePackDispatcher msgDispatcher = MessagePackDispatcher.GetInstance(); msgDispatcher.RegisterFollowPacket((int)Proto.MsgId.L2CGameToken, MsgGameToken); msgDispatcher.RegisterFollowPacket((int)Proto.MsgId.C2GLoginByTokenRs, MsgLoginByTokenRs); // UI _btnPlayer = GetUi <Button>(@"Character Select List/Button (Play)"); _btnPlayer.onClick.AddListener(OnClickPlayer); _toggleGroup = GetUi <ToggleGroup>(@"Character Select List"); _btnCreate = GetUi <Button>(@"Character Select List/Characters List/Content/Button (Create)"); _btnCreate.onClick.AddListener(OnClickCreate); // 角色列表对象 _characterParent = UiUtil.GetTransform(_gameObj, @"Character Select List/Characters List/Content/Characters"); // 3d 模型 RawImage rawImage = GetUi <RawImage>(@"Character"); RectTransform transformObj = rawImage.GetComponent <RectTransform>(); _renderTexture = new RenderTexture((int)transformObj.sizeDelta.x, (int)transformObj.sizeDelta.y, 24); rawImage.texture = _renderTexture; base.OnInit(); }
void Start() { MessagePackDispatcher msgDispatcher = MessagePackDispatcher.GetInstance(); msgDispatcher.RegisterDefaultHandler(MsgDefaultHandler); msgDispatcher.RegisterFollowPacket((int)Proto.MsgId.L2CPlayerList, MsgPlayerList); msgDispatcher.RegisterFollowPacket((int)Proto.MsgId.G2CSyncPlayer, MsgPlayer); msgDispatcher.RegisterFollowPacket((int)Proto.MsgId.S2CEnterWorld, MsgEnterWorld); }
public void UnPacket(PacketHead head, byte[] byteArray, int offset, int length) { Proto.MsgId msgId = (Proto.MsgId)head.msg_id; if (!_msgHandler.ContainsKey(msgId)) { UnityEngine.Debug.LogWarning("!!!!! not found handler. recv packet msgId:" + head.msg_id); return; } Google.Protobuf.IMessage msg = _msgHandler[msgId](byteArray, offset, length); MessagePackDispatcher.GetInstance().Broadcasting(head.msg_id, msg); }
void OnDestroy() { MessagePackDispatcher msgDispatcher = MessagePackDispatcher.GetInstance(); if (msgDispatcher != null) { msgDispatcher.RemoveFollowPacket((int)Proto.MsgId.L2CPlayerList, MsgPlayerList); msgDispatcher.RemoveFollowPacket((int)Proto.MsgId.G2CSyncPlayer, MsgPlayer); msgDispatcher.RemoveFollowPacket((int)Proto.MsgId.S2CEnterWorld, MsgEnterWorld); } SceneManager.sceneLoaded -= OnSceneLoaded; }
protected override void OnDestroy() { // 事件 EventDispatcher eDispatcher = EventDispatcher.GetInstance(); eDispatcher.RemoveEvent <AppType>(eEventType.Connected, EventNetworkConnected); eDispatcher.RemoveEvent <AppType>(eEventType.Disconnect, EventNetworkDisconnect); // 网络事件 MessagePackDispatcher msgDispatcher = MessagePackDispatcher.GetInstance(); msgDispatcher.RemoveFollowPacket((int)Proto.MsgId.C2LAccountCheckRs, MsgAccoutCheckRs); }
protected override void OnInit() { _inputAccount = GetUi <InputField>(@"Input Field (Username)"); _inputPassword = GetUi <InputField>(@"Input Field (Password)"); _btnLogin = GetUi <Button>(@"Button (Login)"); _btnLogin.onClick.AddListener(OnClickLogin); // 事件 EventDispatcher eDispatcher = EventDispatcher.GetInstance(); eDispatcher.RegisterEvent <AppType>(eEventType.Connected, EventNetworkConnected); eDispatcher.RegisterEvent <AppType>(eEventType.Disconnect, EventNetworkDisconnect); // 网络事件 MessagePackDispatcher msgDispatcher = MessagePackDispatcher.GetInstance(); msgDispatcher.RegisterFollowPacket((int)Proto.MsgId.C2LAccountCheckRs, MsgAccoutCheckRs); }
protected override void OnDestroy() { MessagePackDispatcher msgDispatcher = MessagePackDispatcher.GetInstance(); msgDispatcher.RemoveFollowPacket((int)Proto.MsgId.C2GLoginByTokenRs, MsgLoginByTokenRs); msgDispatcher.RemoveFollowPacket((int)Proto.MsgId.L2CGameToken, MsgGameToken); // 事件 EventDispatcher eDispatcher = EventDispatcher.GetInstance(); eDispatcher.RemoveEvent <AppType>(eEventType.Connected, EventNetworkConnected); eDispatcher.RemoveEvent <AppType>(eEventType.Disconnect, EventNetworkDisconnect); if (_characterObj != null) { UnityEngine.Object.Destroy(_characterObj); } base.OnDestroy(); }