コード例 #1
0
        public void TestDeinitRemovesChildEntity()
        {
            var entityManager = this.testGame.EntityManager;
            const string TestBlueprintId = "TestBlueprint";
            BlueprintManager blueprintManager;
            this.testGame.BlueprintManager = blueprintManager = new BlueprintManager();
            blueprintManager.AddBlueprint(TestBlueprintId, new Blueprint());

            TestInspectorTypeWithEntityProperty testType = new TestInspectorTypeWithEntityProperty();
            var testInspectorType = InspectorType.GetInspectorType(typeof(TestInspectorTypeWithEntityProperty));
            IAttributeTable configuration = new AttributeTable();
            EntityConfiguration childConfiguration = new EntityConfiguration { BlueprintId = TestBlueprintId };
            configuration.SetValue(TestInspectorTypeWithEntityProperty.AttributeMember1, childConfiguration);

            // Init.
            InspectorUtils.InitFromAttributeTable(entityManager, testInspectorType, testType, configuration);

            // Check that child entity was created.
            Assert.AreNotEqual(0, testType.EntityMember);

            // Deinit.
            InspectorUtils.Deinit(entityManager, testInspectorType, testType);

            // Check that child entity was removed.
            Assert.IsTrue(entityManager.EntityIsBeingRemoved(testType.EntityMember));
        }
コード例 #2
0
 /// <summary>
 ///   Copy constructor.
 /// </summary>
 /// <param name="entityConfiguration">Configuration to copy.</param>
 public EntityConfiguration(EntityConfiguration entityConfiguration)
 {
     this.BlueprintId = entityConfiguration.BlueprintId;
     this.additionalComponentTypes = entityConfiguration.additionalComponentTypes != null
                                         ? new List<Type>(entityConfiguration.additionalComponentTypes)
                                         : null;
     this.configuration = entityConfiguration.configuration != null
                              ? new AttributeTable(entityConfiguration.configuration)
                              : null;
 }
コード例 #3
0
 /// <summary>
 ///   Copy constructor.
 /// </summary>
 /// <param name="entityConfiguration">Configuration to copy.</param>
 public EntityConfiguration(EntityConfiguration entityConfiguration)
 {
     this.BlueprintId = entityConfiguration.BlueprintId;
     this.additionalComponentTypes = entityConfiguration.additionalComponentTypes != null
                                         ? new List <Type>(entityConfiguration.additionalComponentTypes)
                                         : null;
     this.configuration = entityConfiguration.configuration != null
                              ? new AttributeTable(entityConfiguration.configuration)
                              : null;
 }
コード例 #4
0
        public void TestDeserializationFromAttributeTable()
        {
            IAttributeTable attributeTable = new AttributeTable();
            AttributeTable entityAttributeTable = new AttributeTable();
            const string TestValueString = "Test";
            entityAttributeTable.SetValue(TestComponent.AttributeTestString, TestValueString);
            EntityConfiguration entityConfiguration = new EntityConfiguration
                {
                    BlueprintId = TestBlueprintId,
                    Configuration = entityAttributeTable
                };
            attributeTable.SetValue(TestData.AttributeTestEntity, entityConfiguration);

            TestData testData = InspectorUtils.CreateFromAttributeTable<TestData>(
                this.testGame.EntityManager, InspectorType.GetInspectorType(typeof(TestData)), attributeTable);
            Assert.AreNotEqual(testData.TestEntity, 0);
            Assert.AreNotEqual(testData.TestEntity, -1);

            // Check entity.
            TestComponent testComponent = this.testGame.EntityManager.GetComponent<TestComponent>(testData.TestEntity);
            Assert.NotNull(testComponent);
            Assert.AreEqual(testComponent.TestString, TestValueString);
        }
コード例 #5
0
 /// <summary>
 ///   Determines whether the specified <see cref="EntityConfiguration" /> is equal to the current
 ///   <see
 ///     cref="EntityConfiguration" />
 ///   .
 /// </summary>
 /// <returns>
 ///   true if the specified <see cref="EntityConfiguration" /> is equal to the current <see cref="EntityConfiguration" />; otherwise, false.
 /// </returns>
 /// <param name="other">
 ///   The <see cref="EntityConfiguration" /> to compare with the current <see cref="EntityConfiguration" />.
 /// </param>
 protected bool Equals(EntityConfiguration other)
 {
     return CollectionUtils.SequenceEqual(this.AdditionalComponentTypes, other.AdditionalComponentTypes)
            && Equals(this.Configuration, other.Configuration)
            && string.Equals(this.BlueprintId, other.BlueprintId);
 }
コード例 #6
0
 private static int CreateEntity(EntityManager entityManager, EntityConfiguration entityConfiguration)
 {
     int entityId = 0;
     if (entityConfiguration != null)
     {
         if (entityConfiguration.BlueprintId != null)
         {
             entityId = entityManager.CreateEntity(
                 entityConfiguration.BlueprintId,
                 entityConfiguration.Configuration);
         }
     }
     return entityId;
 }
コード例 #7
0
 /// <summary>
 ///   Tries to convert the specified text to a value of the correct type for this property.
 /// </summary>
 /// <param name="text">Text to convert.</param>
 /// <param name="value">Value of the correct type for this property, if the conversion was successful.</param>
 /// <returns>
 ///   True if the conversion was successful; otherwise, false.
 /// </returns>
 public override bool TryConvertStringToValue(string text, out object value)
 {
     if (string.IsNullOrEmpty(text))
     {
         value = null;
     }
     else
     {
         EntityConfiguration entityConfiguration = new EntityConfiguration { BlueprintId = text };
         value = entityConfiguration;
     }
     return true;
 }
コード例 #8
0
 /// <summary>
 ///   Determines whether the specified <see cref="EntityConfiguration" /> is equal to the current
 ///   <see
 ///     cref="EntityConfiguration" />
 ///   .
 /// </summary>
 /// <returns>
 ///   true if the specified <see cref="EntityConfiguration" /> is equal to the current <see cref="EntityConfiguration" />; otherwise, false.
 /// </returns>
 /// <param name="other">
 ///   The <see cref="EntityConfiguration" /> to compare with the current <see cref="EntityConfiguration" />.
 /// </param>
 protected bool Equals(EntityConfiguration other)
 {
     return(CollectionUtils.SequenceEqual(this.AdditionalComponentTypes, other.AdditionalComponentTypes) &&
            Equals(this.Configuration, other.Configuration) &&
            string.Equals(this.BlueprintId, other.BlueprintId));
 }