示例#1
0
 public void InitPlayer(ClientPlayerInfo playerInfo)
 {
     player          = new ClientPlayer(playerInfo.id, this);
     player.aoId     = playerInfo.aoId;
     player.playerId = playerInfo.playerId;
     player.InitPosition(playerInfo.position);
     player.configName = playerInfo.configName;
     player.seed       = playerInfo.seed;
 }
        public override void ServerDo(ClientConnectionWorker connectionWork)
        {
            ClientPlayerInfo playerInfo = new ClientPlayerInfo();

            playerInfo.id         = roleId;
            playerInfo.aoId       = aoId;
            playerInfo.playerId   = playerId;
            playerInfo.position   = position;
            playerInfo.configName = worldConfigName;
            playerInfo.seed       = seed;
            Debug.Log("初始化世界配置:" + worldConfigName);
            connectionWork.InitPlayer(playerInfo);
            NetManager.Instance.server.gameTime = time;
            NetManager.Instance.server.playerManager.AddPlayer(connectionWork.player, true);
            Debug.Log("服务器初始化主玩家信息完成!");
        }
示例#3
0
        public override void ServerDo(ClientConnectionWorker connectionWork)
        {
            //在服务器中初始化当前加入玩家的信息
            int              aoId       = AoIdManager.instance.getAoId();
            Vector3          birthPlace = NetManager.Instance.server.playerManager.mainPlayer.position;
            ClientPlayerInfo playerInfo = new ClientPlayerInfo();

            playerInfo.id         = roleId;
            playerInfo.aoId       = aoId;
            playerInfo.position   = birthPlace;
            playerInfo.playerId   = playerId;
            playerInfo.configName = NetManager.Instance.server.playerManager.mainPlayer.configName;
            playerInfo.seed       = NetManager.Instance.server.playerManager.mainPlayer.seed;
            connectionWork.InitPlayer(playerInfo);
            NetManager.Instance.server.playerManager.AddPlayer(connectionWork.player);

            //通知自己进入游戏,并返回一些配置
            ClientJoinGamePackage package = PackageFactory.GetPackage(PackageType.ClientJoinGame) as ClientJoinGamePackage;

            package.playerId        = playerId;
            package.aoId            = aoId;
            package.birthPlace      = birthPlace;
            package.worldConfigName = NetManager.Instance.server.playerManager.mainPlayer.configName;
            package.seed            = NetManager.Instance.server.playerManager.mainPlayer.seed;
            package.time            = NetManager.Instance.server.gameTime;
            connectionWork.SendPackage(package);

            //通知其他人我已进入游戏,并出现在他们视野内
            PlayerJoinViewPackage joinViewPackage = PackageFactory.GetPackage(PackageType.PlayerJoinView) as PlayerJoinViewPackage;

            joinViewPackage.playerId   = playerId;
            joinViewPackage.aoId       = aoId;
            joinViewPackage.birthPlace = birthPlace;
            List <int> viewPlayers = connectionWork.player.viewPlayers;

            for (int i = 0; i < viewPlayers.Count; i++)
            {
                ClientPlayer otherPlayer = NetManager.Instance.server.playerManager.GetPlayer(viewPlayers[i]);
                otherPlayer.worker.SendPackage(joinViewPackage);
            }
        }