/// <summary> /// Draws the entity configuration inspector. /// </summary> public override void OnInspectorGUI() { base.OnInspectorGUI(); this.entityConfigurationBehaviour = (EntityConfigurationBehaviour)this.target; if (EditorApplication.isPlaying) { // Show entity data. EditorGUILayout.LabelField( new GUIContent("Entity Id"), new GUIContent(this.entityConfigurationBehaviour.EntityId.ToString(CultureInfo.InvariantCulture))); EditorGUILayout.LabelField( new GUIContent("Blueprint Id"), new GUIContent(this.entityConfigurationBehaviour.BlueprintId)); } else { if (hierarchicalBlueprintManager == null) { // Load project blueprint data. this.LoadBlueprints(); } this.entityConfigurationBehaviour.BlueprintId = EditorGUIUtils.BlueprintIdSelection( new GUIContent("Blueprint"), this.entityConfigurationBehaviour.BlueprintId, inspectorComponentTypes, hierarchicalBlueprintManager); if (this.entityConfigurationBehaviour.Configuration == null) { // Create initial configuration. this.entityConfigurationBehaviour.Configuration = new AttributeTable(); } Blueprint selectedBlueprint = hierarchicalBlueprintManager.GetBlueprint(this.entityConfigurationBehaviour.BlueprintId); if (selectedBlueprint != null) { EditorGUIUtils.BlueprintComponentsField( selectedBlueprint, this.entityConfigurationBehaviour.Configuration, inspectorComponentTypes, hierarchicalBlueprintManager); } if (GUILayout.Button("Reload Blueprints")) { this.LoadBlueprints(); } } }
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); } }