Beispiel #1
0
        public void NotifyAuthorityCallsOnStartStopAuthority()
        {
            int startAuth = 0;
            int stopAuth  = 0;

            identity.OnAuthorityChanged.AddListener(auth =>
            {
                if (auth)
                {
                    startAuth++;
                }
                else
                {
                    stopAuth++;
                }
            });

            // set authority from false to true, which should call OnStartAuthority
            identity.HasAuthority = true;
            identity.NotifyAuthority();
            // shouldn't be touched
            Assert.That(identity.HasAuthority, Is.True);
            // start should be called
            Assert.That(startAuth, Is.EqualTo(1));
            Assert.That(stopAuth, Is.EqualTo(0));

            // set it to true again, should do nothing because already true
            identity.HasAuthority = true;
            identity.NotifyAuthority();
            // shouldn't be touched
            Assert.That(identity.HasAuthority, Is.True);
            // same as before
            Assert.That(startAuth, Is.EqualTo(1));
            Assert.That(stopAuth, Is.EqualTo(0));

            // set it to false, should call OnStopAuthority
            identity.HasAuthority = false;
            identity.NotifyAuthority();
            // shouldn't be touched
            Assert.That(identity.HasAuthority, Is.False);
            // same as before
            Assert.That(startAuth, Is.EqualTo(1));
            Assert.That(stopAuth, Is.EqualTo(1));

            // set it to false again, should do nothing because already false
            identity.HasAuthority = false;
            identity.NotifyAuthority();
            // shouldn't be touched
            Assert.That(identity.HasAuthority, Is.False);
            // same as before
            Assert.That(startAuth, Is.EqualTo(1));
            Assert.That(stopAuth, Is.EqualTo(1));
        }
        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);
        }
Beispiel #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);
        }
        public void NotifyAuthorityCallsOnStartStopAuthority()
        {
            // add components
            UnityAction startAuthFunc = Substitute.For <UnityAction>();
            UnityAction stopAuthFunc  = Substitute.For <UnityAction>();

            identity.OnStartAuthority.AddListener(startAuthFunc);
            identity.OnStopAuthority.AddListener(stopAuthFunc);

            // set authority from false to true, which should call OnStartAuthority
            identity.HasAuthority = true;
            identity.NotifyAuthority();
            // shouldn't be touched
            Assert.That(identity.HasAuthority, Is.True);
            // start should be called
            startAuthFunc.Received(1).Invoke();
            stopAuthFunc.Received(0).Invoke();

            // set it to true again, should do nothing because already true
            identity.HasAuthority = true;
            identity.NotifyAuthority();
            // shouldn't be touched
            Assert.That(identity.HasAuthority, Is.True);
            // same as before
            startAuthFunc.Received(1).Invoke();
            stopAuthFunc.Received(0).Invoke();

            // set it to false, should call OnStopAuthority
            identity.HasAuthority = false;
            identity.NotifyAuthority();
            // shouldn't be touched
            Assert.That(identity.HasAuthority, Is.False);
            // same as before
            startAuthFunc.Received(1).Invoke();
            stopAuthFunc.Received(1).Invoke();

            // set it to false again, should do nothing because already false
            identity.HasAuthority = false;
            identity.NotifyAuthority();
            // shouldn't be touched
            Assert.That(identity.HasAuthority, Is.False);
            // same as before
            startAuthFunc.Received(1).Invoke();
            stopAuthFunc.Received(1).Invoke();
        }
Beispiel #5
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);
        }
        internal void OnRemoveCharacter(RemoveCharacterMessage msg)
        {
            if (logger.LogEnabled())
            {
                logger.Log($"Client remove character handler");
            }

            INetworkPlayer  player   = Client.Player;
            NetworkIdentity identity = player.Identity;

            if (identity == null)
            {
                logger.LogWarning($"Could not find player's character");
                return;
            }

            player.Identity       = null;
            identity.HasAuthority = msg.keepAuthority;

            identity.NotifyAuthority();
        }