Ejemplo n.º 1
0
        public void Setup()
        {
            go                         = new GameObject();
            client                     = go.AddComponent <NetworkClient>();
            server                     = go.AddComponent <NetworkServer>();
            spawner                    = go.AddComponent <CharacterSpawner>();
            sceneManager               = go.AddComponent <NetworkSceneManager>();
            serverObjectManager        = go.AddComponent <ServerObjectManager>();
            clientObjectManager        = go.AddComponent <ClientObjectManager>();
            spawner.SceneManager       = sceneManager;
            sceneManager.Client        = client;
            sceneManager.Server        = server;
            serverObjectManager.Server = server;
            clientObjectManager.Client = client;
            clientObjectManager.NetworkSceneManager = sceneManager;
            spawner.Client = client;
            spawner.Server = server;
            spawner.ServerObjectManager = serverObjectManager;
            spawner.ClientObjectManager = clientObjectManager;

            playerPrefab = new GameObject();
            NetworkIdentity playerId = playerPrefab.AddComponent <NetworkIdentity>();

            spawner.PlayerPrefab = playerId;

            pos1 = new GameObject().transform;
            pos2 = new GameObject().transform;
            spawner.startPositions.Add(pos1);
            spawner.startPositions.Add(pos2);
        }
Ejemplo n.º 2
0
        public static GameObject CreateNetworkManager()
        {
            var components = new Type[]
            {
                typeof(NetworkManager),
                typeof(NetworkServer),
                typeof(NetworkClient),
                typeof(NetworkSceneManager),
                typeof(ServerObjectManager),
                typeof(ClientObjectManager),
                typeof(CharacterSpawner),
                typeof(KcpTransport),
                typeof(LogSettings)
            };
            var go = new GameObject("NetworkManager", components);

            KcpTransport        transport = go.GetComponent <KcpTransport>();
            NetworkSceneManager nsm       = go.GetComponent <NetworkSceneManager>();

            NetworkClient networkClient = go.GetComponent <NetworkClient>();

            networkClient.Transport = transport;

            NetworkServer networkServer = go.GetComponent <NetworkServer>();

            networkServer.Transport = transport;

            ServerObjectManager serverObjectManager = go.GetComponent <ServerObjectManager>();

            serverObjectManager.Server = networkServer;
            serverObjectManager.NetworkSceneManager = nsm;

            ClientObjectManager clientObjectManager = go.GetComponent <ClientObjectManager>();

            clientObjectManager.Client = networkClient;
            clientObjectManager.NetworkSceneManager = nsm;

            NetworkManager networkManager = go.GetComponent <NetworkManager>();

            networkManager.Client = networkClient;
            networkManager.Server = networkServer;
            networkManager.ServerObjectManager = serverObjectManager;
            networkManager.ClientObjectManager = clientObjectManager;
            networkManager.NetworkSceneManager = nsm;

            CharacterSpawner playerSpawner = go.GetComponent <CharacterSpawner>();

            playerSpawner.Client              = networkClient;
            playerSpawner.Server              = networkServer;
            playerSpawner.SceneManager        = nsm;
            playerSpawner.ServerObjectManager = serverObjectManager;
            playerSpawner.ClientObjectManager = clientObjectManager;

            nsm.Client = networkClient;
            nsm.Server = networkServer;
            return(go);
        }
Ejemplo n.º 3
0
        public static GameObject CreateNetworkManager()
        {
            var components = new Type[]
            {
                typeof(NetworkManager),
                typeof(NetworkServer),
                typeof(NetworkClient),
                typeof(NetworkSceneManager),
                typeof(ServerObjectManager),
                typeof(ClientObjectManager),
                typeof(CharacterSpawner),
                typeof(UdpSocketFactory),
                typeof(LogSettings)
            };
            var go = new GameObject("NetworkManager", components);

            UdpSocketFactory    socketFactory = go.GetComponent <UdpSocketFactory>();
            NetworkSceneManager nsm           = go.GetComponent <NetworkSceneManager>();

            NetworkClient networkClient = go.GetComponent <NetworkClient>();

            networkClient.SocketFactory = socketFactory;

            NetworkServer networkServer = go.GetComponent <NetworkServer>();

            networkServer.SocketFactory = socketFactory;

            ServerObjectManager serverObjectManager = go.GetComponent <ServerObjectManager>();

            serverObjectManager.Server = networkServer;
            serverObjectManager.NetworkSceneManager = nsm;

            ClientObjectManager clientObjectManager = go.GetComponent <ClientObjectManager>();

            clientObjectManager.Client = networkClient;
            clientObjectManager.NetworkSceneManager = nsm;

            NetworkManager networkManager = go.GetComponent <NetworkManager>();

            networkManager.Client = networkClient;
            networkManager.Server = networkServer;
            networkManager.ServerObjectManager = serverObjectManager;
            networkManager.ClientObjectManager = clientObjectManager;
            networkManager.NetworkSceneManager = nsm;

            CharacterSpawner playerSpawner = go.GetComponent <CharacterSpawner>();

            playerSpawner.Client              = networkClient;
            playerSpawner.Server              = networkServer;
            playerSpawner.SceneManager        = nsm;
            playerSpawner.ServerObjectManager = serverObjectManager;
            playerSpawner.ClientObjectManager = clientObjectManager;

            nsm.Client = networkClient;
            nsm.Server = networkServer;
            return(go);
        }
Ejemplo n.º 4
0
        public void SetUp()
        {
            networkServerGameObject = new GameObject();
            server = networkServerGameObject.AddComponent <NetworkServer>();
            serverObjectManager        = networkServerGameObject.AddComponent <ServerObjectManager>();
            serverObjectManager.Server = server;
            networkServerGameObject.AddComponent <NetworkClient>();

            gameObject      = new GameObject();
            identity        = gameObject.AddComponent <NetworkIdentity>();
            identity.Server = server;
            identity.ServerObjectManager = serverObjectManager;

            tconn42 = Substitute.For <IConnection>();
            tconn43 = Substitute.For <IConnection>();
        }
        public void SetUp()
        {
            networkServerGameObject = new GameObject();
            server = networkServerGameObject.AddComponent <NetworkServer>();
            serverObjectManager        = networkServerGameObject.AddComponent <ServerObjectManager>();
            serverObjectManager.Server = server;
            networkServerGameObject.AddComponent <NetworkClient>();

            gameObject      = new GameObject();
            identity        = gameObject.AddComponent <NetworkIdentity>();
            identity.Server = server;
            identity.ServerObjectManager = serverObjectManager;

            player1 = Substitute.For <INetworkPlayer>();
            player2 = Substitute.For <INetworkPlayer>();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Call this function on an object to move it to a new scene and rebuild its observers
        /// </summary>
        /// <param name="scene"></param>
        public void MoveToScene(Scene scene)
        {
            INetworkPlayer owner = Identity.Owner;

            // remove player from other clients
            removeObservers(Identity);

            // remove other objects from player
            if (owner != null)
            {
                owner.RemoveAllVisibleObjects();
            }

            // move player to new scene
            SceneManager.MoveGameObjectToScene(Identity.gameObject, scene);

            // spawn new objects for player
            if (owner != null)
            {
                ServerObjectManager.SpawnVisibleObjects(Identity.Owner);
            }
        }