Skip to content

Commit 9bfde82

Browse files
authored
Merge pull request #43 from Unity-Technologies/UNI-21323-save-location-preference
UNI-21323 added preference for ConvertToModel save path
2 parents e823a9c + d6e4644 commit 9bfde82

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static List<GameObject> OnConvertInPlace (GameObject [] unityActiveGOs)
7575

7676
// find common ancestor root & filePath;
7777
string[] filePaths = new string[gosToExport.Length];
78-
string dirPath = Path.Combine (Application.dataPath, "Objects");
78+
string dirPath = FbxExporters.EditorTools.ExportSettings.instance.convertToModelSavePath;
7979

8080
for(int n = 0; n < gosToExport.Length; n++){
8181
var filename = ModelExporter.ConvertToValidFilename (gosToExport [n].name + ".fbx");

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,82 @@ namespace FbxExporters.EditorTools {
88

99
[CustomEditor(typeof(ExportSettings))]
1010
public class ExportSettingsEditor : UnityEditor.Editor {
11+
Vector2 scrollPos = Vector2.zero;
12+
const float LabelWidth = 225;
13+
const float SelectableLabelMinWidth = 200;
14+
const float BrowseButtonWidth = 55;
15+
1116
public override void OnInspectorGUI() {
1217
ExportSettings exportSettings = (ExportSettings)target;
1318

1419
// Increasing the label width so that none of the text gets cut off
15-
EditorGUIUtility.labelWidth = 300;
20+
EditorGUIUtility.labelWidth = LabelWidth;
21+
22+
scrollPos = GUILayout.BeginScrollView (scrollPos);
1623

1724
exportSettings.weldVertices = EditorGUILayout.Toggle ("Weld Vertices:", exportSettings.weldVertices);
1825
exportSettings.embedTextures = EditorGUILayout.Toggle ("Embed Textures:", exportSettings.embedTextures);
1926
exportSettings.mayaCompatibleNames = EditorGUILayout.Toggle (
20-
new GUIContent("Convert to Maya Compatible Naming:",
27+
new GUIContent ("Convert to Maya Compatible Naming:",
2128
"In Maya some symbols such as spaces and accents get replaced when importing an FBX " +
2229
"(e.g. \"foo bar\" becomes \"fooFBXASC032bar\"). " +
2330
"On export, convert the names of GameObjects so they are Maya compatible." +
24-
(exportSettings.mayaCompatibleNames? "" :
31+
(exportSettings.mayaCompatibleNames ? "" :
2532
"\n\nWARNING: Disabling this feature may result in lost material connections," +
26-
" and unexpected character replacements in Maya.")
33+
" and unexpected character replacements in Maya.")
2734
),
2835
exportSettings.mayaCompatibleNames);
2936

37+
GUILayout.BeginHorizontal ();
38+
GUILayout.Label (new GUIContent (
39+
"Model Prefab Path:",
40+
"Relative path for saving Model Prefabs."));
41+
42+
EditorGUILayout.SelectableLabel(GetRelativePath(exportSettings.convertToModelSavePath, Application.dataPath),
43+
EditorStyles.textField, GUILayout.MinWidth(SelectableLabelMinWidth), GUILayout.Height(EditorGUIUtility.singleLineHeight));
44+
45+
if (GUILayout.Button ("Browse", EditorStyles.miniButton, GUILayout.Width (BrowseButtonWidth))) {
46+
string path = EditorUtility.OpenFolderPanel (
47+
"Select Model Prefabs Path", Application.dataPath, null
48+
);
49+
// Make sure something is selected, and that it is in the Asset folder
50+
if (!string.IsNullOrEmpty (path) && path.StartsWith (Application.dataPath)) {
51+
exportSettings.convertToModelSavePath = path;
52+
} else {
53+
Debug.LogWarning ("Please select a location in Assets/");
54+
}
55+
}
56+
57+
GUILayout.EndHorizontal ();
58+
GUILayout.FlexibleSpace ();
59+
GUILayout.EndScrollView ();
60+
3061
if (GUI.changed) {
3162
EditorUtility.SetDirty (exportSettings);
3263
exportSettings.Save ();
3364
}
3465
}
66+
67+
private string GetRelativePath(string filePath, string folder){
68+
Uri pathUri;
69+
try{
70+
pathUri = new Uri (filePath);
71+
}
72+
catch(UriFormatException){
73+
return filePath;
74+
}
75+
if (!folder.EndsWith (Path.DirectorySeparatorChar.ToString ())) {
76+
folder += Path.DirectorySeparatorChar;
77+
}
78+
Uri folderUri = new Uri (folder);
79+
string relativePath = Uri.UnescapeDataString (
80+
folderUri.MakeRelativeUri (pathUri).ToString ().Replace ('/', Path.DirectorySeparatorChar)
81+
);
82+
if (!relativePath.StartsWith ("Assets")) {
83+
relativePath = string.Format("Assets{0}{1}", Path.DirectorySeparatorChar, relativePath);
84+
}
85+
return relativePath;
86+
}
3587
}
3688

3789
[FilePath("ProjectSettings/FbxExportSettings.asset",FilePathAttribute.Location.ProjectFolder)]
@@ -40,6 +92,12 @@ public class ExportSettings : FbxExporters.EditorTools.ScriptableSingleton<Expor
4092
public bool weldVertices = true;
4193
public bool embedTextures = false;
4294
public bool mayaCompatibleNames = true;
95+
public string convertToModelSavePath;
96+
97+
void OnEnable()
98+
{
99+
convertToModelSavePath = Path.Combine (Application.dataPath, "Objects");
100+
}
43101

44102
[MenuItem("Edit/Project Settings/Fbx Export", priority = 300)]
45103
static void ShowManager()

0 commit comments

Comments
 (0)