Exemple #1
0
        // channel删除的时候需要清除与unit id的关联
        private void OnChannelDispose(AChannel channel)
        {
            ChannelUnitInfoComponent channelUnitInfoComponent =
                channel.GetComponent <ChannelUnitInfoComponent>();

            if (channelUnitInfoComponent != null)
            {
                this.unitIdChannels.Remove(channelUnitInfoComponent.UnitId);
            }
        }
Exemple #2
0
        /// <summary>
        /// 接收分发封包
        /// </summary>
        /// <param name="channel"></param>
        private static async void ProcessChannel(AChannel channel)
        {
            while (true)
            {
                byte[] messageBytes = await channel.RecvAsync();

                Opcode opcode = (Opcode)BitConverter.ToUInt16(messageBytes, 0);
                if (!OpcodeHelper.IsClientMessage(opcode))
                {
                    continue;
                }

                ObjectId unitId = channel.GetComponent <ChannelUnitInfoComponent>().UnitId;
                Actor    actor  = World.Instance.GetComponent <ActorComponent>().Get(unitId);
                actor.Add(messageBytes);
            }
        }