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)); }
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)); }
public void SetUp() { this.testGame = new Game(); BlueprintManager blueprintManager = new BlueprintManager(); Blueprint blueprint = new Blueprint(); blueprint.ComponentTypes.Add(typeof(TestComponent)); blueprintManager.AddBlueprint(TestBlueprintId, blueprint); this.testGame.BlueprintManager = blueprintManager; }
public void SetUp() { this.testGame = new Game(); BlueprintManager blueprintManager = new BlueprintManager(); Blueprint blueprint = new Blueprint(); blueprint.ComponentTypes.Add(typeof(TestComponent)); blueprintManager.AddBlueprint(TestBlueprintId, blueprint); this.testGame.BlueprintManager = blueprintManager; }
private void OnGUI() { // Reload blueprints if missing. if (blueprintManager == null) { // Load blueprints. LoadBlueprints(); } string removedBlueprintId = null; Type removedComponentType = null; // Summary. GUILayout.Label("Summary", EditorStyles.boldLabel); EditorGUILayout.LabelField("Blueprint file:", blueprintFileName); EditorGUILayout.LabelField("Selected blueprint:", this.selectedBlueprintId); if (GUILayout.Button("Save Blueprints")) { SaveBlueprints(); } EditorGUILayout.BeginHorizontal(); { this.blueprintListScrollPosition = EditorGUILayout.BeginScrollView( this.blueprintListScrollPosition, false, true); EditorGUILayout.BeginVertical(GUILayout.Width(200f)); { // List blueprints. GUILayout.Label("Blueprints", EditorStyles.boldLabel); foreach (var namedBlueprint in blueprintManager.Blueprints) { EditorGUILayout.BeginHorizontal(); { // Remove blueprint button. if (this.GUILayoutButtonRemove()) { removedBlueprintId = namedBlueprint.Key; } // Select blueprint button. if (GUILayout.Button(namedBlueprint.Key)) { this.selectedBlueprintId = namedBlueprint.Key; this.selectedBlueprint = hierarchicalBlueprintManager.GetBlueprint(this.selectedBlueprintId); } } EditorGUILayout.EndHorizontal(); } // Add blueprint button. EditorGUILayout.BeginHorizontal(); { this.newBlueprintId = EditorGUILayout.TextField("Add blueprint:", this.newBlueprintId); if (this.GUILayoutButtonAdd()) { try { var blueprint = new Blueprint(); blueprintManager.AddBlueprint(this.newBlueprintId, blueprint); } catch (ArgumentException e) { EditorUtility.DisplayDialog("Error", e.Message, "Close"); } } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); this.blueprintDetailsScrollPosition = EditorGUILayout.BeginScrollView(this.blueprintDetailsScrollPosition, false, true); EditorGUILayout.BeginVertical(); { if (this.selectedBlueprint != null) { // Components. GUILayout.Label("Components", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); { // Current components. EditorGUILayout.BeginVertical(); { GUILayout.Label("Current", EditorStyles.boldLabel); // Show parent blueprint components, but don't allow to remove them. foreach (var componentType in this.selectedBlueprint.GetAllComponentTypes().Except(this.selectedBlueprint.ComponentTypes)) { GUILayout.Label(componentType.Name); } // Show blueprint components. foreach (var componentType in this.selectedBlueprint.ComponentTypes) { EditorGUILayout.BeginHorizontal(); { // Remove component button. if (this.GUILayoutButtonRemove()) { removedComponentType = componentType; } GUILayout.Label(componentType.Name); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); // New components. EditorGUILayout.BeginVertical(); { GUILayout.Label("Other", EditorStyles.boldLabel); foreach (var componentType in inspectorTypeTable.Types().Except(this.selectedBlueprint.GetAllComponentTypes())) { EditorGUILayout.BeginHorizontal(); { // Add component button. if (this.GUILayoutButtonAdd()) { this.selectedBlueprint.ComponentTypes.Add(componentType); } GUILayout.Label(componentType.Name); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); // Attributes. GUILayout.Label("Attributes", EditorStyles.boldLabel); EditorGUIUtils.BlueprintComponentsField(this.selectedBlueprint, this.selectedBlueprint.AttributeTable, inspectorTypeTable, hierarchicalBlueprintManager); } } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); } EditorGUILayout.EndHorizontal(); // Remove data, if user wants to. if (removedBlueprintId != null) { blueprintManager.RemoveBlueprint(removedBlueprintId); this.selectedBlueprint = null; this.selectedBlueprintId = string.Empty; } if (this.selectedBlueprint != null && removedComponentType != null) { this.selectedBlueprint.ComponentTypes.Remove(removedComponentType); } }