Skip to content

Commit 5b51ee7

Browse files
authored
Merge pull request #61 from Unity-Technologies/UNI-22052
Uni 22052 - fix small annoying things about fbx export settings
2 parents 44cc2df + 949048e commit 5b51ee7

File tree

3 files changed

+463
-86
lines changed

3 files changed

+463
-86
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,16 @@ static void OnContextItem (MenuCommand command)
7676
/// </summary>
7777
/// <returns>list of instanced Model Prefabs</returns>
7878
/// <param name="unityGameObjectsToConvert">Unity game objects to convert to Model Prefab instances</param>
79-
/// <param name="path">Path to save Model Prefab</param>
79+
/// <param name="path">Path to save Model Prefab; use FbxExportSettings if null</param>
8080
/// <param name="keepOriginal">If set to <c>true</c> keep original gameobject hierarchy.</param>
8181
public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGameObjectsToConvert, string path = null, bool keepOriginal = true)
8282
{
83+
if (path == null) {
84+
path = FbxExporters.EditorTools.ExportSettings.GetAbsoluteSavePath();
85+
} else {
86+
path = Path.GetFullPath(path);
87+
}
88+
8389
List<GameObject> result = new List<GameObject> ();
8490

8591
var exportSet = ModelExporter.RemoveRedundantObjects (unityGameObjectsToConvert);
@@ -90,8 +96,6 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
9096

9197
// find common ancestor root & filePath;
9298
string[] filePaths = new string[gosToExport.Length];
93-
if (path==null)
94-
path = FbxExporters.EditorTools.ExportSettings.instance.convertToModelSavePath;
9599

96100
for(int n = 0; n < gosToExport.Length; n++){
97101
var filename = ModelExporter.ConvertToValidFilename (gosToExport [n].name + ".fbx");
@@ -117,17 +121,16 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
117121
continue;
118122
}
119123

120-
// make filepath relative to project folder
121-
if (fbxFileName.StartsWith (Application.dataPath, System.StringComparison.CurrentCulture))
122-
{
123-
fbxFileName = "Assets" + fbxFileName.Substring (Application.dataPath.Length);
124-
}
124+
// make filepath relative to assets folder
125+
var relativePath = FbxExporters.EditorTools.ExportSettings.ConvertToAssetRelativePath(fbxFileName);
125126

126127
// refresh the assetdata base so that we can query for the model
127128
AssetDatabase.Refresh ();
128129

129-
// replace w Model asset
130-
Object unityMainAsset = AssetDatabase.LoadMainAssetAtPath (fbxFileName);
130+
// Replace w Model asset. LoadMainAssetAtPath wants a path
131+
// relative to the project, not relative to the assets
132+
// folder.
133+
Object unityMainAsset = AssetDatabase.LoadMainAssetAtPath("Assets/" + relativePath);
131134

132135
if (unityMainAsset != null) {
133136
Object unityObj = PrefabUtility.InstantiatePrefab (unityMainAsset);

0 commit comments

Comments
 (0)