/// <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); }
/// <summary> /// Gets the text content of template. /// </summary> /// <returns>The text content of template.</returns> private static string GetTplText() { string[] assetPaths = Utils.EditorUtil.GetAssetPath(dataTableRowScriptTemplateFileName, "t:TextAsset"); string tplPath = null; string tplText = null; if (assetPaths != null && assetPaths.Length > 0) { tplPath = assetPaths[0]; } if (!string.IsNullOrEmpty(tplPath)) { TextAsset tplAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(tplPath); if (tplAsset) { tplText = tplAsset.text; } } else { QuickUnityEditorApplication.DisplaySimpleDialog("", DialogMessages.CanNotFindTplFileMessage); } return(tplText); }
/// <summary> /// Draw editor GUI. /// </summary> private void OnGUI() { CalculateLabelWidth(); GUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.BeginVertical(); GUILayout.Space(10); preferencesData.DataTablesStorageLocation = (DataTableStorageLocation)EditorGUILayout.EnumPopup(Styles.DataTablesStorageLocationStyle, preferencesData.DataTablesStorageLocation); GUILayout.Space(2.5f); preferencesData.DataTableRowScriptsStorageLocation = Utils.EditorGUIHelper.FolderField(Styles.DataRowScriptsStorageLocationStyle, preferencesData.DataTableRowScriptsStorageLocation, "Data Row Scripts Storage Location", QuickUnityEditorApplication.AssetsFolderName); preferencesData.DataTableRowScriptsStorageLocation = Utils.EditorUtil.ConvertToAssetPath(preferencesData.DataTableRowScriptsStorageLocation); // Check scripts storage location. if (!string.IsNullOrEmpty(preferencesData.DataTableRowScriptsStorageLocation) && preferencesData.DataTableRowScriptsStorageLocation.IndexOf(QuickUnityEditorApplication.AssetsFolderName) != 0) { QuickUnityEditorApplication.DisplaySimpleDialog("", DialogMessages.MakeSureScriptsStorageLocationInProjectMessage, () => { preferencesData.DataTableRowScriptsStorageLocation = null; }); } GUILayout.Space(2.5f); preferencesData.AutoGenerateScriptsNamespace = EditorGUILayout.Toggle(Styles.AutoGenerateScriptsNamespaceStyle, preferencesData.AutoGenerateScriptsNamespace); GUILayout.Space(2.5f); EditorGUI.BeginDisabledGroup(preferencesData.AutoGenerateScriptsNamespace); preferencesData.DataTableRowScriptsNamespace = EditorGUILayout.TextField(Styles.DataTableRowScriptsNamespaceStyle, preferencesData.DataTableRowScriptsNamespace); // Handle empty namespace. if (preferencesData.AutoGenerateScriptsNamespace) { preferencesData.DataTableRowScriptsNamespace = null; } else if (string.IsNullOrEmpty(preferencesData.DataTableRowScriptsNamespace)) { preferencesData.DataTableRowScriptsNamespace = DataTablePreferences.DefaultNamespace; } EditorGUI.EndDisabledGroup(); GUILayout.Space(2.5f); preferencesData.DataRowsStartRow = EditorGUILayout.IntField(Styles.DataRowsStartRowStyle, preferencesData.DataRowsStartRow); preferencesData.DataRowsStartRow = Math.Max(preferencesData.DataRowsStartRow, DataTablePreferences.MinDataRowsStartRow); GUILayout.Space(10); GUILayout.EndVertical(); GUILayout.Space(10); GUILayout.EndHorizontal(); }
public static void Import() { if (CheckPreferencesData()) { string filesFolderPath = EditorUtility.OpenFolderPanel("Import Data...", "", ""); if (!string.IsNullOrEmpty(filesFolderPath)) { Utils.EditorUtil.ClearConsole(); ExcelFilesPath = filesFolderPath; GenerateDataTableRowScripts(filesFolderPath); } else { QuickUnityEditorApplication.DisplaySimpleDialog("", DialogMessages.DataImportAbortMessage); } } }
/// <summary> /// Generates the database files. /// </summary> private static void GenerateDBFiles() { string path = ExcelFilesPath; string namespaceString = GetNamespace(); DeleteOldDBFiles(); ForEachExcelFile(path, (DataTable table, string fileName, int index, int length) => { EditorUtility.DisplayProgressBar(importProgressBarTitle, string.Format(savingDataProgressBarInfo, fileName, index + 1, length), (float)(index + 1) / length); List <DataTableRowInfo> rowInfos = GenerateDataTableRowInfos(table); List <DataTableRow> collection = GenerateDataTableRowCollection(table, namespaceString, fileName, rowInfos); string classFullName = string.Format("{0}.{1}", namespaceString, fileName); Type type = ProjectAssemblies.GetType(classFullName); if (type != null) { ReflectionUtil.InvokeStaticGenericMethod(typeof(DataImport), "SaveData", type, new object[] { fileName, rowInfos, collection, index }); } else { Debug.LogErrorFormat(null, "Can not find the Type: {0}", classFullName); } }); DeleteDBConfigFiles(); RenameDBFiles(); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); EditorUtility.ClearProgressBar(); QuickUnityEditorApplication.DisplaySimpleDialog("", DialogMessages.DataImportDoneMessage); }