public void Draw(EntitasPreferencesConfig config) { EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField("VisualDebugging", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); { _enableVisualDebugging = EditorGUILayout.Toggle("Enable Visual Debugging", _enableVisualDebugging); } var changed = EditorGUI.EndChangeCheck(); if (changed) { if (_enableVisualDebugging) { _scriptingDefineSymbols.RemoveDefineSymbol(ENTITAS_DISABLE_VISUAL_DEBUGGING); } else { _scriptingDefineSymbols.AddDefineSymbol(ENTITAS_DISABLE_VISUAL_DEBUGGING); } } EditorGUILayout.Space(); _visualDebuggingConfig.defaultInstanceCreatorFolderPath = EditorGUILayout.TextField("DefaultInstanceCreator Folder", _visualDebuggingConfig.defaultInstanceCreatorFolderPath); _visualDebuggingConfig.typeDrawerFolderPath = EditorGUILayout.TextField("TypeDrawer Folder", _visualDebuggingConfig.typeDrawerFolderPath); } EntitasEditorLayout.EndVertical(); }
public override void OnInspectorGUI() { LuaEntity entity = target as LuaEntity; var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUILayout.Button("Destroy Entity")) { LuaEntity.DestroyEntity(entity.poolName, entity.entityId); } GUI.backgroundColor = bgColor; DrawComponents(entity.poolName, entity.entityId); EditorGUILayout.Space(); EditorGUILayout.LabelField("Retained by (" + LuaEntity.GetEntityRetainCount(entity.poolName, entity.entityId) + ")", EditorStyles.boldLabel); EntitasEditorLayout.BeginVerticalBox(); { string[] owners = LuaEntity.GetEntityOwners(entity.poolName, entity.entityId); foreach (var owner in owners) { EditorGUILayout.LabelField(owner); } } EntitasEditorLayout.EndVertical(); }
public static void DrawComponents(IContext context, IEntity entity, bool hideInBlueprintInspector = false) { bool[] unfoldedComponents; if (!_contextToUnfoldedComponents.TryGetValue(context, out unfoldedComponents)) { unfoldedComponents = new bool[context.totalComponents]; for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } _contextToUnfoldedComponents.Add(context, unfoldedComponents); } EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel); if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = false; } } if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); var index = drawAddComponentMenu(entity, hideInBlueprintInspector); if (index >= 0) { var componentType = entity.contextInfo.componentTypes[index]; var component = (IComponent)Activator.CreateInstance(componentType); entity.AddComponent(index, component); } EditorGUILayout.Space(); _componentNameSearchString = EntitasEditorLayout.SearchTextField(_componentNameSearchString); EditorGUILayout.Space(); var indices = entity.GetComponentIndices(); var components = entity.GetComponents(); for (int i = 0; i < components.Length; i++) { DrawComponent(unfoldedComponents, entity, indices[i], components[i]); } } EntitasEditorLayout.EndVertical(); }
void OnGUI() { _scrollViewPosition = EditorGUILayout.BeginScrollView(_scrollViewPosition); { var offsetY = EntitasEditorLayout.DrawHeaderTexture(this, _headerTexture); EditorGUILayout.Space(); EditorGUILayout.LabelField("Version: " + _localVersion); GUILayout.Space(offsetY - 24); var descriptionStyle = new GUIStyle(GUI.skin.label); descriptionStyle.wordWrap = true; foreach (var migration in _migrations) { EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField(migration.version, EditorStyles.boldLabel); EditorGUILayout.LabelField(migration.description, descriptionStyle); if (GUILayout.Button("Apply migration " + migration.version)) { migrate(migration); } } EntitasEditorLayout.EndVertical(); } } EditorGUILayout.EndScrollView(); }
public static object DrawAndGetNewValue(Type type, string fieldName, object value, Entity entity, int index, IComponent component) { if (value == null) { var isUnityObject = type == typeof(UnityEngine.Object) || type.IsSubclassOf(typeof(UnityEngine.Object)); EntitasEditorLayout.BeginHorizontal(); { if (isUnityObject) { value = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)value, type, true); } else { EditorGUILayout.LabelField(fieldName, "null"); } if (GUILayout.Button("Create", GUILayout.Height(14))) { object defaultValue; if (CreateDefault(type, out defaultValue)) { value = defaultValue; } } } EntitasEditorLayout.EndHorizontal(); return(value); } if (!type.IsValueType) { EntitasEditorLayout.BeginHorizontal(); EntitasEditorLayout.BeginVertical(); } var typeDrawer = getTypeDrawer(type); if (typeDrawer != null) { value = typeDrawer.DrawAndGetNewValue(type, fieldName, value, entity, index, component); } else { drawUnsupportedType(type, fieldName, value); } if (!type.IsValueType) { EntitasEditorLayout.EndVertical(); if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) { value = null; } EntitasEditorLayout.EndHorizontal(); } return(value); }
void drawCodeGenerators() { EditorGUILayout.Space(); EditorGUILayout.LabelField("Code Generators", EditorStyles.boldLabel); var enabledCodeGenerators = new HashSet <string>(_codeGeneratorConfig.enabledCodeGenerators); var availableGeneratorNames = new HashSet <string>(); EntitasEditorLayout.BeginHorizontal(); { var rect = EntitasEditorLayout.BeginVertical(); if (rect.height > 0) { _generatorsRectHeight = rect.height - 2; } { foreach (var codeGenerator in _codeGenerators) { availableGeneratorNames.Add(codeGenerator.Name); var isEnabled = enabledCodeGenerators.Contains(codeGenerator.Name); isEnabled = EditorGUILayout.Toggle(codeGenerator.Name.Replace("Generator", string.Empty), isEnabled); if (isEnabled) { enabledCodeGenerators.Add(codeGenerator.Name); } else { enabledCodeGenerators.Remove(codeGenerator.Name); } } } EntitasEditorLayout.EndVertical(); var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.green; if (GUILayout.Button("Generate", GUILayout.Width(200), GUILayout.Height(_generatorsRectHeight))) { UnityCodeGenerator.Generate(); } GUI.backgroundColor = bgColor; } EntitasEditorLayout.EndHorizontal(); foreach (var generatorName in _codeGeneratorConfig.enabledCodeGenerators.ToArray()) { if (!availableGeneratorNames.Contains(generatorName)) { enabledCodeGenerators.Remove(generatorName); } } var sortedCodeGenerators = enabledCodeGenerators.ToArray(); Array.Sort(sortedCodeGenerators); _codeGeneratorConfig.enabledCodeGenerators = sortedCodeGenerators; }
static void drawSystemsOverview(string systemsName) { EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField(systemsName, EditorStyles.boldLabel); EditorGUILayout.LabelField("Initialize Systems", Convert.ToInt32(LuaSystems.GetProfile(systemsName)["initializesystemcount"]).ToString()); EditorGUILayout.LabelField("Execute Systems", Convert.ToInt32(LuaSystems.GetProfile(systemsName)["executesystemcount"]).ToString()); EditorGUILayout.LabelField("Total Systems", Convert.ToInt32(LuaSystems.GetProfile(systemsName)["allsystemcount"]).ToString()); } EntitasEditorLayout.EndVertical(); }
void drawSystemsMonitor(string systemsName) { if (_systemsMonitor == null) { _systemsMonitor = new SystemsMonitor(SYSTEM_MONITOR_DATA_LENGTH); _systemMonitorData = new Queue <float>(new float[SYSTEM_MONITOR_DATA_LENGTH]); if (EditorApplication.update != Repaint) { EditorApplication.update += Repaint; } } EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField("Execution duration", EditorStyles.boldLabel); EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField("Total", string.Format("{0:0.000}", LuaSystems.GetProfile(systemsName)["executecostnow"])); var buttonStyle = new GUIStyle(GUI.skin.button); if (!(bool)LuaSystems.GetProfile(systemsName)["enable"]) { buttonStyle.normal = GUI.skin.button.active; } if (GUILayout.Button("▌▌", buttonStyle, GUILayout.Width(50))) { LuaSystems.GetProfile(systemsName)["enable"] = !(bool)LuaSystems.GetProfile(systemsName)["enable"]; } if (GUILayout.Button("Step", GUILayout.Width(50))) { LuaSystems.Step(systemsName); } } EntitasEditorLayout.EndHorizontal(); if (!EditorApplication.isPaused) { LuaSystems systems = target as LuaSystems; if ((bool)LuaSystems.GetProfile(systemsName)["enable"]) { addDuration(Convert.ToSingle(LuaSystems.GetProfile(systemsName)["executecostnow"])); } else if (systems.stepState == LuaSystems.StepState.Over) { systems.stepState = LuaSystems.StepState.Disable; addDuration(Convert.ToSingle(LuaSystems.GetProfile(systemsName)["executecostnow"])); } } _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f); } EntitasEditorLayout.EndVertical(); }
static void drawSystemsOverview(DebugSystems systems) { EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField(systems.name, EditorStyles.boldLabel); EditorGUILayout.LabelField("Initialize Systems", systems.initializeSystemsCount.ToString()); EditorGUILayout.LabelField("Execute Systems", systems.executeSystemsCount.ToString()); EditorGUILayout.LabelField("Total Systems", systems.totalSystemsCount.ToString()); } EntitasEditorLayout.EndVertical(); }
public void Draw(EntitasPreferencesConfig config) { EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField("Code Generator", EditorStyles.boldLabel); drawGeneratedFolderPath(); drawPools(); drawCodeGenerators(); } EntitasEditorLayout.EndVertical(); }
void drawSystemList(DebugSystems systems) { EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval); if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14))) { systems.ResetDurations(); } } EntitasEditorLayout.EndHorizontal(); _threshold = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f); _sortSystemInfos = EditorGUILayout.Toggle("Sort by execution duration", _sortSystemInfos); _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems); EditorGUILayout.Space(); _systemNameSearchTerm = EditorGUILayout.TextField("Search", _systemNameSearchTerm); _showInitializeSystems = EditorGUILayout.Foldout(_showInitializeSystems, "Initialize Systems"); if (_showInitializeSystems && shouldShowSystems(systems, true)) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systems, true, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } _showExecuteSystems = EditorGUILayout.Foldout(_showExecuteSystems, "Execute Systems"); if (_showExecuteSystems && shouldShowSystems(systems, false)) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systems, false, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } } EntitasEditorLayout.EndVertical(); }
void drawCodeGenerators() { EditorGUILayout.Space(); EditorGUILayout.LabelField("Code Generators", EditorStyles.boldLabel); var enabledCodeGenerators = new HashSet <string>(_codeGeneratorConfig.enabledCodeGenerators); var availableGeneratorNames = new HashSet <string>(); EntitasEditorLayout.BeginHorizontal(); { EntitasEditorLayout.BeginVertical(); { foreach (var codeGenerator in _codeGenerators) { availableGeneratorNames.Add(codeGenerator.Name); var isEnabled = enabledCodeGenerators.Contains(codeGenerator.Name); isEnabled = EditorGUILayout.Toggle(codeGenerator.Name, isEnabled); if (isEnabled) { enabledCodeGenerators.Add(codeGenerator.Name); } else { enabledCodeGenerators.Remove(codeGenerator.Name); } } } EntitasEditorLayout.EndVertical(); if (GUILayout.Button("Generate", GUILayout.Width(200), GUILayout.Height(68))) { UnityCodeGenerator.Generate(); } } EntitasEditorLayout.EndHorizontal(); foreach (var generatorName in _codeGeneratorConfig.enabledCodeGenerators.ToArray()) { if (!availableGeneratorNames.Contains(generatorName)) { enabledCodeGenerators.Remove(generatorName); } } var sortedCodeGenerators = enabledCodeGenerators.ToArray(); Array.Sort(sortedCodeGenerators); _codeGeneratorConfig.enabledCodeGenerators = sortedCodeGenerators; }
void drawSystemsMonitor(DebugSystems systems) { if (_systemsMonitor == null) { _systemsMonitor = new SystemsMonitor(SYSTEM_MONITOR_DATA_LENGTH); _systemMonitorData = new Queue <float>(new float[SYSTEM_MONITOR_DATA_LENGTH]); if (EditorApplication.update != Repaint) { EditorApplication.update += Repaint; } } EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField("Execution duration", EditorStyles.boldLabel); EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField("Total", systems.totalDuration.ToString()); var buttonStyle = new GUIStyle(GUI.skin.button); if (systems.paused) { buttonStyle.normal = GUI.skin.button.active; } if (GUILayout.Button("▌▌", buttonStyle, GUILayout.Width(50))) { systems.paused = !systems.paused; } if (GUILayout.Button("Step", GUILayout.Width(50))) { systems.paused = true; systems.Step(); addDuration((float)systems.totalDuration); _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f); } } EntitasEditorLayout.EndHorizontal(); if (!EditorApplication.isPaused && !systems.paused) { addDuration((float)systems.totalDuration); } _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f); } EntitasEditorLayout.EndVertical(); }
public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component) { var componentType = component.GetType(); var componentName = EntityExtension.RemoveComponentSuffix(componentType.Name); if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) { var fields = componentType.GetFields(BindingFlags.Public | BindingFlags.Instance); var boxStyle = getColoredBoxStyle(entity.totalComponents, index); EntitasEditorLayout.BeginVerticalBox(boxStyle); { EntitasEditorLayout.BeginHorizontal(); { if (fields.Length == 0) { EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel); } else { unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle); } if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) { entity.RemoveComponent(index); } } EntitasEditorLayout.EndHorizontal(); if (unfoldedComponents[index]) { foreach (var field in fields) { var value = field.GetValue(component); DrawAndSetElement(field.FieldType, field.Name, value, entity, index, component, field.SetValue); } } } EntitasEditorLayout.EndVertical(); } }
public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component) { var componentType = component.GetType(); var componentName = componentType.Name.RemoveComponentSuffix(); if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) { var memberInfos = componentType.GetPublicMemberInfos(); var boxStyle = getColoredBoxStyle(entity.totalComponents, index); EntitasEditorLayout.BeginVerticalBox(boxStyle); { EntitasEditorLayout.BeginHorizontal(); { if (memberInfos.Length == 0) { EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel); } else { unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle); } if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) { entity.RemoveComponent(index); } } EntitasEditorLayout.EndHorizontal(); if (unfoldedComponents[index]) { foreach (var info in memberInfos) { DrawAndSetElement(info.type, info.name, info.GetValue(component), entity, index, component, info.SetValue); } } } EntitasEditorLayout.EndVertical(); } }
static bool draw(string propertyName, object value, bool drawLuaTable, out object nvalue) { bool ret = false; if (value == null) { nvalue = null; EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField(propertyName, "null"); if (GUILayout.Button("CreateString", GUILayout.Height(14))) { nvalue = string.Empty; ret = true; } if (GUILayout.Button("CreateNumber", GUILayout.Height(14))) { nvalue = 0d; ret = true; } } EntitasEditorLayout.EndHorizontal(); return(ret); } EntitasEditorLayout.BeginVertical(); { PropertyDrawer drawer; if ((!drawLuaTable && value is LuaTable) || !propertyTypeDrawer.TryGetValue(value.GetType(), out drawer)) { drawer = defaultDrawer; } ret = drawer(propertyName, value, out nvalue); } EntitasEditorLayout.EndVertical(); return(ret); }
public void Draw(EntitasPreferencesConfig config) { EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField("Code Generator", EditorStyles.boldLabel); drawGeneratedFolderPath(); drawContexts(); _codeGeneratorConfig.dataProviders = drawMaskField("Data Providers", _availableDataProviderTypes, _availableDataProviderNames, _codeGeneratorConfig.dataProviders); _codeGeneratorConfig.codeGenerators = drawMaskField("Code Generators", _availableGeneratorTypes, _availableGeneratorNames, _codeGeneratorConfig.codeGenerators); _codeGeneratorConfig.postProcessors = drawMaskField("Post Processors", _availablePostProcessorTypes, _availablePostProcessorNames, _codeGeneratorConfig.postProcessors); var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.green; if (GUILayout.Button("Generate", GUILayout.Height(32))) { UnityCodeGenerator.Generate(); } GUI.backgroundColor = bgColor; } EntitasEditorLayout.EndVertical(); }
void DrawComponent(string poolName, int entityId, int componentId, Dictionary <int, bool> state) { LuaEntity.ComponentStruct componentStruct = LuaEntity.GetComponentStruct(componentId); if (componentStruct.fullName.ToLower().Contains(componentNameSearchTerm.ToLower())) { var boxStyle = getColoredBoxStyle(LuaEntity.GetComponentSelectText().Length, componentStruct.id); EntitasEditorLayout.BeginVerticalBox(boxStyle); { EntitasEditorLayout.BeginHorizontal(); { if (componentStruct.propertyNames.Length == 0) { EditorGUILayout.LabelField(componentStruct.fullName, EditorStyles.boldLabel); } else { state[componentId] = EditorGUILayout.Foldout(state[componentId], componentStruct.fullName, foldoutStyle); } if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) { LuaEntity.RemoveComponent(poolName, entityId, componentId); } } EntitasEditorLayout.EndHorizontal(); if (state[componentId]) { foreach (var propertyName in componentStruct.propertyNames) { DrawAndSetElement(poolName, entityId, componentId, propertyName); } } } EntitasEditorLayout.EndVertical(); } }
public static void DrawEntity(IContext context, IEntity entity) { var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUILayout.Button("Destroy Entity")) { context.DestroyEntity(entity); } GUI.backgroundColor = bgColor; DrawComponents(context, entity); EditorGUILayout.Space(); EditorGUILayout.LabelField("Retained by (" + entity.retainCount + ")", EditorStyles.boldLabel); #if !ENTITAS_FAST_AND_UNSAFE EntitasEditorLayout.BeginVerticalBox(); { foreach (var owner in entity.owners.OrderBy(o => o.GetType().Name)) { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField(owner.ToString()); if (GUILayout.Button("Release", GUILayout.Width(88), GUILayout.Height(14))) { entity.Release(owner); } EntitasEditorLayout.EndHorizontal(); } } } EntitasEditorLayout.EndVertical(); #endif }
public override void OnInspectorGUI() { var poolObserver = ((PoolObserverBehaviour)target).poolObserver; EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField(poolObserver.pool.metaData.poolName, EditorStyles.boldLabel); EditorGUILayout.LabelField("Entities", poolObserver.pool.count.ToString()); EditorGUILayout.LabelField("Reusable entities", poolObserver.pool.reusableEntitiesCount.ToString()); var retainedEntitiesCount = poolObserver.pool.retainedEntitiesCount; if (retainedEntitiesCount != 0) { var c = GUI.contentColor; 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); } EntitasEditorLayout.BeginHorizontal(); { if (GUILayout.Button("Create Entity")) { var entity = poolObserver.pool.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")) { poolObserver.pool.DestroyAllEntities(); } GUI.backgroundColor = bgColor; } EntitasEditorLayout.EndHorizontal(); } EntitasEditorLayout.EndVertical(); var groups = poolObserver.groups; if (groups.Length != 0) { EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.LabelField("Groups (" + groups.Length + ")", EditorStyles.boldLabel); foreach (var group in groups.OrderByDescending(g => g.count)) { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField(group.ToString()); EditorGUILayout.LabelField(group.count.ToString(), GUILayout.Width(48)); } EntitasEditorLayout.EndHorizontal(); } if (GUILayout.Button("Clear Groups")) { poolObserver.pool.ClearGroups(); } } EntitasEditorLayout.EndVertical(); } EditorUtility.SetDirty(target); }
public static void DrawComponents(Pool pool, Entity entity) { bool[] unfoldedComponents; if (!_poolToUnfoldedComponents.TryGetValue(pool, out unfoldedComponents)) { unfoldedComponents = new bool[pool.totalComponents]; for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } _poolToUnfoldedComponents.Add(pool, unfoldedComponents); } EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel); if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = false; } } if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); var componentNames = entity.poolMetaData.componentNames; var index = EditorGUILayout.Popup("Add Component", -1, componentNames); if (index >= 0) { var componentType = entity.poolMetaData.componentTypes[index]; var component = (IComponent)Activator.CreateInstance(componentType); entity.AddComponent(index, component); } EditorGUILayout.Space(); EntitasEditorLayout.BeginHorizontal(); { _componentNameSearchTerm = EditorGUILayout.TextField("Search", _componentNameSearchTerm); const string clearButtonControlName = "Clear Button"; GUI.SetNextControlName(clearButtonControlName); if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) { _componentNameSearchTerm = string.Empty; GUI.FocusControl(clearButtonControlName); } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); var indices = entity.GetComponentIndices(); var components = entity.GetComponents(); for (int i = 0; i < components.Length; i++) { DrawComponent(unfoldedComponents, entity, indices[i], components[i]); } } EntitasEditorLayout.EndVertical(); }
public override void OnInspectorGUI() { LuaPool pool = target as LuaPool; string poolName = pool.poolName; EntitasEditorLayout.BeginVerticalBox(); { int totalCount, reusableCount, retainedCount; LuaPool.GetEntitiesCount(poolName, out totalCount, out reusableCount, out retainedCount); EditorGUILayout.LabelField(poolName, EditorStyles.boldLabel); EditorGUILayout.LabelField("Entities", (totalCount - reusableCount - retainedCount).ToString()); EditorGUILayout.LabelField("Reusable entities", reusableCount.ToString()); if (retainedCount != 0) { var c = GUI.contentColor; GUI.color = Color.red; EditorGUILayout.LabelField("Retained entities", retainedCount.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); } else { EditorGUILayout.LabelField("Retained entities", retainedCount.ToString()); } EntitasEditorLayout.BeginHorizontal(); { if (GUILayout.Button("Create Entity")) { LuaPool.CreateEntity(poolName); } var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUILayout.Button("Destroy All Entities")) { LuaPool.DestroyAllEntity(poolName); } GUI.backgroundColor = bgColor; } EntitasEditorLayout.EndHorizontal(); } EntitasEditorLayout.EndVertical(); Dictionary <string, KeyValuePair <int, int> > groupsInfo = new Dictionary <string, KeyValuePair <int, int> >(); using (var enumerator = LuaPool.GetGroupsInfo(poolName).GetEnumerator()) { while ((enumerator.MoveNext())) { LuaTable info = enumerator.Current.Value as LuaTable; groupsInfo.Add(info["desc"].ToString(), new KeyValuePair <int, int>( System.Convert.ToInt32(((LuaTable)info["matcher"])["id"]), System.Convert.ToInt32(((LuaTable)info["entities"])["count"]))); } } if (groupsInfo.Count > 0) { EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField("Groups (" + groupsInfo.Count + ")", EditorStyles.boldLabel, GUILayout.Width(100)); EditorGUILayout.LabelField("sort", GUILayout.Width(30)); sortGroups = EditorGUILayout.Toggle(sortGroups); if (pool.entityDisplayMatcherIds.Count > 0 && GUILayout.Button("clean filter", GUILayout.Width(100))) { pool.entityDisplayMatcherIds.Clear(); } } EntitasEditorLayout.EndHorizontal(); var groupList = sortGroups ? groupsInfo.OrderByDescending(p => p.Value.Value) : groupsInfo.OrderByDescending(p => p.Key); foreach (var group in groupList) { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField(group.Key); EditorGUILayout.LabelField(group.Value.Value.ToString(), GUILayout.Width(48)); bool pointOut = pool.entityDisplayMatcherIds.Contains(group.Value.Key); bool nPointOut = EditorGUILayout.Toggle(pointOut, GUILayout.Width(48)); if (pointOut && !nPointOut) { pool.entityDisplayMatcherIds.Remove(group.Value.Key); } if (!pointOut && nPointOut) { pool.entityDisplayMatcherIds.Add(group.Value.Key); } } EntitasEditorLayout.EndHorizontal(); } } EntitasEditorLayout.EndVertical(); } EditorUtility.SetDirty(target); }
public static void DrawComponent(bool[] unfoldedComponents, IEntity entity, int index, IComponent component) { var componentType = component.GetType(); var componentName = componentType.Name.RemoveComponentSuffix(); if (EntitasEditorLayout.MatchesSearchString(componentName.ToLower(), _componentNameSearchString.ToLower())) { var boxStyle = getColoredBoxStyle(entity.totalComponents, index); EntitasEditorLayout.BeginVerticalBox(boxStyle); { var memberInfos = componentType.GetPublicMemberInfos(); EntitasEditorLayout.BeginHorizontal(); { if (memberInfos.Count == 0) { EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel); } else { unfoldedComponents[index] = EntitasEditorLayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle); } if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) { entity.RemoveComponent(index); } } EntitasEditorLayout.EndHorizontal(); if (unfoldedComponents[index]) { var componentDrawer = getComponentDrawer(componentType); if (componentDrawer != null) { var newComponent = entity.CreateComponent(index, componentType); component.CopyPublicMemberValues(newComponent); EditorGUI.BeginChangeCheck(); { componentDrawer.DrawComponent(newComponent); } var changed = EditorGUI.EndChangeCheck(); if (changed) { entity.ReplaceComponent(index, newComponent); } else { entity.GetComponentPool(index).Push(newComponent); } } else { foreach (var info in memberInfos) { DrawAndSetElement(info.type, info.name, info.GetValue(component), entity, index, component, info.SetValue); } } } } EntitasEditorLayout.EndVertical(); } }
void drawSystemList(string systemsName) { EntitasEditorLayout.BeginVertical(); { EntitasEditorLayout.BeginHorizontal(); { LuaSystems ls = target as LuaSystems; ls.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", ls.avgResetInterval); if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14))) { LuaSystems.Reset(systemsName); } } EntitasEditorLayout.EndHorizontal(); _threshold = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f); _sortSystemInfos = EditorGUILayout.Toggle("Sort by execution duration", _sortSystemInfos); EditorGUILayout.Space(); EntitasEditorLayout.BeginHorizontal(); { _systemNameSearchTerm = EditorGUILayout.TextField("Search", _systemNameSearchTerm); const string clearButtonControlName = "Clear Button"; GUI.SetNextControlName(clearButtonControlName); if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) { _systemNameSearchTerm = string.Empty; GUI.FocusControl(clearButtonControlName); } } EntitasEditorLayout.EndHorizontal(); _showInitializeSystems = EditorGUILayout.Foldout(_showInitializeSystems, "Initialize Systems"); if (_showInitializeSystems) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systemsName, true, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } _showExecuteSystems = EditorGUILayout.Foldout(_showExecuteSystems, "Execute Systems"); if (_showExecuteSystems) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systemsName, false, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } } EntitasEditorLayout.EndVertical(); }
void drawSystemList(DebugSystems systems) { EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval); if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14))) { systems.ResetDurations(); } } EntitasEditorLayout.EndHorizontal(); _threshold = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f); _systemSortMethod = (SortMethod)EditorGUILayout.EnumPopup("Sort by ", _systemSortMethod); _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems); EditorGUILayout.Space(); EntitasEditorLayout.BeginHorizontal(); { _systemNameSearchTerm = EditorGUILayout.TextField("Search", _systemNameSearchTerm); const string clearButtonControlName = "Clear Button"; GUI.SetNextControlName(clearButtonControlName); if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) { _systemNameSearchTerm = string.Empty; GUI.FocusControl(clearButtonControlName); } } EntitasEditorLayout.EndHorizontal(); _showInitializeSystems = EntitasEditorLayout.Foldout(_showInitializeSystems, "Initialize Systems"); if (_showInitializeSystems && shouldShowSystems(systems, SystemInterfaceFlags.IInitializeSystem)) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.IInitializeSystem, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } _showExecuteSystems = EntitasEditorLayout.Foldout(_showExecuteSystems, "Execute Systems"); if (_showExecuteSystems && shouldShowSystems(systems, SystemInterfaceFlags.IExecuteSystem)) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.IExecuteSystem, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } _showCleanupSystems = EntitasEditorLayout.Foldout(_showCleanupSystems, "Cleanup Systems"); if (_showCleanupSystems && shouldShowSystems(systems, SystemInterfaceFlags.ICleanupSystem)) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.ICleanupSystem, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } _showTearDownSystems = EntitasEditorLayout.Foldout(_showTearDownSystems, "TearDown Systems"); if (_showTearDownSystems && shouldShowSystems(systems, SystemInterfaceFlags.ITearDownSystem)) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.ITearDownSystem, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } } EntitasEditorLayout.EndVertical(); }
public static void DrawEntity(Pool pool, Entity entity) { var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUILayout.Button("Destroy Entity")) { pool.DestroyEntity(entity); } GUI.backgroundColor = bgColor; bool[] unfoldedComponents; if (!_poolToUnfoldedComponents.TryGetValue(pool, out unfoldedComponents)) { unfoldedComponents = new bool[pool.totalComponents]; for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } _poolToUnfoldedComponents.Add(pool, unfoldedComponents); } EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel); if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = false; } } if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); var componentNames = entity.poolMetaData.componentNames; var index = EditorGUILayout.Popup("Add Component", -1, componentNames); if (index >= 0) { var componentType = entity.poolMetaData.componentTypes[index]; var component = (IComponent)Activator.CreateInstance(componentType); entity.AddComponent(index, component); } EditorGUILayout.Space(); _componentNameSearchTerm = EditorGUILayout.TextField("Search", _componentNameSearchTerm); EditorGUILayout.Space(); var indices = entity.GetComponentIndices(); var components = entity.GetComponents(); for (int i = 0; i < components.Length; i++) { DrawComponent(unfoldedComponents, entity, indices[i], components[i]); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Retained by (" + entity.retainCount + ")", EditorStyles.boldLabel); #if !ENTITAS_FAST_AND_UNSAFE EntitasEditorLayout.BeginVerticalBox(); { foreach (var owner in entity.owners.ToArray()) { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField(owner.ToString()); if (GUILayout.Button("Release", GUILayout.Width(88), GUILayout.Height(14))) { entity.Release(owner); } EntitasEditorLayout.EndHorizontal(); } } } EntitasEditorLayout.EndVertical(); #endif } EntitasEditorLayout.EndVertical(); }
void DrawComponents(string poolName, int entityId) { Dictionary <int, bool> componentState; if (!poolComponentState.TryGetValue(poolName, out componentState)) { componentState = new Dictionary <int, bool>(); poolComponentState.Add(poolName, componentState); } int[] componentTypeIds = LuaEntity.GetEntityComponentIds(poolName, entityId); EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { bool forceSet = false, state = false; EditorGUILayout.LabelField("Components (" + componentTypeIds.Length + ")", EditorStyles.boldLabel); if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) { forceSet = true; state = false; } if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) { forceSet = true; state = true; } for (int i = 0; i < componentTypeIds.Length; i++) { if (forceSet || !componentState.ContainsKey(componentTypeIds[i])) { componentState[componentTypeIds[i]] = state; } } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); var index = EditorGUILayout.Popup("Add Component", -1, LuaEntity.GetComponentSelectText()); if (index >= 0) { int componentId = LuaEntity.GetComponentIdByIndex(index); LuaEntity.AddComponent(poolName, entityId, componentId); } EditorGUILayout.Space(); EntitasEditorLayout.BeginHorizontal(); { componentNameSearchTerm = EditorGUILayout.TextField("Search", componentNameSearchTerm); const string clearButtonControlName = "Clear Button"; GUI.SetNextControlName(clearButtonControlName); if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) { componentNameSearchTerm = string.Empty; GUI.FocusControl(clearButtonControlName); } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); for (int i = 0; i < componentTypeIds.Length; i++) { DrawComponent(poolName, entityId, componentTypeIds[i], componentState); } } EntitasEditorLayout.EndVertical(); }