private void RebuildSharedComponents(VisualElement container) { container.Clear(); var header = new Label("Shared Components:"); header.AddToClassList("header"); container.Add(header); var element = new VisualElement(); var so = new SerializedObject(this.temp); var source = so.FindProperty("sharedComponents"); this.fieldsCacheSharedComponents.Clear(); DataConfigEditor.BuildInspectorPropertiesElement("data", this, null, source, element, noFields: false, onBuild: (index, propElement) => { this.fieldsCacheSharedComponents.Add(index, propElement); }); this.sharedComponentsDirty = true; container.Add(element); }
private void RebuildComponents(VisualElement container) { container.Clear(); var header = new Label("Components:"); header.AddToClassList("header"); container.Add(header); var element = new VisualElement(); var so = new SerializedObject(this.temp); foreach (var fields in this.fieldsCacheComponents) { fields.Value.Unbind(); } var source = so.FindProperty("components"); this.fieldsCacheComponents.Clear(); DataConfigEditor.BuildInspectorPropertiesElement("data", this, null, source, element, noFields: false, onBuild: (index, propElement) => { this.fieldsCacheComponents.Add(index, propElement); }); /* * this.fieldsCacheComponents.Clear(); * var prop = so.FindProperty("components"); * for (int i = 0; i < prop.arraySize; ++i) { * * var propField = prop.GetArrayElementAtIndex(i); * var dataField = propField.FindPropertyRelative("data"); * var field = new PropertyField(dataField); * field.BindProperty(dataField); * element.Add(field); * this.fieldsCacheComponents.Add(i, field); * * }*/ this.componentsDirty = true; container.Add(element); }
public static void BuildContainer(DataConfigEditor editor, VisualElement container, SerializedObject so) { var structComponents = new VisualElement(); var removeStructComponents = new VisualElement(); container.Clear(); var searchField = new ToolbarSearchField(); searchField.AddToClassList("search-field"); searchField.RegisterValueChangedCallback((evt) => { var search = evt.newValue.ToLower(); Search(search, structComponents); Search(search, removeStructComponents); }); container.Add(searchField); { var header = new Label("Components:"); header.AddToClassList("header"); container.Add(header); container.Add(structComponents); var usedComponents = new System.Collections.Generic.HashSet <System.Type>(); var source = so.FindProperty("structComponents"); BuildInspectorProperties(editor, usedComponents, source, structComponents, noFields: false); container.Add(CreateButton(editor, usedComponents, source, structComponents, noFields: false)); } { var header = new Label("Remove Components:"); header.AddToClassList("header"); container.Add(header); container.Add(removeStructComponents); var usedComponents = new System.Collections.Generic.HashSet <System.Type>(); var source = so.FindProperty("removeStructComponents"); BuildInspectorProperties(editor, usedComponents, source, removeStructComponents, noFields: true); container.Add(CreateButton(editor, usedComponents, source, removeStructComponents, noFields: true)); } editor.BuildUsedTemplates(container, so); }
private static IMGUIContainer CreateButton(DataConfigEditor editor, System.Collections.Generic.HashSet <System.Type> usedComponents, SerializedProperty source, VisualElement elements, bool noFields) { var addMenuButton = new IMGUIContainer(() => { GUILayoutExt.DrawAddComponentMenu(usedComponents, (type, isUsed) => { if (isUsed == false) { usedComponents.Add(type); source.serializedObject.Update(); ++source.arraySize; var elem = source.GetArrayElementAtIndex(source.arraySize - 1); elem.managedReferenceValue = System.Activator.CreateInstance(type); source.serializedObject.ApplyModifiedProperties(); if (noFields == true) { editor.OnAddComponentFromRemoveList(type); } else { editor.OnAddComponent(type); } } else { RemoveComponent(editor, usedComponents, source, type, noFields); } editor.Save(); BuildInspectorProperties(editor, usedComponents, source, elements, noFields); }, showRuntime: noFields); }); addMenuButton.AddToClassList("add-component-menu-button-imgui"); return(addMenuButton); }
private static void RemoveComponent(DataConfigEditor editor, System.Collections.Generic.HashSet <System.Type> usedComponents, SerializedProperty source, System.Type type, bool noFields) { var copy = source.Copy(); var i = 0; var enterChildren = true; while (copy.NextVisible(enterChildren) == true) { enterChildren = false; if (copy.propertyType != SerializedPropertyType.ManagedReference) { continue; } GetTypeFromManagedReferenceFullTypeName(copy.managedReferenceFullTypename, out var compType); if (compType == type) { source.serializedObject.Update(); usedComponents.Remove(type); source.DeleteArrayElementAtIndex(i); source.serializedObject.ApplyModifiedProperties(); if (noFields == true) { editor.OnRemoveComponentFromRemoveList(type); } else { editor.OnRemoveComponent(type); } break; } ++i; } }
public override VisualElement CreateInspectorGUI() { var container = new VisualElement(); container.styleSheets.Add(EditorUtilities.Load <StyleSheet>("Editor/Core/DataConfigs/styles.uss", isRequired: true)); this.rootElement = container; var target = this.target as ME.ECS.Debug.EntityDebugComponent; if (target.world != null && target.world.isActive == true) { this.debug = new ME.ECS.Debug.EntityProxyDebugger(target.entity, target.world); this.temp.components = this.debug.GetComponentsList(); this.temp.sharedComponents = this.debug.GetSharedComponentsList(); container.schedule.Execute(this.Update).Every((long)(target.world.GetTickTime() * 1000f)); var searchField = new ToolbarSearchField(); searchField.AddToClassList("search-field"); searchField.RegisterValueChangedCallback((evt) => { var search = evt.newValue.ToLower(); DataConfigEditor.Search(search, this.componentsContainer); DataConfigEditor.Search(search, this.sharedComponentsContainer); }); container.Add(searchField); { var entityElement = new VisualElement(); this.entityContainer = entityElement; entityElement.name = "EntityContainer"; entityElement.AddToClassList("entity-container"); var id = new Label("ID:"); id.AddToClassList("entity-container-item"); id.AddToClassList("entity-container-item-label"); entityElement.Add(id); var idValue = new Label(); idValue.AddToClassList("entity-container-item"); idValue.AddToClassList("entity-container-item-value"); idValue.name = "EntityId"; this.entityId = idValue; entityElement.Add(idValue); var gen = new Label("Generation:"); gen.AddToClassList("entity-container-item"); gen.AddToClassList("entity-container-item-label"); entityElement.Add(gen); var genValue = new Label(); genValue.AddToClassList("entity-container-item"); genValue.AddToClassList("entity-container-item-value"); genValue.name = "EntityGen"; this.entityGen = genValue; entityElement.Add(genValue); var version = new Label("Version:"); version.AddToClassList("entity-container-item"); version.AddToClassList("entity-container-item-label"); entityElement.Add(version); var versionValue = new Label(); versionValue.AddToClassList("entity-container-item"); versionValue.AddToClassList("entity-container-item-value"); versionValue.name = "EntityVersion"; this.entityVersion = versionValue; entityElement.Add(versionValue); container.Add(entityElement); var changedWarning = new Label("Selected entity is no longer available: generation has been changed."); this.entityContainerWarning = changedWarning; changedWarning.name = "EntityChanged"; changedWarning.AddToClassList("entity-changed-warning"); changedWarning.AddToClassList("hidden"); container.Add(changedWarning); } this.content = new VisualElement(); this.content.name = "Content"; container.Add(this.content); if (target.entity.IsAlive() == true) { this.BuildLists(this.content); } } else { var element = new Label("No active world found"); element.AddToClassList("world-not-found"); this.rootElement.Add(element); } return(this.rootElement); }
private static IMGUIContainer CreateTemplatesButton(DataConfigEditor editor, System.Collections.Generic.HashSet <ME.ECS.DataConfigs.DataConfigTemplate> usedComponents, VisualElement rootElement, VisualElement templatesContainer, SerializedProperty source, SerializedObject so, System.Action <SerializedObject, ME.ECS.DataConfigs.DataConfigTemplate> onAddTemplate, System.Action <SerializedObject, ME.ECS.DataConfigs.DataConfigTemplate> onRemoveTemplate) { var container = new IMGUIContainer(() => { GUILayoutExt.DrawManageDataConfigTemplateMenu(usedComponents, (template, isUsed) => { var path = AssetDatabase.GetAssetPath(template); var guid = AssetDatabase.AssetPathToGUID(path); if (string.IsNullOrEmpty(guid) == true) { return; } if (isUsed == true) { var copy = source.Copy(); var i = 0; var enterChildren = true; while (copy.NextVisible(enterChildren) == true) { enterChildren = false; if (copy.propertyType != SerializedPropertyType.String) { continue; } if (copy.stringValue == guid) { usedComponents.Remove(template); source.DeleteArrayElementAtIndex(i); so.ApplyModifiedProperties(); onRemoveTemplate.Invoke(so, template); break; } ++i; } } else { usedComponents.Add(template); onAddTemplate.Invoke(so, template); ++source.arraySize; var elem = source.GetArrayElementAtIndex(source.arraySize - 1); elem.stringValue = guid; so.ApplyModifiedProperties(); } editor.Save(); BuildContainer(editor, rootElement, so); }); }); container.AddToClassList("add-template-menu-button-imgui"); return(container); }