@@ -76,10 +76,16 @@ static void OnContextItem (MenuCommand command)
76
76
/// </summary>
77
77
/// <returns>list of instanced Model Prefabs</returns>
78
78
/// <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>
80
80
/// <param name="keepOriginal">If set to <c>true</c> keep original gameobject hierarchy.</param>
81
81
public static GameObject [ ] CreateInstantiatedModelPrefab ( GameObject [ ] unityGameObjectsToConvert , string path = null , bool keepOriginal = true )
82
82
{
83
+ if ( path == null ) {
84
+ path = FbxExporters . EditorTools . ExportSettings . GetAbsoluteSavePath ( ) ;
85
+ } else {
86
+ path = Path . GetFullPath ( path ) ;
87
+ }
88
+
83
89
List < GameObject > result = new List < GameObject > ( ) ;
84
90
85
91
var exportSet = ModelExporter . RemoveRedundantObjects ( unityGameObjectsToConvert ) ;
@@ -90,8 +96,6 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
90
96
91
97
// find common ancestor root & filePath;
92
98
string [ ] filePaths = new string [ gosToExport . Length ] ;
93
- if ( path == null )
94
- path = FbxExporters . EditorTools . ExportSettings . instance . convertToModelSavePath ;
95
99
96
100
for ( int n = 0 ; n < gosToExport . Length ; n ++ ) {
97
101
var filename = ModelExporter . ConvertToValidFilename ( gosToExport [ n ] . name + ".fbx" ) ;
@@ -117,17 +121,16 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
117
121
continue ;
118
122
}
119
123
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 ) ;
125
126
126
127
// refresh the assetdata base so that we can query for the model
127
128
AssetDatabase . Refresh ( ) ;
128
129
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 ) ;
131
134
132
135
if ( unityMainAsset != null ) {
133
136
Object unityObj = PrefabUtility . InstantiatePrefab ( unityMainAsset ) ;
0 commit comments