コード例 #1
0
        /// <summary>
        /// Deletes old database files.
        /// </summary>
        private static void DeleteOldDBFiles()
        {
            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (preferencesData)
            {
                string path = dataTablesLocationMap[preferencesData.DataTablesStorageLocation];

                // If directory doesn't exist, create it.
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                DirectoryInfo dirInfo   = new DirectoryInfo(path);
                FileInfo[]    fileInfos = dirInfo.GetFiles();

                for (int i = 0, length = fileInfos.Length; i < length; ++i)
                {
                    FileInfo fileInfo = fileInfos[i];

                    try
                    {
                        fileInfo.Delete();
                    }
                    catch (Exception exception)
                    {
                        Debug.LogException(exception);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the namespace.
        /// </summary>
        /// <returns>The namespace of scripts.</returns>
        private static string GetNamespace()
        {
            string namespaceString = string.Empty;

            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (preferencesData)
            {
                if (preferencesData.AutoGenerateScriptsNamespace)
                {
                    // Generate namespace automatically.
                    namespaceString = GenerateNamespace(preferencesData);
                }
                else
                {
                    namespaceString = preferencesData.DataTableRowScriptsNamespace;
                }
            }

            // Handle empty namespace.
            if (string.IsNullOrEmpty(namespaceString))
            {
                namespaceString = DataTablePreferences.DefaultNamespace;
            }

            return(namespaceString);
        }
コード例 #3
0
        /// <summary>
        /// Checks the preferences data.
        /// </summary>
        /// <returns><c>true</c> if preferences data is ready, <c>false</c> otherwise.</returns>
        private static bool CheckPreferencesData()
        {
            bool success = true;

            // Load preferences data or create default preferences data.
            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (!preferencesData)
            {
                preferencesData = DataTablePreferencesWindow.CreateDefaultPreferencesData();
                DataTablePreferencesWindow.SavePreferenceData(preferencesData);
            }

            // Check preferences data is safe.
            if (string.IsNullOrEmpty(preferencesData.DataTableRowScriptsStorageLocation))
            {
                QuickUnityEditorApplication.DisplaySimpleDialog("", DialogMessages.DataTableRowScriptsStorageLocationNullMessage, () =>
                {
                    success = false;
                    DataTablePreferencesWindow.ShowEditorWindow();
                });
            }

            return(success);
        }
コード例 #4
0
        public static void ShowEditorWindow()
        {
            if (editorWindow == null)
            {
                editorWindow = CreateInstance <DataTablePreferencesWindow>();
                editorWindow.titleContent = new GUIContent("DataTable Preferences");
                editorWindow.minSize      = new Vector2(500, 120);
            }

            editorWindow.ShowUtility();
            editorWindow.Focus();
        }
コード例 #5
0
        /// <summary>
        /// Gets the database files path.
        /// </summary>
        /// <returns>The database files path.</returns>
        private static string GetDBFilesPath()
        {
            string path = dataTablesLocationMap[DataTableStorageLocation.PersistentDataPath];

            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (preferencesData)
            {
                path = dataTablesLocationMap[preferencesData.DataTablesStorageLocation];
            }

            return(path);
        }
コード例 #6
0
        /// <summary>
        /// Generates the data table row collection.
        /// </summary>
        /// <param name="table">The data table.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="rowInfos">The list of DataTableRow.</param>
        /// <returns>The data collection of data table row.</returns>
        private static List <DataTableRow> GenerateDataTableRowCollection(DataTable table, string namespaceString, string className, List <DataTableRowInfo> rowInfos)
        {
            List <DataTableRow> dataCollection = new List <DataTableRow>();
            string classFullName = className;

            if (!string.IsNullOrEmpty(namespaceString))
            {
                classFullName = string.Format("{0}.{1}", namespaceString, classFullName);
            }

            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (preferencesData)
            {
                int rowCount = table.Rows.Count;

                for (int i = preferencesData.DataRowsStartRow - 1; i < rowCount; ++i)
                {
                    DataTableRow rowData = (DataTableRow)UnityReflectionUtil.CreateInstance(classFullName);

                    for (int j = 0, propertiesCount = rowInfos.Count; j < propertiesCount; ++j)
                    {
                        string cellValue = table.Rows[i][j].ToString().Trim();

                        if (!string.IsNullOrEmpty(cellValue))
                        {
                            DataTableRowInfo rowInfo    = rowInfos[j];
                            ITypeParser      typeParser = GetTypeParser(rowInfo.Type);

                            if (typeParser != null)
                            {
                                object value = typeParser.Parse(cellValue);
                                ReflectionUtil.SetObjectPropertyValue(rowData, rowInfo.PropertyName, value);
                            }
                            else
                            {
                                Debug.LogWarningFormat("Type '{0}' is not supported!", rowInfo.Type);
                            }
                        }
                    }

                    dataCollection.Add(rowData);
                }
            }

            return(dataCollection);
        }
コード例 #7
0
        /// <summary>
        /// Generates the script of DataTableRow.
        /// </summary>
        /// <param name="tplText">The script template text.</param>
        /// <param name="namesapceString">The string of namesapce.</param>
        /// <param name="scriptName">Name of the script.</param>
        /// <param name="rowInfos">The list of DataTableRowInfo.</param>
        private static void GenerateDataTableRowScript(string tplText, string namesapceString, string scriptName, List <DataTableRowInfo> rowInfos)
        {
            tplText = tplText.Replace(ScriptTemplateSpecifiers.NamespaceSpecifier, namesapceString);
            tplText = tplText.Replace(ScriptTemplateSpecifiers.ScriptNameSpecifier, scriptName);
            tplText = tplText.Replace(ScriptTemplateSpecifiers.PropertiesSpecifier, GenerateScriptPropertiesString(rowInfos));

            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (preferencesData)
            {
                if (!Directory.Exists(preferencesData.DataTableRowScriptsStorageLocation))
                {
                    Directory.CreateDirectory(preferencesData.DataTableRowScriptsStorageLocation);
                }

                string             scriptFilePath = Path.Combine(preferencesData.DataTableRowScriptsStorageLocation, scriptName + scriptFileExtension);
                UnityEngine.Object scriptAsset    = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(scriptFilePath);

                if (scriptAsset)
                {
                    EditorUtility.SetDirty(scriptAsset);
                }

                FileStream   fileStream = null;
                StreamWriter writer     = null;

                try
                {
                    fileStream = File.Open(scriptFilePath, FileMode.Create, FileAccess.Write);
                    writer     = new StreamWriter(fileStream, new UTF8Encoding(true));
                    writer.Write(tplText);
                }
                catch (Exception exception)
                {
                    Debug.LogException(exception);
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// If necessary, Renames the database files.
        /// </summary>
        private static void RenameDBFiles()
        {
            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (preferencesData && preferencesData.DataTablesStorageLocation == DataTableStorageLocation.ResourcesPath)
            {
                string   path      = dataTablesLocationMap[preferencesData.DataTablesStorageLocation];
                string[] filePaths = Directory.GetFiles(path);

                for (int i = 0, length = filePaths.Length; i < length; ++i)
                {
                    string   filePath = filePaths[i];
                    FileInfo fileInfo = new FileInfo(filePath);

                    if (fileInfo.Extension == boxDbFileExtension)
                    {
                        string newFileName = fileInfo.GetFileNameWithoutExtension() + QuickUnityEditorApplication.BytesAssetFileExtension;
                        fileInfo.Rename(newFileName);
                    }
                }
            }
        }