public static void GenerateEnums(List <string> definitionNames, bool refresh = true)
        {
            var addedDefinitions = new List <string>();
            var entityTypeConfig = ScriptableObjectEditorUtils.FindFirstOfType <EntityTypeConfig>();

            _enumNames = new List <string>();
            foreach (var definitionName in definitionNames)
            {
                if (addedDefinitions.Contains(definitionName))
                {
                    continue;
                }
                _enumNames.Add(definitionName);
                if (!entityTypeConfig.EntityNames.Contains(definitionName))
                {
                    entityTypeConfig.EntityNames.Add(definitionName);
                    EntityTypeGenerator.AddEnum(definitionName, false);
                }
                addedDefinitions.Add(definitionName);
            }
            GenerateFile();
            if (refresh)
            {
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            }
        }
예제 #2
0
        public static void CreateConfigFiles()
        {
            var typeConfig  = ScriptableObjectEditorUtils.FindFirstOfType <EntityTypeConfig>();
            var groupConfig = ScriptableObjectEditorUtils.FindFirstOfType <EntityPropertyConfig>();

            if (typeConfig == null || groupConfig == null)
            {
                if (!Directory.Exists(_settings.ConfigRootPath))
                {
                    Directory.CreateDirectory(_settings.ConfigRootPath);
                }

                if (typeConfig == null)
                {
                    typeConfig = ScriptableObject.CreateInstance <EntityTypeConfig>();
                    AssetDatabase.CreateAsset(typeConfig, $"{Path.Combine(_settings.ConfigRootPath, "EntityTypeConfig")}.asset");
                }
                if (groupConfig == null)
                {
                    groupConfig = ScriptableObject.CreateInstance <EntityPropertyConfig>();
                    AssetDatabase.CreateAsset(groupConfig, $"{Path.Combine(_settings.ConfigRootPath, "EntityGroupConfig")}.asset");
                }
            }

            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();
        }
예제 #3
0
        static void SelectSettingsFile()
        {
            var settingsSO = ScriptableObjectEditorUtils.FindFirstOfType <GdOrganizerSettings>();

            Selection.activeObject = settingsSO;
            EditorGUIUtility.PingObject(Selection.activeObject);
        }
예제 #4
0
        public static void Regenerate()
        {
            var entityPropertyConfig = ScriptableObjectEditorUtils.FindFirstOfType <EntityPropertyConfig>();
            var entityTypeConfig     = ScriptableObjectEditorUtils.FindFirstOfType <EntityTypeConfig>();

            entityPropertyConfig.ValidateNames();
            entityTypeConfig.ValidateNames();

            EntityPropertyGenerator.GenerateEnums(entityPropertyConfig.PropertyNames);
            EntityTypeGenerator.GenerateEnums(entityTypeConfig.EntityNames);
        }
예제 #5
0
        public static void GeneratePropertyDefinitionsForAllTypes()
        {
            var entityTypeDefinitions = ScriptableObjectEditorUtils.FindAllOfType <EntityTypeDefinition>();

            foreach (var typeDefinition in entityTypeDefinitions)
            {
                GenerateGroupDefinitionsForType(typeDefinition);
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        public static void SetupGroupDefinitions()
        {
            var existingGroupDefinitions = ScriptableObjectEditorUtils.FindAllOfType <EntityTypeDefinition>();

            foreach (var groupDefinition in existingGroupDefinitions)
            {
                if (groupDefinition.EntityType.TryToGroup(out EntityProperty entityProperty))
                {
                    groupDefinition.SetGroup(entityProperty);
                }
            }
        }
예제 #7
0
        public static GdOrganizerSettings GetSettingsFile()
        {
            if (_settings == null)
            {
                _settings = ScriptableObjectEditorUtils.FindFirstOfType <GdOrganizerSettings>();
                if (_settings == null)
                {
                    _settings = CreateSettingsFile();
                }
            }

            return(_settings);
        }
        public static void CleanupUnusedDefinitions()
        {
            var definitionNames          = Enum.GetNames(typeof(EntityProperty));
            var existingGroupDefinitions = ScriptableObjectEditorUtils.FindAllOfType <EntityPropertyDefinition>();

            if (definitionNames.Length != existingGroupDefinitions.Count)
            {
                foreach (var definition in existingGroupDefinitions)
                {
                    if (!definitionNames.Contains(definition.EntityType.ToString()))
                    {
                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(definition));
                    }
                }
            }
            AssetDatabase.Refresh();
        }
        public static void GenerateDefinitions()
        {
            var addedDefinitions         = new List <string>();
            var existingGroupDefinitions = ScriptableObjectEditorUtils.FindAllOfType <EntityPropertyDefinition>();

            var settings = ScriptableObjectEditorUtils.FindFirstOfType <GdOrganizerSettings>();

            var propertyDefinitionPath = Path.Combine(settings.DefinitionsRootPath, "EntityPropertyDefinitions");

            var definitionNames = Enum.GetNames(typeof(EntityProperty));

            foreach (var definitionName in definitionNames)
            {
                if (addedDefinitions.Contains(definitionName))
                {
                    continue;
                }

                if (!existingGroupDefinitions.Exists(x => x.EntityType.ToString().Equals(definitionName)))
                {
                    // create SO
                    var definitionInstance = ScriptableObject.CreateInstance <EntityPropertyDefinition>();
                    var groupType          = Enum.Parse(typeof(EntityType), definitionName);

                    definitionInstance.SetEntityType((EntityType)groupType);
                    if (!Directory.Exists(propertyDefinitionPath))
                    {
                        Directory.CreateDirectory(propertyDefinitionPath);
                    }

                    string fullPath = $"{Path.Combine(propertyDefinitionPath, definitionName)}.asset";
                    if (File.Exists(fullPath))
                    {
                        return;
                    }
                    AssetDatabase.CreateAsset(definitionInstance, fullPath);
                }
                addedDefinitions.Add(definitionName);
            }

            SetupGroupDefinitions();

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
예제 #10
0
        public static void OnCompileScripts()
        {
            if (!EditorPrefs.GetBool(RegenerationTriggeredKey))
            {
                return;
            }
            var entityGroupConfig = ScriptableObjectEditorUtils.FindFirstOfType <EntityPropertyConfig>();
            var entityTypeConfig  = ScriptableObjectEditorUtils.FindFirstOfType <EntityTypeConfig>();

            EntityTypeGenerator.CleanupUnusedDefinitions();
            EntityPropertyGenerator.CleanupUnusedDefinitions();

            EntityTypeGenerator.GenerateDefinitions();
            EntityPropertyGenerator.GenerateDefinitions();

            entityTypeConfig.EntityTypeDefinitions   = ScriptableObjectEditorUtils.FindAllOfType <EntityTypeDefinition>();
            entityGroupConfig.EntityGroupDefinitions = ScriptableObjectEditorUtils.FindAllOfType <EntityPropertyDefinition>();

            EditorPrefs.SetBool(RegenerationTriggeredKey, false);
        }
        public static void GenerateLookup()
        {
            string equalityCompararContent = "";
            string typePropLookupContent   = "";
            string propTypeLookupContent   = "";

            Dictionary <EntityProperty, List <EntityType> > PropertyTypeMap = new Dictionary <EntityProperty, List <EntityType> >();
            Dictionary <EntityType, List <EntityProperty> > TypePropertyMap = new Dictionary <EntityType, List <EntityProperty> >();

            string fileContent            = "";
            string typePropertyLookupName = "TypePropertiesLookup";
            string propertyTypeLookupName = "PropertyTypeLookup";
            var    path = "Assets/Modules/O.M.A.Games/GDOrganizer/Generated";

            var existingTypeDefinitions     = ScriptableObjectEditorUtils.FindAllOfType <EntityTypeDefinition>();
            var existingPropertyDefinitions = ScriptableObjectEditorUtils.FindAllOfType <EntityPropertyDefinition>();

            foreach (var propertyDefinition in existingPropertyDefinitions)
            {
                if (Enum.TryParse(propertyDefinition.EntityType.ToString(), out EntityProperty entityProperty))
                {
                    PropertyTypeMap.Add(entityProperty, new List <EntityType>());
                }
                else
                {
                    Debug.LogError("Cannot cast " + propertyDefinition);
                }
            }
            foreach (var typeDefinition in existingTypeDefinitions)
            {
                var properties = new List <EntityProperty>();
                foreach (var property in typeDefinition.EntityProperties.Properties)
                {
                    properties.Add(property);
                    if (PropertyTypeMap.ContainsKey(property))
                    {
                        PropertyTypeMap[property].Add(typeDefinition.EntityType);
                    }
                    else
                    {
                        Debug.LogError("Cannot find property " + property);
                    }
                }
                TypePropertyMap.Add(typeDefinition.EntityType, properties);
            }


            var settings = ScriptableObjectEditorUtils.FindFirstOfType <GdOrganizerSettings>();
            var fullPath = Path.Combine(path, GeneratedFileName);

            equalityCompararContent += GenerateEqualityComparer <EntityType>();
            equalityCompararContent += GenerateEqualityComparer <EntityProperty>();

            typePropLookupContent += GenerateLookupMap(typePropertyLookupName, TypePropertyMap);
            propTypeLookupContent += GenerateLookupMap(propertyTypeLookupName, PropertyTypeMap);

            AppendContent(CodeGenerationHelper.GetLine("using System;"), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine("using System.Collections.Generic;"), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine("using System.Linq;"), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine(""), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine("namespace O.M.A.Games.GDOrganizer.Generated"), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine("{"), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine("public static class EntityLookup", 1), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine("{", 1), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine(equalityCompararContent), ref fileContent);

            AppendContent(CodeGenerationHelper.GetLine(GenerateHasLookupMethod <EntityType, EntityProperty>("HasProperty", typePropertyLookupName), 2), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine(GenerateHasLookupMethod <EntityProperty, EntityType>("HasType", propertyTypeLookupName), 2), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine(GenerateGetLookupMethod <EntityType, EntityProperty>("GetProperties", typePropertyLookupName), 2), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine(GenerateGetLookupMethod <EntityProperty, EntityType>("GetTypes", propertyTypeLookupName), 2), ref fileContent);

            AppendContent(CodeGenerationHelper.GetLine(typePropLookupContent, 2), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine(propTypeLookupContent, 2), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine("}", 1), ref fileContent);
            AppendContent(CodeGenerationHelper.GetLine("}"), ref fileContent);

            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(path);
            }
            File.WriteAllText(fullPath, fileContent);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }