コード例 #1
0
        private static void CopyDatabaseFile(string dbFolderPath, long dbLocalAddress, string entityName = null)
        {
            var sourceFilePath = PathUtility.UnifyToAltDirectorySeparatorChar(Path.Combine(TempFolderPath, $"db{dbLocalAddress}.box"));
            var newFileName    = dbLocalAddress > 1 ? $"{entityName}.db.bytes" : "MetadataEntityDBConfig.db.bytes";
            var destFilePath   = PathUtility.UnifyToAltDirectorySeparatorChar(Path.Combine(dbFolderPath, newFileName));

            FileUtil.ReplaceFile(sourceFilePath, destFilePath);
            EncryptFileRawData(destFilePath);
            var assetFilePath = EditorPath.ConvertToAssetPath(destFilePath);

            AssetDatabase.ImportAsset(assetFilePath);
        }
コード例 #2
0
        private static bool GenerateMetadataEntityScript(MetadataAssetSettings settings, string entityScriptName, List <MetadataEntityRawInfo> rawInfoList)
        {
            try
            {
                entityScriptName = entityScriptName.ToTitleCase();
                var scriptTextContent = ScriptTemplate.LoadScriptTemplateFile("NewMetadataEntityScriptTemplate.txt", UnityPackageName);
                scriptTextContent = scriptTextContent.Replace(ScriptTemplate.Placeholders.Namespace, settings.EntityScriptNamespace);
                scriptTextContent = scriptTextContent.Replace(ScriptTemplate.Placeholders.ScriptName, entityScriptName);
                scriptTextContent = scriptTextContent.Replace(ScriptTemplate.Placeholders.EnumInsideOfClass, GenerateEntityScriptEnumString(rawInfoList));
                scriptTextContent = scriptTextContent.Replace(ScriptTemplate.Placeholders.Properties, GenerateEntityScriptPropertiesString(rawInfoList));

                var scriptStorePath = EditorPath.ConvertToAbsolutePath(settings.EntityScriptsStorePath, $"{entityScriptName}.cs");
                var assetPath       = EditorPath.ConvertToAssetPath(scriptStorePath);
                File.WriteAllText(scriptStorePath, scriptTextContent, new UTF8Encoding(true));
                AssetDatabase.ImportAsset(assetPath);
                return(true);
            }
            catch (Exception ex)
            {
                UnityDebug.LogError(ex.ToString());
                return(false);
            }
        }
コード例 #3
0
        internal void DrawEditorGUI()
        {
            if (settings == null)
            {
                return;
            }

            GUILayout.BeginVertical();

            // Import Settings
            GUILayout.Label("Import Settings", EditorStyles.boldLabel);
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            GUILayout.BeginVertical();

            // Excel Sheets Folder Path
            if (!string.IsNullOrEmpty(settings.ExcelWorkbookFilesFolderPath) && !Directory.Exists(settings.ExcelWorkbookFilesFolderPath))
            {
                settings.ExcelWorkbookFilesFolderPath = string.Empty;
            }

            settings.ExcelWorkbookFilesFolderPath = EditorGUILayoutUtility.FolderField(new GUIContent("Excel Workbook Files Folder Path",
                                                                                                      "The folder path where to locate excel workbook files."), settings.ExcelWorkbookFilesFolderPath, "Excel Workbook Files Folder Path", string.Empty, string.Empty, LabelWidth);

            // Metadata Persistent Store Path
            var metadataPersistentStoreAbsolutePath = EditorGUILayoutUtility.FolderField(new GUIContent("Metadata Persistent Store Path",
                                                                                                        "The folder path where to store metadata."), settings.MetadataPersistentStorePath, "Metadata Persistent Store Path", settings.MetadataPersistentStorePath, string.Empty, LabelWidth);

            if (EditorPath.IsAssetPath(metadataPersistentStoreAbsolutePath))
            {
                settings.MetadataPersistentStorePath = EditorPath.ConvertToAssetPath(metadataPersistentStoreAbsolutePath);
            }
            else
            {
                Debug.LogError("The 'Metadata Persistent Store Path' you choose is invalid path, please select the folder in the project!");
            }

            // Metadata Entity Scripts Store Path
            var entityScriptsStoreAbsolutePath = EditorGUILayoutUtility.FolderField(new GUIContent("Entity Scripts Store Path",
                                                                                                   "The folder path where to store metadata entity scripts."), settings.EntityScriptsStorePath, "Entity Scripts Store Path", settings.EntityScriptsStorePath, string.Empty, LabelWidth);

            if (EditorPath.IsAssetPath(entityScriptsStoreAbsolutePath))
            {
                settings.EntityScriptsStorePath = EditorPath.ConvertToAssetPath(entityScriptsStoreAbsolutePath);
            }
            else
            {
                Debug.LogError("The 'Entity Scripts Store Path' you choose is invalid path, please select the folder in the project!");
            }

            // Metadata Entity Namespace
            using (new EditorGUIFieldScope(LabelWidth))
            {
                settings.EntityScriptNamespace = EditorGUILayout.TextField(new GUIContent("Entity Script Namespace",
                                                                                          "The namespace of entity script."), settings.EntityScriptNamespace);
            }

            // Metadata Entity Property Comment Row Index
            using (new EditorGUIFieldScope(LabelWidth))
            {
                settings.EntityPropertyCommentRowIndex = EditorGUILayout.IntSlider(new GUIContent("Entity Property Comment Definition Row Index",
                                                                                                  "The row index of entity property comment definition."), settings.EntityPropertyCommentRowIndex, 0, MaxIntValue);
            }

            // Metadata Entity Property Type Row Index
            using (new EditorGUIFieldScope(LabelWidth))
            {
                settings.EntityPropertyTypeRowIndex = EditorGUILayout.IntSlider(new GUIContent("Entity Property Type Definition Row Index",
                                                                                               "The row index of entity property type definition."), settings.EntityPropertyTypeRowIndex, 0, MaxIntValue);
            }

            // Metadata Entity Property Name Row Index
            using (new EditorGUIFieldScope(LabelWidth))
            {
                settings.EntityPropertyNameRowIndex = EditorGUILayout.IntSlider(new GUIContent("Entity Property Name Definition Row Index",
                                                                                               "The row index of entity property name definition."), settings.EntityPropertyNameRowIndex, 0, MaxIntValue);
            }

            // Metadata Entity Property Value Starting Row Index
            using (new EditorGUIFieldScope(LabelWidth))
            {
                settings.EntityDataStartingRowIndex = EditorGUILayout.IntSlider(new GUIContent("Entity Data Starting Row Index",
                                                                                               "The row index and after will be entity data definitions."), settings.EntityDataStartingRowIndex, 0, MaxIntValue);
            }

            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.EndHorizontal();

            GUILayout.Space(20);

            // Other Settings
            GUILayout.Label("Other Settings", EditorStyles.boldLabel);

            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            GUILayout.BeginVertical();

            // Data encryption/decryption
            using (new EditorGUIFieldScope(LabelWidth))
            {
                settings.DataEncryptionAndDecryption = EditorGUILayout.Toggle(new GUIContent("Data Encryption/Decryption",
                                                                                             "Generate database file with encryption, and load metadata with decryption."), settings.DataEncryptionAndDecryption);
            }

            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.EndHorizontal();

            GUILayout.Space(20);

            using (new EditorGUIFieldScope(LabelWidth))
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Build Metadata Assets", GUILayout.Width(LabelWidth), GUILayout.Height(25)))
                {
                    BuildAssets();
                    GUIUtility.ExitGUI();
                }
                GUILayout.FlexibleSpace();
            }

            GUILayout.Space(20);

            GUILayout.EndVertical();
        }