Example #1
0
        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();
        }
        public override void OnInspectorGUI()
        {
            var binaryBlueprint = ((BinaryBlueprint)target);

            EditorGUI.BeginChangeCheck();
            {
                EditorGUILayout.LabelField("Blueprint", EditorStyles.boldLabel);
                binaryBlueprint.name = EditorGUILayout.TextField("Name", binaryBlueprint.name);

                EntitasEditorLayout.BeginHorizontal();
                {
                    _poolIndex = EditorGUILayout.Popup(_poolIndex, _allPoolNames);

                    if (GUILayout.Button("Switch"))
                    {
                        switchToPool();
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                EntityDrawer.DrawComponents(_pool, _entity, true);
            }
            var changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                binaryBlueprint.Serialize(_entity);
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), binaryBlueprint.name);
                EditorUtility.SetDirty(target);
            }
        }
Example #3
0
        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;
        }
Example #5
0
        public static void DrawMultipleEntities(Pool pool, Entity[] entities)
        {
            EditorGUILayout.Space();
            EntitasEditorLayout.BeginHorizontal();
            {
                var entity         = entities[0];
                var componentNames = entity.poolMetaData.componentNames;
                var index          = EditorGUILayout.Popup("Add Component", -1, componentNames);
                if (index >= 0)
                {
                    var componentType = entity.poolMetaData.componentTypes[index];
                    foreach (var e in entities)
                    {
                        var component = (IComponent)Activator.CreateInstance(componentType);
                        e.AddComponent(index, component);
                    }
                }
            }
            EntitasEditorLayout.EndHorizontal();

            EditorGUILayout.Space();

            var bgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.red;

            if (GUILayout.Button("Destroy selected entities"))
            {
                foreach (var e in entities)
                {
                    pool.DestroyEntity(e);
                }
            }

            GUI.backgroundColor = bgColor;

            EditorGUILayout.Space();

            foreach (var e in entities)
            {
                EntitasEditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(e.ToString());

                    bgColor             = GUI.backgroundColor;
                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("Destroy Entity"))
                    {
                        pool.DestroyEntity(e);
                    }

                    GUI.backgroundColor = bgColor;
                }
                EntitasEditorLayout.EndHorizontal();
            }
        }
Example #6
0
        public static void DrawMultipleEntities(IContext context, IEntity[] entities, bool hideInBlueprintInspector = false)
        {
            EditorGUILayout.Space();
            EntitasEditorLayout.BeginHorizontal();
            {
                var entity = entities[0];
                var index  = drawAddComponentMenu(entity, hideInBlueprintInspector);
                if (index >= 0)
                {
                    var componentType = entity.contextInfo.componentTypes[index];
                    foreach (var e in entities)
                    {
                        var component = (IComponent)Activator.CreateInstance(componentType);
                        e.AddComponent(index, component);
                    }
                }
            }
            EntitasEditorLayout.EndHorizontal();

            EditorGUILayout.Space();

            var bgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.red;

            if (GUILayout.Button("Destroy selected entities"))
            {
                foreach (var e in entities)
                {
                    context.DestroyEntity(e);
                }
            }

            GUI.backgroundColor = bgColor;

            EditorGUILayout.Space();

            foreach (var e in entities)
            {
                EntitasEditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(e.ToString());

                    bgColor             = GUI.backgroundColor;
                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("Destroy Entity"))
                    {
                        context.DestroyEntity(e);
                    }

                    GUI.backgroundColor = bgColor;
                }
                EntitasEditorLayout.EndHorizontal();
            }
        }
Example #7
0
        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();
        }
Example #8
0
        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();
        }
Example #9
0
        int drawSystemInfos(string systemsName, bool initOnly, bool isChildSysem)
        {
            string[] names = initOnly ? LuaSystems.GetInitializeChildNameList(systemsName) : LuaSystems.GetExecuteChildNameList(systemsName);
            names = names
                    .Where(name => { return(LuaSystems.GetAverageCost(name) >= _threshold); })
                    .ToArray();

            if (_sortSystemInfos)
            {
                names = names
                        .OrderByDescending(name => LuaSystems.GetAverageCost(name))
                        .ToArray();
            }

            var systemsDrawn = 0;

            foreach (var name in names)
            {
                if (name.ToLower().Contains(_systemNameSearchTerm.ToLower()))
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        LuaTable profile = LuaSystems.GetProfile(name);
                        EditorGUI.BeginDisabledGroup(isChildSysem);
                        {
                            profile["enable"] = EditorGUILayout.Toggle(Convert.ToBoolean(profile["enable"]), GUILayout.Width(20));
                        }
                        EditorGUI.EndDisabledGroup();

                        float initCost = Convert.ToSingle(profile["initializecost"]);
                        var   avg      = string.Format("Ø {0:0.000}", initOnly ? initCost : LuaSystems.GetAverageCost(name)).PadRight(9);
                        var   min      = string.Format("min {0:0.000}", initOnly ? initCost : Convert.ToSingle(profile["executecostmin"])).PadRight(11);
                        var   max      = string.Format("max {0:0.000}", initOnly ? initCost : Convert.ToSingle(profile["executecostmax"]));
                        EditorGUILayout.LabelField(name, avg + "\t" + min + "\t" + max, getSystemStyle(name));
                    }
                    EntitasEditorLayout.EndHorizontal();

                    systemsDrawn += 1;
                }

                if (LuaSystems.IsSystems(name))
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    systemsDrawn          += drawSystemInfos(name, initOnly, true);
                    EditorGUI.indentLevel  = indent;
                }
            }

            return(systemsDrawn);
        }
Example #10
0
        void DrawAndSetElement(string poolName, int entityId, int componentId, string propertyName)
        {
            object value = LuaEntity.GetEntityComponetnPropertyValue(poolName, entityId, componentId, propertyName);

            EntitasEditorLayout.BeginHorizontal();
            {
                object nvalue;
                if (draw(propertyName, value, true, out nvalue))
                {
                    LuaEntity.SetEntityComponetnPropertyValue(poolName, entityId, componentId, propertyName, nvalue);
                }
            }
            EntitasEditorLayout.EndHorizontal();
        }
        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;
        }
Example #12
0
        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();
        }
Example #13
0
        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();
            }
        }
Example #15
0
        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);
        }
Example #16
0
 static void drawUnsupportedType(Type type, string fieldName, object value)
 {
     EntitasEditorLayout.BeginHorizontal();
     {
         EditorGUILayout.LabelField(fieldName, value.ToString());
         if (GUILayout.Button("Missing ITypeDrawer", GUILayout.Height(14)))
         {
             var typeName = type.ToCompilableString();
             if (EditorUtility.DisplayDialog(
                     "No ITypeDrawer found",
                     "There's no ITypeDrawer implementation to handle the type '" + typeName + "'.\n" +
                     "Providing an ITypeDrawer enables you draw instances for that type.\n\n" +
                     "Do you want to generate an ITypeDrawer implementation for '" + typeName + "'?\n",
                     "Generate",
                     "Cancel"
                     ))
             {
                 generateITypeDrawer(typeName);
             }
         }
     }
     EntitasEditorLayout.EndHorizontal();
 }
Example #17
0
        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();
            }
        }
Example #18
0
        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
        }
Example #19
0
        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();
        }
Example #20
0
        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();
            }
        }
Example #21
0
        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);
        }
Example #22
0
        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();
        }
Example #23
0
        int drawSystemInfos(DebugSystems systems, bool initOnly, bool isChildSysem)
        {
            var systemInfos = initOnly ? systems.initializeSystemInfos : systems.executeSystemInfos;

            systemInfos = systemInfos
                          .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                          .ToArray();

            systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod);

            var systemsDrawn = 0;

            foreach (var systemInfo in systemInfos)
            {
                var debugSystems = systemInfo.system as DebugSystems;
                if (debugSystems != null)
                {
                    if (!shouldShowSystems(debugSystems, initOnly))
                    {
                        continue;
                    }
                }

                if (systemInfo.systemName.ToLower().Contains(_systemNameSearchTerm.ToLower()))
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        EditorGUI.BeginDisabledGroup(isChildSysem);
                        {
                            systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                        }
                        EditorGUI.EndDisabledGroup();
                        var reactiveSystem = systemInfo.system as ReactiveSystem;
                        if (reactiveSystem != null)
                        {
                            if (systemInfo.isActive)
                            {
                                reactiveSystem.Activate();
                            }
                            else
                            {
                                reactiveSystem.Deactivate();
                            }
                        }

                        var avg = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12);
                        var min = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12);
                        var max = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration);

                        EditorGUILayout.LabelField(systemInfo.systemName, avg + min + max, getSystemStyle(systemInfo));
                    }
                    EntitasEditorLayout.EndHorizontal();

                    systemsDrawn += 1;
                }

                var debugSystem = systemInfo.system as DebugSystems;
                if (debugSystem != null)
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    systemsDrawn          += drawSystemInfos(debugSystem, initOnly, true);
                    EditorGUI.indentLevel  = indent;
                }
            }

            return(systemsDrawn);
        }
Example #24
0
        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();
        }
        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();
        }
Example #26
0
        static LuaEntityInspector()
        {
            foldoutStyle           = new GUIStyle(EditorStyles.foldout);
            foldoutStyle.fontStyle = FontStyle.Bold;

            defaultDrawer = (string name, object value, out object nvalue) =>
            {
                nvalue = value;
                EditorGUILayout.LabelField(name, value.ToString());
                return(false);
            };

            propertyTypeDrawer[typeof(double)] = (string name, object value, out object nvalue) =>
            {
                EntitasEditorLayout.BeginHorizontal();

                nvalue = EditorGUILayout.DoubleField(name, (double)value);
                if (GUILayout.Button("str", GUILayout.Width(35), GUILayout.Height(14)))
                {
                    EntitasEditorLayout.EndHorizontal();
                    nvalue = nvalue.ToString();
                    return(true);
                }

                EntitasEditorLayout.EndHorizontal();
                return(Math.Abs((double)value - (double)nvalue) > Mathf.Epsilon);
            };
            propertyTypeDrawer[typeof(string)] = (string name, object value, out object nvalue) =>
            {
                EntitasEditorLayout.BeginHorizontal();

                nvalue = EditorGUILayout.TextField(name, (string)value);
                if (GUILayout.Button("num", GUILayout.Width(35), GUILayout.Height(14)))
                {
                    EntitasEditorLayout.EndHorizontal();
                    double tmp;
                    nvalue = double.TryParse(nvalue.ToString(), out tmp) ? tmp : 0d;
                    return(true);
                }

                EntitasEditorLayout.EndHorizontal();
                return(nvalue != value);
            };
            propertyTypeDrawer[typeof(LuaTable)] = (string name, object value, out object nvalue) =>
            {
                nvalue = value;
                LuaTable table  = value as LuaTable;
                bool     modify = false;

                using (var dict = table.ToDictTable())
                {
                    using (var e = dict.GetEnumerator())
                    {
                        while (e.MoveNext())
                        {
                            object tmp;
                            bool   arrayKey = e.Current.Key is double;
                            if (draw(name + "." + (arrayKey ? "" : "'") + e.Current.Key + (arrayKey ? "" : "'"), e.Current.Value, false, out tmp))
                            {
                                if (arrayKey)
                                {
                                    table[Convert.ToInt32(e.Current.Key)] = tmp;
                                }
                                else
                                {
                                    table[e.Current.Key.ToString()] = tmp;
                                }
                                modify = true;
                            }
                        }
                    }
                }

                return(modify);
            };
        }
Example #27
0
        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();
        }
Example #28
0
        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);
        }
        int drawSystemInfos(DebugSystems systems, SystemInterfaceFlags type, bool isChildSystem)
        {
            SystemInfo[] systemInfos = null;

            var drawExecutionDuration = false;

            switch (type)
            {
            case SystemInterfaceFlags.IInitializeSystem:
                systemInfos = systems.initializeSystemInfos;
                break;

            case SystemInterfaceFlags.IExecuteSystem:
                systemInfos           = systems.executeSystemInfos;
                drawExecutionDuration = true;
                break;

            case SystemInterfaceFlags.ICleanupSystem:
                systemInfos = systems.cleanupSystemInfos;
                break;

            case SystemInterfaceFlags.ITearDownSystem:
                systemInfos = systems.tearDownSystemInfos;
                break;
            }

            systemInfos = systemInfos
                          .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                          .ToArray();

            systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod);

            var systemsDrawn = 0;

            foreach (var systemInfo in systemInfos)
            {
                var debugSystems = systemInfo.system as DebugSystems;
                if (debugSystems != null)
                {
                    if (!shouldShowSystems(debugSystems, type))
                    {
                        continue;
                    }
                }

                if (EntitasEditorLayout.MatchesSearchString(systemInfo.systemName.ToLower(), _systemNameSearchString.ToLower()))
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        EditorGUI.BeginDisabledGroup(isChildSystem);
                        {
                            systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                        }
                        EditorGUI.EndDisabledGroup();

                        var reactiveSystem = systemInfo.system as IReactiveSystem;
                        if (reactiveSystem != null)
                        {
                            if (systemInfo.isActive)
                            {
                                reactiveSystem.Activate();
                            }
                            else
                            {
                                reactiveSystem.Deactivate();
                            }
                        }

                        if (drawExecutionDuration)
                        {
                            var avg = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12);
                            var min = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12);
                            var max = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration);
                            EditorGUILayout.LabelField(systemInfo.systemName, avg + min + max, getSystemStyle(systemInfo));
                        }
                        else
                        {
                            EditorGUILayout.LabelField(systemInfo.systemName, getSystemStyle(systemInfo));
                        }
                    }
                    EntitasEditorLayout.EndHorizontal();

                    systemsDrawn += 1;
                }

                var debugSystem = systemInfo.system as DebugSystems;
                if (debugSystem != null)
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    systemsDrawn          += drawSystemInfos(debugSystem, type, true);
                    EditorGUI.indentLevel  = indent;
                }
            }

            return(systemsDrawn);
        }