public void OnStartClientCallsComponentsAndCatchesExceptions()
        {
            // add component
            UnityAction func = Substitute.For <UnityAction>();

            identity.OnStartClient.AddListener(func);

            func
            .When(f => f.Invoke())
            .Do(f => { throw new Exception("Some exception"); });

            // make sure exceptions are not swallowed
            Assert.Throws <Exception>(() =>
            {
                identity.StartClient();
            });
            func.Received().Invoke();

            // we have checks to make sure that it's only called once.
            Assert.DoesNotThrow(() =>
            {
                identity.StartClient();
            });
            func.Received(1).Invoke();
        }
        void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg)
        {
            if (msg.assetId != Guid.Empty)
            {
                identity.AssetId = msg.assetId;
            }

            if (!identity.gameObject.activeSelf)
            {
                identity.gameObject.SetActive(true);
            }

            identity.SetClientValues(this, msg);

            if (msg.isLocalPlayer)
            {
                InternalAddPlayer(identity);
            }

            // deserialize components if any payload
            // (Count is 0 if there were no components)
            if (msg.payload.Count > 0)
            {
                using (PooledNetworkReader payloadReader = NetworkReaderPool.GetReader(msg.payload))
                {
                    identity.OnDeserializeAllSafely(payloadReader, true);
                }
            }

            // objects spawned as part of initial state are started on a second pass
            identity.NotifyAuthority();
            identity.StartClient();
            CheckForLocalPlayer(identity);
        }
Exemple #3
0
        private void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg)
        {
            if (msg.prefabHash.HasValue)
            {
                identity.PrefabHash = msg.prefabHash.Value;
            }

            if (!identity.gameObject.activeSelf)
            {
                identity.gameObject.SetActive(true);
            }

            identity.SetClientValues(this, msg);

            if (msg.isLocalPlayer)
            {
                InternalAddCharacter(identity);
            }

            // deserialize components if any payload
            // (Count is 0 if there were no components)
            if (msg.payload.Count > 0)
            {
                using (var payloadReader = NetworkReaderPool.GetReader(msg.payload, Client.World))
                {
                    identity.OnDeserializeAll(payloadReader, true);
                }
            }

            // objects spawned as part of initial state are started on a second pass
            identity.NotifyAuthority();
            identity.StartClient();
            CheckForLocalPlayer(identity);
        }
Exemple #4
0
        void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg)
        {
            if (msg.assetId != Guid.Empty)
            {
                identity.AssetId = msg.assetId;
            }

            if (!identity.gameObject.activeSelf)
            {
                identity.gameObject.SetActive(true);
            }

            // apply local values for VR support
            identity.transform.localPosition = msg.position;
            identity.transform.localRotation = msg.rotation;
            identity.transform.localScale    = msg.scale;
            identity.HasAuthority            = msg.isOwner;
            identity.NetId  = msg.netId;
            identity.Client = Client;
            identity.ClientObjectManager = this;

            if (msg.isLocalPlayer)
            {
                InternalAddPlayer(identity);
            }

            // deserialize components if any payload
            // (Count is 0 if there were no components)
            if (msg.payload.Count > 0)
            {
                using (PooledNetworkReader payloadReader = NetworkReaderPool.GetReader(msg.payload))
                {
                    identity.OnDeserializeAllSafely(payloadReader, true);
                }
            }

            SpawnedObjects[msg.netId] = identity;

            // objects spawned as part of initial state are started on a second pass
            identity.NotifyAuthority();
            identity.StartClient();
            CheckForLocalPlayer(identity);
        }