示例#1
0
        public void Field_updates_get_called_for_non_blittable_fields()
        {
            using (var world = new World("test-world"))
            {
                var entityManager = world.GetOrCreateManager <EntityManager>();
                var entity        = entityManager.CreateEntity(typeof(NonBlittableComponent.Component));
                var reader        =
                    new NonBlittableComponent.Requirable.ReaderWriterImpl(entity, entityManager,
                                                                          new LoggingDispatcher());

                string     stringValue = null;
                List <int> listValue   = null;

                reader.StringFieldUpdated += newValue => { stringValue = newValue; };
                reader.ListFieldUpdated   += newValue => { listValue = newValue; };

                reader.OnComponentUpdate(new NonBlittableComponent.Update
                {
                    StringField = new Option <string>("new string"),
                    ListField   = new Option <List <int> >(new List <int>
                    {
                        5,
                        6,
                        7
                    })
                });

                Assert.AreEqual("new string", stringValue);
                Assert.AreEqual(new List <int> {
                    5, 6, 7
                }, listValue);
            }
        }
示例#2
0
        public void Data_returns_non_blittable_component_instance()
        {
            using (var world = new World("test-world"))
            {
                var entityManager = world.GetOrCreateManager <EntityManager>();
                var entity        = entityManager.CreateEntity(typeof(NonBlittableComponent.Component));
                var reader        =
                    new NonBlittableComponent.Requirable.ReaderWriterImpl(entity, entityManager,
                                                                          new LoggingDispatcher());

                var schemaComponentData = NonBlittableComponent.Component.CreateSchemaComponentData(
                    boolField: false,
                    intField: 0,
                    longField: 0,
                    floatField: 0,
                    doubleField: 0,
                    stringField: "test string",
                    optionalField: null,
                    listField: new List <int>(),
                    mapField: new Dictionary <int, string>()).SchemaData;

                if (schemaComponentData != null)
                {
                    entityManager.SetComponentData(entity, NonBlittableComponent.Serialization.Deserialize(
                                                       schemaComponentData.Value.GetFields(), world));
                }

                var data = entityManager.GetComponentData <NonBlittableComponent.Component>(entity);

                Assert.AreEqual(data, reader.Data);
                Assert.AreEqual("test string", reader.Data.StringField);
            }
        }
示例#3
0
        public void Updating_field_leaves_other_field_unchanged()
        {
            using (var world = new World("test-world"))
            {
                var entityManager = world.GetOrCreateManager <EntityManager>();
                var entity        = entityManager.CreateEntity(typeof(NonBlittableComponent.Component));
                entityManager.AddComponentData(entity, new SpatialEntityId());

                var schemaComponentData = NonBlittableComponent.Component.CreateSchemaComponentData(
                    boolField: false,
                    intField: 0,
                    longField: 0,
                    floatField: 0,
                    doubleField: 13.37,
                    stringField: "stringy",
                    optionalField: null,
                    listField: new List <int>(),
                    mapField: new Dictionary <int, string>()).SchemaData;

                if (schemaComponentData != null)
                {
                    entityManager.SetComponentData(entity, NonBlittableComponent.Serialization.Deserialize(
                                                       schemaComponentData.Value.GetFields(), world));
                }

                var writer =
                    new NonBlittableComponent.Requirable.ReaderWriterImpl(entity, entityManager,
                                                                          new LoggingDispatcher());
                writer.Send(new NonBlittableComponent.Update
                {
                    IntField  = new Option <int>(42),
                    ListField = new Option <List <int> >(new List <int>
                    {
                        5,
                        6,
                        7
                    })
                });

                double doubleRead = entityManager.GetComponentData <NonBlittableComponent.Component>(entity).DoubleField;
                Assert.AreEqual(13.37, doubleRead);
                string stringRead = entityManager.GetComponentData <NonBlittableComponent.Component>(entity).StringField;
                Assert.AreEqual("stringy", stringRead);
            }
        }
示例#4
0
        public void Sending_component_update_changes_field()
        {
            using (var world = new World("test-world"))
            {
                var entityManager = world.GetOrCreateManager <EntityManager>();
                var entity        = entityManager.CreateEntity(typeof(NonBlittableComponent.Component));
                entityManager.SetComponentData(entity, new NonBlittableComponent.Component());
                var writer =
                    new NonBlittableComponent.Requirable.ReaderWriterImpl(entity, entityManager,
                                                                          new LoggingDispatcher());

                writer.Send(new NonBlittableComponent.Update
                {
                    IntField = new Option <int>(42)
                });

                int valueRead = entityManager.GetComponentData <NonBlittableComponent.Component>(entity).IntField;
                Assert.AreEqual(42, valueRead);
            }
        }