private void ComponentListings() { EditorGUILayout.BeginVertical(EditorExtensions.DefaultBoxStyle); this.WithHorizontalLayout(() => { this.WithLabel("Components (" + _entityView.Entity.Components.Count() + ")"); if (this.WithIconButton("▸")) { showComponents = false; } if (this.WithIconButton("▾")) { showComponents = true; } }); var componentsToRemove = new List <int>(); if (showComponents) { for (var i = 0; i < _entityView.Entity.Components.Count(); i++) { var currentIndex = i; this.UseVerticalBoxLayout(() => { var componentType = _entityView.Entity.Components.ElementAt(currentIndex).GetType(); var typeName = componentType.Name; var typeNamespace = componentType.Namespace; this.WithVerticalLayout(() => { this.WithHorizontalLayout(() => { if (this.WithIconButton("-")) { componentsToRemove.Add(currentIndex); } this.WithLabel(typeName); }); EditorGUILayout.LabelField(typeNamespace); EditorGUILayout.Space(); }); var component = _entityView.Entity.Components.ElementAt(currentIndex); ComponentUIAspect.ShowComponentProperties(component); }); } } EditorGUILayout.EndVertical(); for (var i = 0; i < componentsToRemove.Count(); i++) { var component = _entityView.Entity.Components.ElementAt(i); _entityView.Entity.RemoveComponent(component); } }
private void ComponentListings() { EditorGUILayout.BeginVertical(EditorExtensions.DefaultBoxStyle); this.WithHorizontalLayout(() => { this.WithLabel("Components (" + _entityView.Entity.Components.Count() + ")"); if (this.WithIconButton("▸")) { showComponents = false; } if (this.WithIconButton("▾")) { showComponents = true; } }); var componentsToRemove = new List <int>(); if (showComponents) { var currentComponents = _entityView.Entity.Components.ToArray(); for (var i = 0; i < currentComponents.Length; i++) { var currentIndex = i; this.UseVerticalBoxLayout(() => { var componentType = currentComponents[currentIndex].GetType(); var typeName = componentType.Name; var typeNamespace = componentType.Namespace; this.WithVerticalLayout(() => { this.WithHorizontalLayout(() => { if (this.WithIconButton("-")) { componentsToRemove.Add(currentIndex); } this.WithLabel(typeName); }); EditorGUILayout.LabelField(typeNamespace); EditorGUILayout.Space(); }); var component = currentComponents[currentIndex]; ComponentUIAspect.ShowComponentProperties(component); }); } } EditorGUILayout.EndVertical(); if (componentsToRemove.Count == 0) { return; } var activeComponents = _entityView.Entity.Components.ToArray(); var componentArray = new Type[componentsToRemove.Count]; for (var i = 0; i < componentsToRemove.Count; i++) { var component = activeComponents[i]; componentArray[i] = component.GetType(); } _entityView.Entity.RemoveComponents(componentArray); }
private void ComponentListings() { EditorGUILayout.BeginVertical(EditorExtensions.DefaultBoxStyle); this.WithHorizontalLayout(() => { this.WithLabel("Components (" + _registerAsEntity.Components.Count() + ")"); if (this.WithIconButton("▸")) { showComponents = false; } if (this.WithIconButton("▾")) { showComponents = true; } }); var componentsToRemove = new List <int>(); var componentCount = _registerAsEntity.Components.Count(); if (showComponents) { for (var i = 0; i < componentCount; i++) { var currentIndex = i; this.UseVerticalBoxLayout(() => { var componentType = _registerAsEntity.Components[currentIndex]; var namePortions = componentType.Split(',')[0].Split('.'); var typeName = namePortions.Last(); var typeNamespace = string.Join(".", namePortions.Take(namePortions.Length - 1).ToArray()); this.WithVerticalLayout(() => { this.WithHorizontalLayout(() => { if (this.WithIconButton("-")) { componentsToRemove.Add(currentIndex); } this.WithLabel(typeName); }); EditorGUILayout.LabelField(typeNamespace); EditorGUILayout.Space(); }); var componentTypeName = _registerAsEntity.Components[currentIndex]; // This error only really occurs if the scene has corrupted or an update has changed where editor state is stored on the underlying MB if (_registerAsEntity.ComponentEditorState.Count <= currentIndex) { Debug.LogError("It seems there is missing editor state for [" + componentTypeName + "] this can often be fixed by removing and re-adding the RegisterAsEntity MonoBehavior"); } var editorStateValue = _registerAsEntity.ComponentEditorState[currentIndex]; var component = ComponentUIAspect.RehydrateEditorComponent(componentTypeName, editorStateValue); ComponentUIAspect.ShowComponentProperties(component); var serializedData = component.SerializeComponent(); _registerAsEntity.ComponentEditorState[currentIndex] = serializedData.ToString(); }); } } EditorGUILayout.EndVertical(); for (var i = 0; i < componentsToRemove.Count(); i++) { _registerAsEntity.Components.RemoveAt(componentsToRemove[i]); _registerAsEntity.ComponentEditorState.RemoveAt(componentsToRemove[i]); } }