示例#1
0
        public void Setup()
        {
            go                         = new GameObject();
            client                     = go.AddComponent <NetworkClient>();
            server                     = go.AddComponent <NetworkServer>();
            spawner                    = go.AddComponent <PlayerSpawner>();
            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 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);
        }
示例#3
0
        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);
        }
示例#4
0
        public static GameObject CreateNetworkManager()
        {
            var go = new GameObject("NetworkManager", typeof(NetworkManager), typeof(NetworkServer), typeof(NetworkClient), typeof(NetworkSceneManager), typeof(ServerObjectManager), typeof(ClientObjectManager), typeof(PlayerSpawner), typeof(KcpTransport), typeof(LogSettings));

            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.sceneManager        = nsm;

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

            playerSpawner.client              = networkClient;
            playerSpawner.server              = networkServer;
            playerSpawner.sceneManager        = nsm;
            playerSpawner.serverObjectManager = serverObjectManager;
            playerSpawner.clientObjectManager = clientObjectManager;

            nsm.client = networkClient;
            nsm.server = networkServer;
            return(go);
        }
示例#5
0
        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);
        }
        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.SendAsync(message, channelId).Forget();

            return(task);
        }