public override void OnServerAddPlayer(INetworkPlayer player) { var character = Instantiate(PlayerPrefab); // Make this a child of the layout panel in the Canvas character.transform.SetParent(Parent); SetCharacterName(player, character); ServerObjectManager.AddCharacter(player, character.gameObject); }
private void OnCreatePlayer(INetworkPlayer player, CreateCharacterMessage createCharacterMessage) { // create a gameobject using the name supplied by client GameObject playergo = Instantiate(playerPrefab).gameObject; playergo.GetComponent <Player>().playerName = createCharacterMessage.name; // set it as the player ServerObjectManager.AddCharacter(player, playergo); chatWindow.gameObject.SetActive(true); }
public IEnumerator SetupHost() => UniTask.ToCoroutine(async() => { networkManagerGo = new GameObject(); // set gameobject name to test name (helps with debugging) networkManagerGo.name = TestContext.CurrentContext.Test.MethodName; networkManagerGo.AddComponent <TestSocketFactory>(); sceneManager = networkManagerGo.AddComponent <NetworkSceneManager>(); serverObjectManager = networkManagerGo.AddComponent <ServerObjectManager>(); clientObjectManager = networkManagerGo.AddComponent <ClientObjectManager>(); manager = networkManagerGo.AddComponent <NetworkManager>(); manager.Client = networkManagerGo.GetComponent <NetworkClient>(); manager.Server = networkManagerGo.GetComponent <NetworkServer>(); server = manager.Server; client = manager.Client; if (ServerConfig != null) { server.PeerConfig = ServerConfig; } if (ClientConfig != null) { client.PeerConfig = ClientConfig; } sceneManager.Client = client; sceneManager.Server = server; serverObjectManager.Server = server; serverObjectManager.NetworkSceneManager = sceneManager; clientObjectManager.Client = client; clientObjectManager.NetworkSceneManager = sceneManager; ExtraSetup(); // wait for all Start() methods to get invoked await UniTask.DelayFrame(1); if (AutoStartServer) { await StartHost(); playerGO = new GameObject("playerGO", typeof(Rigidbody)); identity = playerGO.AddComponent <NetworkIdentity>(); component = playerGO.AddComponent <T>(); serverObjectManager.AddCharacter(server.LocalPlayer, playerGO); // wait for client to spawn it await AsyncUtil.WaitUntilWithTimeout(() => client.Player.HasCharacter); } });
public override void OnServerAddPlayer(INetworkPlayer player) { // add player at correct spawn position Transform start = Server.NumberOfPlayers == 0 ? leftRacketSpawn : rightRacketSpawn; NetworkIdentity character = Instantiate(PlayerPrefab, start.position, start.rotation); ServerObjectManager.AddCharacter(player, character.gameObject); // spawn ball if two players if (Server.NumberOfPlayers == 2) { ball = Instantiate(ballPrefab); ServerObjectManager.Spawn(ball); } }
private void OnCreateCharacter(INetworkPlayer player, CreateMMOCharacterMessage msg) { var prefab = GetPrefab(msg); // create your character object // use the data in msg to configure it var character = Instantiate(prefab); // set syncVars before telling mirage to spawn character // this will cause them to be sent to client in the spawn message character.PlayerName = msg.name; character.hairColor = msg.hairColor; character.eyeColor = msg.eyeColor; // spawn it as the character object ServerObjectManager.AddCharacter(player, character.Identity); }
public IEnumerator UnitySetUp() => UniTask.ToCoroutine(async() => { Console.WriteLine($"[MirageTest] UnitySetUp class:{TestContext.CurrentContext.Test.ClassName} method:{TestContext.CurrentContext.Test.MethodName}"); networkManagerGo = new GameObject(); networkManagerGo.AddComponent <TestSocketFactory>(); serverObjectManager = networkManagerGo.AddComponent <ServerObjectManager>(); clientObjectManager = networkManagerGo.AddComponent <ClientObjectManager>(); manager = networkManagerGo.AddComponent <NetworkManager>(); server = networkManagerGo.AddComponent <NetworkServer>(); client = networkManagerGo.AddComponent <NetworkClient>(); manager.Client = networkManagerGo.GetComponent <NetworkClient>(); manager.Server = networkManagerGo.GetComponent <NetworkServer>(); if (ServerConfig != null) { server.PeerConfig = ServerConfig; } if (ClientConfig != null) { client.PeerConfig = ClientConfig; } serverObjectManager.Server = server; clientObjectManager.Client = client; ExtraSetup(); // wait for all Start() methods to get invoked await UniTask.DelayFrame(2); if (AutoStartServer) { await StartHost(); playerGO = new GameObject("playerGO", typeof(Rigidbody)); playerIdentity = playerGO.AddComponent <NetworkIdentity>(); playerComponent = playerGO.AddComponent <T>(); serverObjectManager.AddCharacter(server.LocalPlayer, playerGO); // wait for client to spawn it await AsyncUtil.WaitUntilWithTimeout(() => client.Player.HasCharacter); } });
public IEnumerator Setup() => UniTask.ToCoroutine(async() => { serverGo = new GameObject("server", typeof(NetworkSceneManager), typeof(ServerObjectManager), typeof(NetworkServer)); clientGo = new GameObject("client", typeof(NetworkSceneManager), typeof(ClientObjectManager), typeof(NetworkClient)); testTransport = serverGo.AddComponent <LoopbackTransport>(); await UniTask.Delay(1); server = serverGo.GetComponent <NetworkServer>(); client = clientGo.GetComponent <NetworkClient>(); server.Transport = testTransport; client.Transport = testTransport; serverSceneManager = serverGo.GetComponent <NetworkSceneManager>(); clientSceneManager = clientGo.GetComponent <NetworkSceneManager>(); serverSceneManager.Server = server; clientSceneManager.Client = client; serverSceneManager.Start(); clientSceneManager.Start(); serverObjectManager = serverGo.GetComponent <ServerObjectManager>(); serverObjectManager.Server = server; serverObjectManager.NetworkSceneManager = serverSceneManager; serverObjectManager.Start(); clientObjectManager = clientGo.GetComponent <ClientObjectManager>(); clientObjectManager.Client = client; clientObjectManager.NetworkSceneManager = clientSceneManager; clientObjectManager.Start(); ExtraSetup(); // create and register a prefab playerPrefab = new GameObject("serverPlayer", typeof(NetworkIdentity), typeof(T)); NetworkIdentity identity = playerPrefab.GetComponent <NetworkIdentity>(); identity.AssetId = Guid.NewGuid(); clientObjectManager.RegisterPrefab(identity); // wait for client and server to initialize themselves await UniTask.Delay(1); // start the server var started = new UniTaskCompletionSource(); server.Started.AddListener(() => started.TrySetResult()); server.ListenAsync().Forget(); await started.Task; // now start the client await client.ConnectAsync("localhost"); await AsyncUtil.WaitUntilWithTimeout(() => server.Players.Count > 0); // get the connections so that we can spawn players connectionToClient = server.Players.First(); connectionToServer = client.Player; // create a player object in the server serverPlayerGO = Object.Instantiate(playerPrefab); serverIdentity = serverPlayerGO.GetComponent <NetworkIdentity>(); serverComponent = serverPlayerGO.GetComponent <T>(); serverObjectManager.AddCharacter(connectionToClient, serverPlayerGO); // wait for client to spawn it await AsyncUtil.WaitUntilWithTimeout(() => connectionToServer.Identity != null); clientIdentity = connectionToServer.Identity; clientPlayerGO = clientIdentity.gameObject; clientComponent = clientPlayerGO.GetComponent <T>(); });
public IEnumerator Setup() => UniTask.ToCoroutine(async() => { serverGo = new GameObject("server", typeof(NetworkSceneManager), typeof(ServerObjectManager), typeof(NetworkServer)); clientGo = new GameObject("client", typeof(NetworkSceneManager), typeof(ClientObjectManager), typeof(NetworkClient)); socketFactory = serverGo.AddComponent <TestSocketFactory>(); await UniTask.Delay(1); server = serverGo.GetComponent <NetworkServer>(); client = clientGo.GetComponent <NetworkClient>(); if (ServerConfig != null) { server.PeerConfig = ServerConfig; } if (ClientConfig != null) { client.PeerConfig = ClientConfig; } server.SocketFactory = socketFactory; client.SocketFactory = socketFactory; serverSceneManager = serverGo.GetComponent <NetworkSceneManager>(); clientSceneManager = clientGo.GetComponent <NetworkSceneManager>(); serverSceneManager.Server = server; clientSceneManager.Client = client; serverSceneManager.Start(); clientSceneManager.Start(); serverObjectManager = serverGo.GetComponent <ServerObjectManager>(); serverObjectManager.Server = server; serverObjectManager.NetworkSceneManager = serverSceneManager; serverObjectManager.Start(); clientObjectManager = clientGo.GetComponent <ClientObjectManager>(); clientObjectManager.Client = client; clientObjectManager.NetworkSceneManager = clientSceneManager; clientObjectManager.Start(); ExtraSetup(); // create and register a prefab playerPrefab = new GameObject("player (unspawned)", typeof(NetworkIdentity), typeof(T)); NetworkIdentity identity = playerPrefab.GetComponent <NetworkIdentity>(); identity.PrefabHash = Guid.NewGuid().GetHashCode(); clientObjectManager.RegisterPrefab(identity); // wait for client and server to initialize themselves await UniTask.Delay(1); // start the server var started = new UniTaskCompletionSource(); server.Started.AddListener(() => started.TrySetResult()); server.StartServer(); await started.Task; if (AutoConnectClient) { // now start the client client.Connect("localhost"); await AsyncUtil.WaitUntilWithTimeout(() => server.Players.Count > 0); // get the connections so that we can spawn players serverPlayer = server.Players.First(); clientPlayer = client.Player; // create a player object in the server serverPlayerGO = Object.Instantiate(playerPrefab); serverPlayerGO.name = "player (server)"; serverIdentity = serverPlayerGO.GetComponent <NetworkIdentity>(); serverComponent = serverPlayerGO.GetComponent <T>(); serverObjectManager.AddCharacter(serverPlayer, serverPlayerGO); // wait for client to spawn it await AsyncUtil.WaitUntilWithTimeout(() => clientPlayer.HasCharacter); clientIdentity = clientPlayer.Identity; clientPlayerGO = clientIdentity.gameObject; clientPlayerGO.name = "player (client)"; clientComponent = clientPlayerGO.GetComponent <T>(); } await LateSetup(); });
public IEnumerator UnitySetUp() => UniTask.ToCoroutine(async() => { Console.WriteLine($"[MirageTest] UnitySetUp class:{TestContext.CurrentContext.Test.ClassName} method:{TestContext.CurrentContext.Test.MethodName} "); serverGo = new GameObject("server", typeof(ServerObjectManager), typeof(NetworkServer)); clientGo = new GameObject("client", typeof(ClientObjectManager), typeof(NetworkClient)); socketFactory = serverGo.AddComponent <TestSocketFactory>(); server = serverGo.GetComponent <NetworkServer>(); client = clientGo.GetComponent <NetworkClient>(); if (ServerConfig != null) { server.PeerConfig = ServerConfig; } if (ClientConfig != null) { client.PeerConfig = ClientConfig; } server.SocketFactory = socketFactory; client.SocketFactory = socketFactory; serverObjectManager = serverGo.GetComponent <ServerObjectManager>(); serverObjectManager.Server = server; clientObjectManager = clientGo.GetComponent <ClientObjectManager>(); clientObjectManager.Client = client; ExtraSetup(); // wait 2 frames for start to be called await UniTask.DelayFrame(2); // create and register a prefab playerPrefab = new GameObject("player (unspawned)", typeof(NetworkIdentity), typeof(T)); // DontDestroyOnLoad so that "prefab" wont be destroyed by scene loading // also means that NetworkScenePostProcess will skip this unspawned object Object.DontDestroyOnLoad(playerPrefab); var identity = playerPrefab.GetComponent <NetworkIdentity>(); identity.PrefabHash = Guid.NewGuid().GetHashCode(); clientObjectManager.RegisterPrefab(identity); // wait for client and server to initialize themselves await UniTask.Delay(1); // start the server var started = new UniTaskCompletionSource(); server.Started.AddListener(() => started.TrySetResult()); server.StartServer(); await started.Task; if (AutoConnectClient) { // now start the client client.Connect("localhost"); await AsyncUtil.WaitUntilWithTimeout(() => server.Players.Count > 0); // get the connections so that we can spawn players serverPlayer = server.Players.First(); clientPlayer = client.Player; // create a player object in the server serverPlayerGO = Object.Instantiate(playerPrefab); serverPlayerGO.name = "player (server)"; serverIdentity = serverPlayerGO.GetComponent <NetworkIdentity>(); serverComponent = serverPlayerGO.GetComponent <T>(); serverObjectManager.AddCharacter(serverPlayer, serverPlayerGO); // wait for client to spawn it await AsyncUtil.WaitUntilWithTimeout(() => clientPlayer.HasCharacter); clientIdentity = clientPlayer.Identity; clientPlayerGO = clientIdentity.gameObject; clientPlayerGO.name = "player (client)"; clientComponent = clientPlayerGO.GetComponent <T>(); } await LateSetup(); });