예제 #1
0
        public static void DrawEntity(IContext context, IEntity entity)
        {
            var bgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("Destroy Entity"))
            {
                entity.Destroy();
            }
            GUI.backgroundColor = bgColor;

            DrawComponents(context, entity);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Retained by (" + entity.RefCount + ")", EditorStyles.boldLabel);

            var safeAerc = entity.RefCounter as SafeARC;

            if (safeAerc != null)
            {
                EntitasEditorLayout.BeginVerticalBox();
                {
                    foreach (var owner in safeAerc.Owners.OrderBy(o => o.GetType().Name))
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField(owner.ToString());
                            if (EntitasEditorLayout.MiniButton("Release"))
                            {
                                entity.Release(owner);
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                EntitasEditorLayout.EndVerticalBox();
            }
        }
예제 #2
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);
        }
예제 #3
0
        public override void OnInspectorGUI()
        {
            var binaryBlueprint = ((BinaryBlueprint)target);

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

                if (_context != null)
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        _contextIndex = EditorGUILayout.Popup(_contextIndex, _allContextNames);

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

                    EntityDrawer.DrawComponents(_context, _entity, true);
                }
                else
                {
                    EditorGUILayout.LabelField("No contexts found!");
                }
            }
            var changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                binaryBlueprint.Serialize(_entity);
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), binaryBlueprint.name);
                EditorUtility.SetDirty(target);
            }
        }
예제 #4
0
        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();
        }
예제 #5
0
 static void drawUnsupportedType(Type memberType, string memberName, object value)
 {
     EditorGUILayout.BeginHorizontal();
     {
         EditorGUILayout.LabelField(memberName, value.ToString());
         if (EntitasEditorLayout.MiniButton("Missing ITypeDrawer"))
         {
             var typeName = memberType.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);
             }
         }
     }
     EditorGUILayout.EndHorizontal();
 }
예제 #6
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();
            }
        }
예제 #7
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
        }
예제 #8
0
        public static void OpenMigrate()
        {
//            EntitasEditorLayout.ShowWindow<MigrationWindow>("QFramework Migration - " + CheckForUpdates.GetLocalVersion());
            EntitasEditorLayout.ShowWindow <MigrationWindow>("QFramework Migration - QFramework");
        }
예제 #9
0
        public static void DrawComponent(bool[] unfoldedComponents, string[] componentMemberSearch, IContext context, IEntity entity, int index, IComponent component)
        {
            var componentType = component.GetType();
            var componentName = componentType.Name.RemoveComponentSuffix();

            if (EntitasEditorLayout.MatchesSearchString(componentName.ToLower(), componentNameSearchString.ToLower()))
            {
                var boxStyle = getColoredBoxStyle(context, index);
                EditorGUILayout.BeginVertical(boxStyle);
                {
                    var memberInfos = componentType.GetPublicMemberInfos();
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (memberInfos.Count == 0)
                        {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        }
                        else
                        {
                            unfoldedComponents[index] = EntitasEditorLayout.Foldout(unfoldedComponents[index], componentName, foldoutStyle);
                            if (unfoldedComponents[index])
                            {
                                componentMemberSearch[index] = memberInfos.Count > 5
                                                                          ? EntitasEditorLayout.SearchTextField(componentMemberSearch[index])
                                                                          : string.Empty;
                            }
                        }
                        if (EntitasEditorLayout.MiniButton("-"))
                        {
                            entity.RemoveComponent(index);
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    if (unfoldedComponents[index])
                    {
                        var newComponent = entity.CreateComponent(index, componentType);
                        component.CopyPublicMemberValues(newComponent);

                        var changed         = false;
                        var componentDrawer = getComponentDrawer(componentType);
                        if (componentDrawer != null)
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                componentDrawer.DrawComponent(newComponent);
                            }
                            changed = EditorGUI.EndChangeCheck();
                        }
                        else
                        {
                            foreach (var info in memberInfos)
                            {
                                if (EntitasEditorLayout.MatchesSearchString(info.name.ToLower(), componentMemberSearch[index].ToLower()))
                                {
                                    var memberValue = info.GetValue(newComponent);
                                    var memberType  = memberValue == null ? info.type : memberValue.GetType();
                                    if (DrawObjectMember(memberType, info.name, memberValue, newComponent, info.SetValue))
                                    {
                                        changed = true;
                                    }
                                }
                            }
                        }

                        if (changed)
                        {
                            entity.ReplaceComponent(index, newComponent);
                        }
                        else
                        {
                            entity.GetComponentPool(index).Push(newComponent);
                        }
                    }
                }
                EntitasEditorLayout.EndVerticalBox();
            }
        }
예제 #10
0
        public static bool DrawObjectMember(Type memberType, string memberName, object value, object target, Action <object, object> setValue)
        {
            if (value == null)
            {
                EditorGUI.BeginChangeCheck();
                {
                    var isUnityObject = memberType == typeof(UnityEngine.Object) || memberType.IsSubclassOf(typeof(UnityEngine.Object));
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (isUnityObject)
                        {
                            setValue(target, EditorGUILayout.ObjectField(memberName, (UnityEngine.Object)value, memberType, true));
                        }
                        else
                        {
                            EditorGUILayout.LabelField(memberName, "null");
                        }

                        if (EntitasEditorLayout.MiniButton("new " + memberType.ToCompilableString().ShortTypeName()))
                        {
                            object defaultValue;
                            if (CreateDefault(memberType, out defaultValue))
                            {
                                setValue(target, defaultValue);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                return(EditorGUI.EndChangeCheck());
            }

            if (!memberType.IsValueType)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical();
            }

            EditorGUI.BeginChangeCheck();
            {
                var typeDrawer = getTypeDrawer(memberType);
                if (typeDrawer != null)
                {
                    var newValue = typeDrawer.DrawAndGetNewValue(memberType, memberName, value, target);
                    setValue(target, newValue);
                }
                else
                {
                    var targetType = target.GetType();
                    var shouldDraw = !targetType.ImplementsInterface <IComponent>() || !Attribute.IsDefined(targetType, typeof(DontDrawComponentAttribute));
                    if (shouldDraw)
                    {
                        EditorGUILayout.LabelField(memberName, value.ToString());

                        var indent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel += 1;

                        EditorGUILayout.BeginVertical();
                        {
                            foreach (var info in memberType.GetPublicMemberInfos())
                            {
                                var mValue = info.GetValue(value);
                                var mType  = mValue == null ? info.type : mValue.GetType();
                                DrawObjectMember(mType, info.name, mValue, value, info.SetValue);
                                if (memberType.IsValueType)
                                {
                                    setValue(target, value);
                                }
                            }
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUI.indentLevel = indent;
                    }
                    else
                    {
                        drawUnsupportedType(memberType, memberName, value);
                    }
                }

                if (!memberType.IsValueType)
                {
                    EditorGUILayout.EndVertical();
                    if (EntitasEditorLayout.MiniButton("×"))
                    {
                        setValue(target, null);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            return(EditorGUI.EndChangeCheck());
        }
예제 #11
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();
        }
예제 #12
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);
                _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, true))
                {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, true, false);
                        if (systemsDrawn == 0)
                        {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }

                _showExecuteSystems = EntitasEditorLayout.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();
        }
예제 #13
0
        public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
        {
            var dictionary = (IDictionary)value;
            var keyType    = memberType.GetGenericArguments()[0];
            var valueType  = memberType.GetGenericArguments()[1];
            var targetType = target.GetType();

            if (!_keySearchTexts.ContainsKey(targetType))
            {
                _keySearchTexts.Add(targetType, string.Empty);
            }

            EditorGUILayout.BeginHorizontal();
            {
                if (dictionary.Count == 0)
                {
                    EditorGUILayout.LabelField(memberName, "empty");
                    _keySearchTexts[targetType] = string.Empty;
                }
                else
                {
                    EditorGUILayout.LabelField(memberName);
                }

                var keyTypeName   = keyType.ToCompilableString().ShortTypeName();
                var valueTypeName = valueType.ToCompilableString().ShortTypeName();
                if (EntitasEditorLayout.MiniButton("new <" + keyTypeName + ", " + valueTypeName + ">"))
                {
                    object defaultKey;
                    if (EntityDrawer.CreateDefault(keyType, out defaultKey))
                    {
                        object defaultValue;
                        if (EntityDrawer.CreateDefault(valueType, out defaultValue))
                        {
                            dictionary[defaultKey] = defaultValue;
                        }
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            if (dictionary.Count > 0)
            {
                var indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = indent + 1;

                if (dictionary.Count > 5)
                {
                    EditorGUILayout.Space();
                    _keySearchTexts[targetType] = EntitasEditorLayout.SearchTextField(_keySearchTexts[targetType]);
                }

                EditorGUILayout.Space();

                var keys = new ArrayList(dictionary.Keys);
                for (int i = 0; i < keys.Count; i++)
                {
                    var key = keys[i];
                    if (EntitasEditorLayout.MatchesSearchString(key.ToString().ToLower(), _keySearchTexts[targetType].ToLower()))
                    {
                        EntityDrawer.DrawObjectMember(keyType, "key", key,
                                                      target, (newComponent, newValue) => {
                            var tmpValue = dictionary[key];
                            dictionary.Remove(key);
                            if (newValue != null)
                            {
                                dictionary[newValue] = tmpValue;
                            }
                        });

                        EntityDrawer.DrawObjectMember(valueType, "value", dictionary[key],
                                                      target, (newComponent, newValue) => dictionary[key] = newValue);

                        EditorGUILayout.Space();
                    }
                }

                EditorGUI.indentLevel = indent;
            }

            return(dictionary);
        }
예제 #14
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);
            };
        }
        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();

                _systemNameSearchString = EntitasEditorLayout.SearchTextField(_systemNameSearchString);
                EditorGUILayout.Space();

                _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();
        }
예제 #16
0
        public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
        {
            var elementType   = memberType.GetGenericArguments()[0];
            var itemsToRemove = new ArrayList();
            var itemsToAdd    = new ArrayList();
            var isEmpty       = !((IEnumerable)value).GetEnumerator().MoveNext();

            EditorGUILayout.BeginHorizontal();
            {
                if (isEmpty)
                {
                    EditorGUILayout.LabelField(memberName, "empty");
                }
                else
                {
                    EditorGUILayout.LabelField(memberName);
                }

                if (EntitasEditorLayout.MiniButton("new " + elementType.ToCompilableString().ShortTypeName()))
                {
                    object defaultValue;
                    if (EntityDrawer.CreateDefault(elementType, out defaultValue))
                    {
                        itemsToAdd.Add(defaultValue);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            if (!isEmpty)
            {
                EditorGUILayout.Space();
                var indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = indent + 1;
                foreach (var item in (IEnumerable)value)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EntityDrawer.DrawObjectMember(elementType, string.Empty, item,
                                                      target, (newComponent, newValue) => {
                            itemsToRemove.Add(item);
                            itemsToAdd.Add(newValue);
                        });

                        if (EntitasEditorLayout.MiniButton("-"))
                        {
                            itemsToRemove.Add(item);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUI.indentLevel = indent;
            }

            foreach (var item in itemsToRemove)
            {
                memberType.GetMethod("Remove").Invoke(value, new [] { item });
            }

            foreach (var item in itemsToAdd)
            {
                memberType.GetMethod("Add").Invoke(value, new [] { item });
            }

            return(value);
        }
예제 #17
0
 void OnEnable()
 {
     _headerTexture = EntitasEditorLayout.LoadTexture("l:EntitasMigrationHeader");
     _localVersion  = EntitasCheckForUpdates.GetLocalVersion();
     _migrations    = getMigrations();
 }
예제 #18
0
        int drawSystemInfos(DebugSystems systems, SystemInterfaceFlags type)
        {
            SystemInfo[] systemInfos = null;

            switch (type)
            {
            case SystemInterfaceFlags.IInitializeSystem:
                systemInfos = systems.initializeSystemInfos
                              .Where(systemInfo => systemInfo.initializationDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.IExecuteSystem:
                systemInfos = systems.executeSystemInfos
                              .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.ICleanupSystem:
                systemInfos = systems.cleanupSystemInfos
                              .Where(systemInfo => systemInfo.cleanupDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.ITearDownSystem:
                systemInfos = systems.tearDownSystemInfos
                              .Where(systemInfo => systemInfo.teardownDuration >= _threshold)
                              .ToArray();
                break;
            }

            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()))
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        var indent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel = 0;

                        var wasActive = systemInfo.isActive;
                        if (systemInfo.areAllParentsActive)
                        {
                            systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                        }
                        else
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            {
                                EditorGUILayout.Toggle(false, GUILayout.Width(20));
                            }
                        }
                        EditorGUI.EndDisabledGroup();

                        EditorGUI.indentLevel = indent;

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

                        switch (type)
                        {
                        case SystemInterfaceFlags.IInitializeSystem:
                            EditorGUILayout.LabelField(systemInfo.systemName, systemInfo.initializationDuration.ToString(), getSystemStyle(systemInfo, SystemInterfaceFlags.IInitializeSystem));
                            break;

                        case SystemInterfaceFlags.IExecuteSystem:
                            var avgE = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12);
                            var minE = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12);
                            var maxE = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration);
                            EditorGUILayout.LabelField(systemInfo.systemName, avgE + minE + maxE, getSystemStyle(systemInfo, SystemInterfaceFlags.IExecuteSystem));
                            break;

                        case SystemInterfaceFlags.ICleanupSystem:
                            var avgC = string.Format("Ø {0:00.000}", systemInfo.averageCleanupDuration).PadRight(12);
                            var minC = string.Format("▼ {0:00.000}", systemInfo.minCleanupDuration).PadRight(12);
                            var maxC = string.Format("▲ {0:00.000}", systemInfo.maxCleanupDuration);
                            EditorGUILayout.LabelField(systemInfo.systemName, avgC + minC + maxC, getSystemStyle(systemInfo, SystemInterfaceFlags.ICleanupSystem));
                            break;

                        case SystemInterfaceFlags.ITearDownSystem:
                            EditorGUILayout.LabelField(systemInfo.systemName, systemInfo.teardownDuration.ToString(), getSystemStyle(systemInfo, SystemInterfaceFlags.ITearDownSystem));
                            break;
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    systemsDrawn += 1;
                }

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

            return(systemsDrawn);
        }
예제 #19
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();
            }
        }
예제 #20
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();
        }
예제 #21
0
 public static void OpenMigrate()
 {
     EntitasEditorLayout.ShowWindow <EntitasMigrationWindow>("Entitas Migration - " + EntitasCheckForUpdates.GetLocalVersion());
 }
예제 #22
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();
        }
예제 #23
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);
        }
예제 #24
0
 public static void OpenMigrate()
 {
     EntitasEditorLayout.ShowWindow <EntitasMigrationWindow>("Entitas Migration");
 }
예제 #25
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);
        }
예제 #26
0
        void drawSystemList(DebugSystems systems)
        {
            _showSystemsList = EntitasEditorLayout.DrawSectionHeaderToggle("Systems", _showSystemsList);
            if (_showSystemsList)
            {
                EntitasEditorLayout.BeginSectionContent();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval);
                        if (GUILayout.Button("Reset Ø now", EditorStyles.miniButton, GUILayout.Width(88)))
                        {
                            systems.ResetDurations();
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    _threshold = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f);

                    _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems);
                    EditorGUILayout.Space();

                    EditorGUILayout.BeginHorizontal();
                    {
                        _systemSortMethod       = (SortMethod)EditorGUILayout.EnumPopup(_systemSortMethod, EditorStyles.popup, GUILayout.Width(150));
                        _systemNameSearchString = EntitasEditorLayout.SearchTextField(_systemNameSearchString);
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Space();

                    _showInitializeSystems = EntitasEditorLayout.DrawSectionHeaderToggle("Initialize Systems", _showInitializeSystems);
                    if (_showInitializeSystems && shouldShowSystems(systems, SystemInterfaceFlags.IInitializeSystem))
                    {
                        EntitasEditorLayout.BeginSectionContent();
                        {
                            var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.IInitializeSystem);
                            if (systemsDrawn == 0)
                            {
                                EditorGUILayout.LabelField(string.Empty);
                            }
                        }
                        EntitasEditorLayout.EndSectionContent();
                    }

                    _showExecuteSystems = EntitasEditorLayout.DrawSectionHeaderToggle("Execute Systems", _showExecuteSystems);
                    if (_showExecuteSystems && shouldShowSystems(systems, SystemInterfaceFlags.IExecuteSystem))
                    {
                        EntitasEditorLayout.BeginSectionContent();
                        {
                            var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.IExecuteSystem);
                            if (systemsDrawn == 0)
                            {
                                EditorGUILayout.LabelField(string.Empty);
                            }
                        }
                        EntitasEditorLayout.EndSectionContent();
                    }

                    _showCleanupSystems = EntitasEditorLayout.DrawSectionHeaderToggle("Cleanup Systems", _showCleanupSystems);
                    if (_showCleanupSystems && shouldShowSystems(systems, SystemInterfaceFlags.ICleanupSystem))
                    {
                        EntitasEditorLayout.BeginSectionContent();
                        {
                            var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.ICleanupSystem);
                            if (systemsDrawn == 0)
                            {
                                EditorGUILayout.LabelField(string.Empty);
                            }
                        }
                        EntitasEditorLayout.EndSectionContent();
                    }

                    _showTearDownSystems = EntitasEditorLayout.DrawSectionHeaderToggle("TearDown Systems", _showTearDownSystems);
                    if (_showTearDownSystems && shouldShowSystems(systems, SystemInterfaceFlags.ITearDownSystem))
                    {
                        EntitasEditorLayout.BeginSectionContent();
                        {
                            var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.ITearDownSystem);
                            if (systemsDrawn == 0)
                            {
                                EditorGUILayout.LabelField(string.Empty);
                            }
                        }
                        EntitasEditorLayout.EndSectionContent();
                    }
                }
                EntitasEditorLayout.EndSectionContent();
            }
        }
예제 #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();
        }
예제 #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);
        }
예제 #29
0
        public static bool DrawComponentMember(Type memberType, string memberName, object value, IComponent component, Action <IComponent, object> setValue)
        {
            if (value == null)
            {
                EditorGUI.BeginChangeCheck();
                {
                    var isUnityObject = memberType == typeof(UnityEngine.Object) || memberType.IsSubclassOf(typeof(UnityEngine.Object));
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (isUnityObject)
                        {
                            setValue(component, EditorGUILayout.ObjectField(memberName, (UnityEngine.Object)value, memberType, true));
                        }
                        else
                        {
                            EditorGUILayout.LabelField(memberName, "null");
                        }

                        if (EntitasEditorLayout.MiniButton("new " + memberType.ToCompilableString().ShortTypeName()))
                        {
                            object defaultValue;
                            if (CreateDefault(memberType, out defaultValue))
                            {
                                setValue(component, defaultValue);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                return(EditorGUI.EndChangeCheck());
            }

            if (!memberType.IsValueType)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical();
            }

            EditorGUI.BeginChangeCheck();
            {
                var typeDrawer = getTypeDrawer(memberType);
                if (typeDrawer != null)
                {
                    setValue(component, typeDrawer.DrawAndGetNewValue(memberType, memberName, value, component));
                }
                else
                {
                    drawUnsupportedType(memberType, memberName, value);
                    EditorGUILayout.BeginVertical();
                    {
                        EditorGUILayout.Space();
                        var infos = memberType.GetPublicMemberInfos();
                        for (int i = 0; i < infos.Count; i++)
                        {
                            var info = infos[i];
                            EditorGUILayout.LabelField(info.name, info.GetValue(value).ToString());
                        }
                    }
                    EditorGUILayout.EndVertical();
                }

                if (!memberType.IsValueType)
                {
                    EditorGUILayout.EndVertical();
                    if (EntitasEditorLayout.MiniButton("×"))
                    {
                        setValue(component, null);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            return(EditorGUI.EndChangeCheck());
        }