public static InfoTableSettings GetOrCreateAndSave() { InfoTableSettings settings = null; var guids = AssetDatabase.FindAssets($"t:{typeof(InfoTableSettings)}"); if (guids.Length > 0) { var guid = guids[0]; string assetPath = AssetDatabase.GUIDToAssetPath(guid); settings = AssetDatabase.LoadAssetAtPath <InfoTableSettings>(assetPath); } if (settings == null) { //Save a new settings file settings = CreateInstance <InfoTableSettings>(); var path = EditorUtility.SaveFilePanel("Save InfoTableSettings", "Assets", "InfoTableSettings", "asset"); if (string.IsNullOrEmpty(path)) { return(null); } if (path.StartsWith(Application.dataPath)) { path = "Assets" + path.Substring(Application.dataPath.Length); } AssetDatabase.CreateAsset(settings, path); } return(settings); }
public static InfoTableSettings Get() { InfoTableSettings settings = null; var guids = AssetDatabase.FindAssets($"t:{typeof(InfoTableSettings)}"); if (guids.Length > 0) { var guid = guids[0]; string assetPath = AssetDatabase.GUIDToAssetPath(guid); settings = AssetDatabase.LoadAssetAtPath <InfoTableSettings>(assetPath); } if (settings == null) { //Create an instance with default values settings = CreateInstance <InfoTableSettings>(); } return(settings); }
public void Export(bool skipDialog = false) { if (!ValidateEntries()) { Debug.LogError("Export Failed"); return; } if (!skipDialog && !EditorUtility.DisplayDialog("Export Info Table", "Exporting will write source code. It's recommended that you commit all current changes to version control before continuing. Continue?", "Ok", "Cancel")) { return; } var settings = InfoTableSettings.Get(); if (settings == null) { return; } if (!Directory.Exists(settings.exportPath)) { if (!EditorUtility.DisplayDialog("Export Info Table", "Export directory does not exist. Create it?", "Ok", "Cancel")) { return; } //Create export directory Directory.CreateDirectory(settings.exportPath); } var entries = GetExportables(); if (exportInvalidEntry) { entries = entries.Append(new InvalidEntry(invalidEntryName)).ToArray(); } //Building the dictionary should also validate we have no dupes BuildAndWriteExportables(ExportedEnumTypeName, entries, settings.exportPath); }