Beispiel #1
0
        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 #2
0
        void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg)
        {
            identity.Reset();

            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.Server = hostServer;
            identity.Client = 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);
                }
            }

            Spawned[msg.netId] = identity;

            // objects spawned as part of initial state are started on a second pass
            if (isSpawnFinished)
            {
                identity.NotifyAuthority();
                identity.StartClient();
                CheckForLocalPlayer(identity);
            }
        }
        static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg)
        {
            identity.Reset();
            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;

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

            // deserialize components if any payload
            // (Count is 0 if there were no components)
            if (msg.payload.Count > 0)
            {
                NetworkReader payloadReader = new NetworkReader(msg.payload);
                identity.OnUpdateVars(payloadReader, true);
            }

            NetworkIdentity.spawned[msg.netId] = identity;

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