Skip to content

Commit c76a0bb

Browse files
author
Benoit Hudson
committed
Yet another bug on windows. Added a unit test.
It was another issue of wrong slashes.
1 parent e338666 commit c76a0bb

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
130130
// Replace w Model asset. LoadMainAssetAtPath wants a path
131131
// relative to the project, not relative to the assets
132132
// folder.
133-
Object unityMainAsset = AssetDatabase.LoadMainAssetAtPath(Path.Combine("Assets", relativePath));
133+
Object unityMainAsset = AssetDatabase.LoadMainAssetAtPath("Assets/" + relativePath);
134134

135135
if (unityMainAsset != null) {
136136
Object unityObj = PrefabUtility.InstantiatePrefab (unityMainAsset);

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ public override void OnInspectorGUI() {
6161
// Unless the user canceled, make sure they chose something in the Assets folder.
6262
if (!string.IsNullOrEmpty (fullPath)) {
6363
var relativePath = ExportSettings.ConvertToAssetRelativePath(fullPath);
64-
if (string.IsNullOrEmpty(relativePath)
65-
|| relativePath == ".."
66-
|| relativePath.StartsWith(".." + Path.DirectorySeparatorChar)) {
64+
if (string.IsNullOrEmpty(relativePath)) {
6765
Debug.LogWarning ("Please select a location in the Assets folder");
6866
} else {
6967
ExportSettings.SetRelativeSavePath(relativePath);
@@ -153,10 +151,21 @@ public static void SetRelativeSavePath(string newPath) {
153151
/// get from GetRelativeSavePath.
154152
///
155153
/// This uses '/' as the path separator.
154+
///
155+
/// If 'requireSubdirectory' is the default on, return empty-string if the full
156+
/// path is not in a subdirectory of assets.
156157
/// </summary>
157-
public static string ConvertToAssetRelativePath(string fullPathInAssets)
158+
public static string ConvertToAssetRelativePath(string fullPathInAssets, bool requireSubdirectory = true)
158159
{
159-
return GetRelativePath(Application.dataPath, fullPathInAssets);
160+
var relativePath = GetRelativePath(Application.dataPath, fullPathInAssets);
161+
if (requireSubdirectory && relativePath.StartsWith("..")) {
162+
if (relativePath.Length == 2 || relativePath[2] == '/') {
163+
// The relative path has us pop out to another directory,
164+
// so return an empty string as requested.
165+
return "";
166+
}
167+
}
168+
return relativePath;
160169
}
161170

162171
/// <summary>

Assets/FbxExporters/Editor/UnitTests/FbxExportSettingsTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ public void TestGetRelativePath()
153153
to = Path.Combine(Application.dataPath, "foo");
154154
relative = ExportSettings.ConvertToAssetRelativePath(to);
155155
Assert.AreEqual("foo", relative);
156+
157+
relative = ExportSettings.ConvertToAssetRelativePath("/path/to/somewhere/else");
158+
Assert.AreEqual("", relative);
159+
160+
relative = ExportSettings.ConvertToAssetRelativePath("/path/to/somewhere/else", requireSubdirectory: false);
161+
Assert.IsTrue(relative.StartsWith("../"));
162+
Assert.IsFalse(relative.Contains("\\"));
156163
}
157164

158165
[Test]

0 commit comments

Comments
 (0)