Skip to content

Commit 0fbed1b

Browse files
author
Benoit Hudson
committed
UNI-22401: review comments
Remove trailing slashes. Switch to always storing / so multi-platform teams don't get clashes. Switch to always using the platform path separator locally.
1 parent 187d22c commit 0fbed1b

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public override void OnInspectorGUI() {
4646
"Relative path for saving Model Prefabs."));
4747

4848
var pathLabel = ExportSettings.GetRelativeSavePath();
49-
if (pathLabel == "./") { pathLabel = "(Assets root)"; }
49+
if (pathLabel == ".") { pathLabel = "(Assets root)"; }
5050
EditorGUILayout.SelectableLabel(pathLabel,
5151
EditorStyles.textField,
5252
GUILayout.MinWidth(SelectableLabelMinWidth),
@@ -128,7 +128,13 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
128128

129129
/// <summary>
130130
/// The path where Convert To Model will save the new fbx and prefab.
131-
/// This is relative to the Application.dataPath
131+
///
132+
/// To help teams work together, this is stored to be relative to the
133+
/// Application.dataPath, and the path separator is the forward-slash
134+
/// (e.g. unix and http, not windows).
135+
///
136+
/// Use GetRelativeSavePath / SetRelativeSavePath to get/set this
137+
/// value, properly interpreted for the current platform.
132138
/// </summary>
133139
[SerializeField]
134140
string convertToModelSavePath = kDefaultSavePath;
@@ -142,6 +148,18 @@ public static string GetRelativeSavePath() {
142148
if (string.IsNullOrEmpty(relativePath)) {
143149
relativePath = kDefaultSavePath;
144150
}
151+
152+
// Normalize to the platform path separator.
153+
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar,
154+
Path.DirectorySeparatorChar);
155+
156+
// Trim off trailing slashes. If all we had was slashes, we're at
157+
// the root of the Application.dataPath so return "."
158+
relativePath = relativePath.TrimEnd(Path.DirectorySeparatorChar);
159+
if (string.IsNullOrEmpty(relativePath)) {
160+
relativePath = ".";
161+
}
162+
145163
return relativePath;
146164
}
147165

@@ -160,7 +178,9 @@ public static string GetAbsoluteSavePath() {
160178
/// This is interpreted as being relative to the Application.dataPath
161179
/// </summary>
162180
public static void SetRelativeSavePath(string newPath) {
163-
instance.convertToModelSavePath = newPath;
181+
instance.convertToModelSavePath = newPath
182+
.Replace('\\', '/')
183+
.TrimEnd(Path.DirectorySeparatorChar);
164184
}
165185

166186
[MenuItem("Edit/Project Settings/Fbx Export", priority = 300)]
@@ -204,8 +224,7 @@ private static T CreateAndLoad()
204224
// First create.
205225
if (s_Instance == null)
206226
{
207-
T t = ScriptableObject.CreateInstance<T>();
208-
s_Instance = t;
227+
s_Instance = ScriptableObject.CreateInstance<T>();
209228
}
210229

211230
// Then load.

0 commit comments

Comments
 (0)