示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#4
0
        public void RegisterPrefabs(ClientObjectManager gameObject)
        {
            ISet <NetworkIdentity> prefabs = LoadPrefabsContaining <NetworkIdentity>("Assets");

            foreach (NetworkIdentity existing in gameObject.spawnPrefabs)
            {
                prefabs.Add(existing);
            }
            gameObject.spawnPrefabs.Clear();
            gameObject.spawnPrefabs.AddRange(prefabs);
        }
        public void RegisterPrefabs()
        {
            var gameObject = new GameObject("NetworkObjectManager", typeof(ClientObjectManager));

            ClientObjectManager client = gameObject.GetComponent <ClientObjectManager>();

            ClientObjectManagerInspector inspector = ScriptableObject.CreateInstance <ClientObjectManagerInspector>();

            inspector.RegisterPrefabs(client);

            Assert.That(client.spawnPrefabs, Has.Count.GreaterThan(2));
            GameObject.DestroyImmediate(gameObject);
            GameObject.DestroyImmediate(inspector);
        }
        public void PreserveExisting()
        {
            var preexisting = new GameObject("object", typeof(NetworkIdentity));

            var gameObject             = new GameObject("NetworkObjectManager", typeof(ClientObjectManager));
            ClientObjectManager client = gameObject.GetComponent <ClientObjectManager>();

            client.spawnPrefabs.Add(preexisting.GetComponent <NetworkIdentity>());

            ClientObjectManagerInspector inspector = ScriptableObject.CreateInstance <ClientObjectManagerInspector>();

            inspector.RegisterPrefabs(client);

            Assert.That(client.spawnPrefabs, Contains.Item(preexisting.GetComponent <NetworkIdentity>()));

            GameObject.DestroyImmediate(gameObject);
            GameObject.DestroyImmediate(preexisting);
        }
示例#7
0
        protected internal UniTask <T> SendServerRpcWithReturn <T>(Type invokeClass, string cmdName, NetworkWriter writer, int channelId, bool requireAuthority = true)
        {
            ValidateServerRpc(invokeClass, cmdName, requireAuthority);

            (UniTask <T> task, int id) = ClientObjectManager.CreateReplyTask <T>();

            // construct the message
            var message = new ServerRpcMessage
            {
                netId          = NetId,
                componentIndex = ComponentIndex,
                replyId        = id,
                // type+func so Inventory.RpcUse != Equipment.RpcUse
                functionHash = RemoteCallHelper.GetMethodHash(invokeClass, cmdName),
                // segment to avoid reader allocations
                payload = writer.ToArraySegment()
            };

            Client.Send(message, channelId);

            return(task);
        }