public static void DrawComponents(IEntity entity) { var unfoldedComponents = getUnfoldedComponents(entity); var componentMemberSearch = getComponentMemberSearch(entity); EditorLayout.BeginVerticalBox(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel); if (EditorLayout.MiniButtonLeft("▸")) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = false; } } if (EditorLayout.MiniButtonRight("▾")) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); var index = drawAddComponentMenu(entity); if (index >= 0) { var componentType = entity.contextInfo.componentTypes[index]; var component = entity.CreateComponent(index, componentType); entity.AddComponent(index, component); } EditorGUILayout.Space(); componentNameSearchString = EditorLayout.SearchTextField(componentNameSearchString); EditorGUILayout.Space(); var indices = entity.GetComponentIndices(); var components = entity.GetComponents(); for (int i = 0; i < components.Length; i++) { DrawComponent(unfoldedComponents, componentMemberSearch, entity, indices[i], components[i]); } } EditorLayout.EndVerticalBox(); }
public static void DrawEntity(IEntity entity) { var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUILayout.Button("Destroy Entity")) { entity.Destroy(); } GUI.backgroundColor = bgColor; DrawComponents(entity); EditorGUILayout.Space(); EditorGUILayout.LabelField("Retained by (" + entity.retainCount + ")", EditorStyles.boldLabel); var safeAerc = entity.aerc as SafeAERC; if (safeAerc != null) { EditorLayout.BeginVerticalBox(); { foreach (var owner in safeAerc.owners.OrderBy(o => o.GetType().Name)) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(owner.ToString()); if (EditorLayout.MiniButton("Release")) { entity.Release(owner); } EditorGUILayout.EndHorizontal(); } } } EditorLayout.EndVerticalBox(); } }
public static void DrawComponent(bool[] unfoldedComponents, string[] componentMemberSearch, IContext context, IEntity entity, int index, IComponent component) { var componentType = component.GetType(); var componentName = componentType.Name.RemoveComponentSuffix(); if (EditorLayout.MatchesSearchString(componentName.ToLower(), componentNameSearchString.ToLower())) { var boxStyle = getColoredBoxStyle(context, index); EditorGUILayout.BeginVertical(boxStyle); { var memberInfos = componentType.GetPublicMemberInfos(); EditorGUILayout.BeginHorizontal(); { if (memberInfos.Count == 0) { EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel); } else { unfoldedComponents[index] = EditorLayout.Foldout(unfoldedComponents[index], componentName, foldoutStyle); if (unfoldedComponents[index]) { componentMemberSearch[index] = memberInfos.Count > 5 ? EditorLayout.SearchTextField(componentMemberSearch[index]) : string.Empty; } } if (EditorLayout.MiniButton("-")) { entity.RemoveComponent(index); } } EditorGUILayout.EndHorizontal(); if (unfoldedComponents[index]) { var newComponent = entity.CreateComponent(index, componentType); component.CopyPublicMemberValues(newComponent); var changed = false; var componentDrawer = getComponentDrawer(componentType); if (componentDrawer != null) { EditorGUI.BeginChangeCheck(); { componentDrawer.DrawComponent(newComponent); } changed = EditorGUI.EndChangeCheck(); } else { foreach (var info in memberInfos) { if (EditorLayout.MatchesSearchString(info.name.ToLower(), componentMemberSearch[index].ToLower())) { var memberValue = info.GetValue(newComponent); var memberType = memberValue == null ? info.type : memberValue.GetType(); if (DrawObjectMember(memberType, info.name, memberValue, newComponent, info.SetValue)) { changed = true; } } } } if (changed) { entity.ReplaceComponent(index, newComponent); } else { entity.GetComponentPool(index).Push(newComponent); } } } EditorLayout.EndVerticalBox(); } }
public override void OnInspectorGUI() { var contextObserver = ((ContextObserverBehaviour)target).contextObserver; EditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField(contextObserver.context.contextInfo.name, EditorStyles.boldLabel); EditorGUILayout.LabelField("Entities", contextObserver.context.count.ToString()); EditorGUILayout.LabelField("Reusable entities", contextObserver.context.reusableEntitiesCount.ToString()); var retainedEntitiesCount = contextObserver.context.retainedEntitiesCount; if (retainedEntitiesCount != 0) { var c = GUI.color; GUI.color = Color.red; EditorGUILayout.LabelField("Retained entities", retainedEntitiesCount.ToString()); GUI.color = c; EditorGUILayout.HelpBox("WARNING: There are retained entities.\nDid you call entity.Retain(owner) and forgot to call entity.Release(owner)?", MessageType.Warning); } EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Create Entity")) { var entity = contextObserver.context.CreateEntity(); var entityBehaviour = Object.FindObjectsOfType <EntityBehaviour>() .Single(eb => eb.entity == entity); Selection.activeGameObject = entityBehaviour.gameObject; } var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUILayout.Button("Destroy All Entities")) { contextObserver.context.DestroyAllEntities(); } GUI.backgroundColor = bgColor; } EditorGUILayout.EndHorizontal(); } EditorLayout.EndVerticalBox(); var groups = contextObserver.groups; if (groups.Length != 0) { EditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField("Groups (" + groups.Length + ")", EditorStyles.boldLabel); foreach (var group in groups.OrderByDescending(g => g.count)) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(group.ToString()); EditorGUILayout.LabelField(group.count.ToString(), GUILayout.Width(48)); } EditorGUILayout.EndHorizontal(); } } EditorLayout.EndVerticalBox(); } EditorUtility.SetDirty(target); }