Exemplo n.º 1
0
        private void OnMove(Socket socket, byte[] data)
        {
            C2S_Move move = NetworkSerializer.Deserialize <C2S_Move>(data);

            if (move.Entities == null) //表示该玩家没有创建移动的游戏物体
            {
                return;
            }
            //玩家的实体
            foreach (var entity in move.Entities)
            {
                //获得场景中所有实例
                foreach (var dict in instances.Values)
                {
                    dict[entity.Id] = entity; //赋值
                }
            }
        }
Exemplo n.º 2
0
        public void Move()
        {
            if (!join) //等待加入游戏成功
            {
                return;
            }

            C2S_Move move = new C2S_Move();

            move.Frame    = frame;
            move.Entities = new List <Entity>();
            foreach (var instance in selfIntances)
            {
                Vector2Int pos = instance.Value.transform.Position;
                move.Entities.Add(new Entity(instance.Key, pos.X, pos.Y));
            }
            Send((ushort)NetworkRole.Client, (ushort)GameCmd.Move, move);
        }