Skip to content

Commit 7a10219

Browse files
committed
store 5 most recently used save paths
- show them in a dropdown in the export model settings window
1 parent 1dc8ca1 commit 7a10219

File tree

2 files changed

+76
-21
lines changed

2 files changed

+76
-21
lines changed

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,22 @@ void OnGUI ()
4848
"Export Path:",
4949
"Relative path for saving Model Prefabs."),GUILayout.Width(LabelWidth - FieldOffset));
5050

51-
var pathLabel = ExportSettings.GetRelativeSavePath();
52-
if (pathLabel == ".") { pathLabel = "(Assets root)"; }
53-
EditorGUILayout.SelectableLabel(pathLabel,
54-
EditorStyles.textField,
55-
GUILayout.MinWidth(SelectableLabelMinWidth),
56-
GUILayout.Height(EditorGUIUtility.singleLineHeight));
51+
var pathLabels = ExportSettings.GetRelativeSavePaths();
52+
for(int i = 0; i < pathLabels.Length; i++){
53+
if (pathLabels[i] == ".") {
54+
pathLabels[i] = "(Assets root)";
55+
break; // no duplicate paths so safe to break
56+
}
57+
}
58+
59+
ExportSettings.instance.selectedExportModelPath = EditorGUILayout.Popup (ExportSettings.instance.selectedExportModelPath, pathLabels, GUILayout.MinWidth(SelectableLabelMinWidth));
5760

5861
if (GUILayout.Button(new GUIContent("...", "Browse to a new location for saving model prefabs"), EditorStyles.miniButton, GUILayout.Width(BrowseButtonWidth)))
5962
{
60-
string initialPath = ExportSettings.GetAbsoluteSavePath();
61-
62-
// if the directory doesn't exist, set it to the default save path
63-
// so we don't open somewhere unexpected
64-
if (!System.IO.Directory.Exists(initialPath))
65-
{
66-
initialPath = Application.dataPath;
67-
}
63+
string initialPath = Application.dataPath;
6864

6965
string fullPath = EditorUtility.OpenFolderPanel(
70-
"Select Model Prefabs Path", initialPath, null
66+
"Select Export Model Path", initialPath, null
7167
);
7268

7369
// Unless the user canceled, make sure they chose something in the Assets folder.
@@ -80,7 +76,7 @@ void OnGUI ()
8076
}
8177
else
8278
{
83-
ExportSettings.SetRelativeSavePath(relativePath);
79+
ExportSettings.AddExportModelSavePath(relativePath);
8480

8581
// Make sure focus is removed from the selectable label
8682
// otherwise it won't update
@@ -113,7 +109,9 @@ void OnGUI ()
113109
}
114110

115111
if (GUILayout.Button ("Export")) {
116-
var filePath = ExportSettings.GetAbsoluteSavePath();
112+
var filePath = ExportSettings.GetExportModelAbsoluteSavePath ();
113+
ExportSettings.AddExportModelSavePath(filePath);
114+
117115
filePath = System.IO.Path.Combine (filePath, m_exportFileName);
118116

119117
// check if file already exists, give a warning if it does
@@ -124,6 +122,11 @@ void OnGUI ()
124122
"Overwrite", "Cancel");
125123
if (!overwrite) {
126124
this.Close ();
125+
126+
if (GUI.changed) {
127+
EditorUtility.SetDirty (ExportSettings.instance);
128+
ExportSettings.instance.Save ();
129+
}
127130
return;
128131
}
129132
}
@@ -136,6 +139,11 @@ void OnGUI ()
136139
this.Close ();
137140
}
138141
GUILayout.EndHorizontal ();
142+
143+
if (GUI.changed) {
144+
EditorUtility.SetDirty (ExportSettings.instance);
145+
ExportSettings.instance.Save ();
146+
}
139147
}
140148
}
141149
}

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,12 @@ public enum LODExportType {
469469
[SerializeField]
470470
string convertToModelSavePath;
471471

472+
[SerializeField]
473+
private List<string> exportModelSavePaths = new List<string> ();
474+
475+
public int selectedExportModelPath = 0;
476+
private int maxStoredSavePaths = 5;
477+
472478
// List of names in order that they appear in option list
473479
[SerializeField]
474480
private List<string> dccOptionNames = new List<string>();
@@ -485,6 +491,7 @@ protected override void LoadDefaults()
485491
HideSendToUnityMenu = true;
486492
ExportFormatSelection = 0;
487493
convertToModelSavePath = kDefaultSavePath;
494+
exportModelSavePaths = new List<string> (){ kDefaultSavePath };
488495
IntegrationSavePath = DefaultIntegrationSavePath;
489496
dccOptionPaths = null;
490497
dccOptionNames = null;
@@ -978,17 +985,57 @@ public static string GetRelativeSavePath() {
978985
return NormalizePath(relativePath, isRelative: true);
979986
}
980987

988+
public static string[] GetRelativeSavePaths(){
989+
var exportSavePaths = instance.exportModelSavePaths;
990+
if (exportSavePaths.Count == 0) {
991+
exportSavePaths.Add (kDefaultSavePath);
992+
}
993+
string[] relSavePaths = new string[exportSavePaths.Count];
994+
for (int i = 0; i < relSavePaths.Length; i++) {
995+
relSavePaths [i] = string.Format("Assets\\{0}", exportSavePaths[i] == "."? "" : NormalizePath(exportSavePaths [i], isRelative: true).Replace("/", "\\"));
996+
}
997+
return relSavePaths;
998+
}
999+
1000+
public static void AddExportModelSavePath(string savePath){
1001+
savePath = ConvertToAssetRelativePath (savePath);
1002+
var exportSavePaths = instance.exportModelSavePaths;
1003+
if (exportSavePaths.Contains (savePath)) {
1004+
// move to first place if it isn't already
1005+
if (exportSavePaths [0] == savePath) {
1006+
return;
1007+
}
1008+
exportSavePaths.Remove (savePath);
1009+
}
1010+
1011+
if (exportSavePaths.Count >= instance.maxStoredSavePaths) {
1012+
// remove last used path
1013+
exportSavePaths.RemoveAt(exportSavePaths.Count-1);
1014+
}
1015+
1016+
exportSavePaths.Insert (0, savePath);
1017+
instance.selectedExportModelPath = 0;
1018+
}
1019+
1020+
public static string GetAbsoluteSavePath(string relativePath){
1021+
var absolutePath = Path.Combine(Application.dataPath, relativePath);
1022+
return NormalizePath(absolutePath, isRelative: false,
1023+
separator: Path.DirectorySeparatorChar);
1024+
}
1025+
9811026
/// <summary>
9821027
/// The path where Convert To Model will save the new fbx and prefab.
9831028
/// This is an absolute path, with platform separators.
9841029
/// </summary>
9851030
public static string GetAbsoluteSavePath() {
986-
var relativePath = GetRelativeSavePath();
987-
var absolutePath = Path.Combine(Application.dataPath, relativePath);
988-
return NormalizePath(absolutePath, isRelative: false,
989-
separator: Path.DirectorySeparatorChar);
1031+
return GetAbsoluteSavePath (GetRelativeSavePath ());
9901032
}
9911033

1034+
public static string GetExportModelAbsoluteSavePath(){
1035+
return GetAbsoluteSavePath (instance.exportModelSavePaths [instance.selectedExportModelPath]);
1036+
}
1037+
1038+
9921039
/// <summary>
9931040
/// Set the path where Convert To Model will save the new fbx and prefab.
9941041
/// This is interpreted as being relative to the Application.dataPath

0 commit comments

Comments
 (0)