예제 #1
0
        public void ImplicitFrom_SetsValue()
        {
            // field = T implicit conversion should set .Value
            SyncVarGameObject field = go;

            Assert.That(field.Value, Is.EqualTo(go));
        }
예제 #2
0
        public void OperatorEquals()
        {
            // != null
            SyncVarGameObject field = new SyncVarGameObject(serverGO);

            // NOTE: this throws a compilation error, which is good!
            // we don't want users to do 'player.target == null'.
            // better to not compile than to fail silently.
            // Assert.That(field != null, Is.True);

            // different SyncVar<T>, same .Value
            SyncVarGameObject fieldSame = new SyncVarGameObject(serverGO);

            Assert.That(field == fieldSame, Is.True);
            Assert.That(field != fieldSame, Is.False);

            // different SyncVar<T>, different .Value
            SyncVarGameObject fieldNull = new SyncVarGameObject(null);

            Assert.That(field == fieldNull, Is.False);
            Assert.That(field != fieldNull, Is.True);

            // same GameObject
            Assert.That(field == serverGO, Is.True);
            Assert.That(field != serverGO, Is.False);

            // different GameObject
            GameObject other = new GameObject("other");

            Assert.That(field == other, Is.False);
            Assert.That(field != other, Is.True);
        }
예제 #3
0
        public void ImplicitTo()
        {
            SyncVarGameObject field = new SyncVarGameObject(go);
            // T = field implicit conversion should get .Value
            GameObject value = field;

            Assert.That(value, Is.EqualTo(go));
        }
예제 #4
0
        public void EqualsTest()
        {
            SyncVarGameObject fieldA = new SyncVarGameObject(go);
            SyncVarGameObject fieldB = new SyncVarGameObject(go);
            SyncVarGameObject fieldC = new SyncVarGameObject(null);

            Assert.That(fieldA.Equals(fieldB), Is.True);
            Assert.That(fieldA.Equals(fieldC), Is.False);
        }
예제 #5
0
        public void Value_GameObject()
        {
            SyncVarGameObject field = new SyncVarGameObject(null);

            // avoid 'not initialized' exception
            field.OnDirty = () => {};

            field.Value = go;
            Assert.That(field.Value, Is.EqualTo(go));
        }
예제 #6
0
        public void SerializeDeltaWritesNetId()
        {
            SyncVarGameObject field  = new SyncVarGameObject(go);
            NetworkWriter     writer = new NetworkWriter();

            field.OnSerializeDelta(writer);

            NetworkReader reader = new NetworkReader(writer.ToArraySegment());

            Assert.That(reader.ReadUInt(), Is.EqualTo(identity.netId));
        }
예제 #7
0
        public void PersistenceThroughDisappearance()
        {
            // field with identity
            SyncVarGameObject field = new SyncVarGameObject(go);

            // remove from spawned, shouldn't be found anymore
            NetworkServer.spawned.Remove(identity.netId);
            Assert.That(field.Value, Is.EqualTo(null));

            // add to spawned again
            // add to spawned again, should be found again
            NetworkServer.spawned[identity.netId] = identity;
            Assert.That(field.Value, Is.EqualTo(go));
        }
예제 #8
0
        public void DeserializeDeltaReadsNetId()
        {
            NetworkWriter writer = new NetworkWriter();

            writer.WriteUInt(identity.netId);
            NetworkReader reader = new NetworkReader(writer.ToArraySegment());

            SyncVarGameObject field = new SyncVarGameObject(null);

            // avoid 'not initialized' exception
            field.OnDirty = () => {};

            field.OnDeserializeDelta(reader);
            Assert.That(field.Value, Is.EqualTo(go));
        }
예제 #9
0
        public void Hook()
        {
            int called = 0;

            void OnChanged(GameObject oldValue, GameObject newValue)
            {
                ++called;
                Assert.That(oldValue, Is.Null);
                Assert.That(newValue, Is.EqualTo(go));
            }

            SyncVarGameObject field = new SyncVarGameObject(null, OnChanged);

            // avoid 'not initialized' exception
            field.OnDirty = () => {};

            field.Value = go;
            Assert.That(called, Is.EqualTo(1));
        }
예제 #10
0
        public void Constructor_GameObject()
        {
            SyncVarGameObject field = new SyncVarGameObject(go);

            Assert.That(field.Value, Is.EqualTo(go));
        }