@@ -18,7 +18,7 @@ namespace Editor
18
18
{
19
19
public static class ConvertToModel
20
20
{
21
- const string MenuItemName1 = "GameObject/Convert To Prefab" ;
21
+ const string MenuItemName1 = "GameObject/Convert To Linked Prefab Instance " ;
22
22
23
23
/// <summary>
24
24
/// OnContextItem is called either:
@@ -62,6 +62,23 @@ public static bool OnValidateMenuItem ()
62
62
return true ;
63
63
}
64
64
65
+ /// <summary>
66
+ /// After a convert-to-model, we normally delete the original object.
67
+ /// That can be overridden.
68
+ /// </summary>
69
+ public enum KeepOriginal {
70
+ Default , // Use the export settings.
71
+ Keep , // Don't delete, just rename it.
72
+ Delete , // Delete the original hierarchy.
73
+ }
74
+
75
+ /// <summary>
76
+ /// Gets the export settings.
77
+ /// </summary>
78
+ public static EditorTools . ExportSettings ExportSettings {
79
+ get { return EditorTools . ExportSettings . instance ; }
80
+ }
81
+
65
82
/// <summary>
66
83
/// Create instantiated model prefabs from a selection of objects.
67
84
///
@@ -73,7 +90,10 @@ public static bool OnValidateMenuItem ()
73
90
/// <param name="unityGameObjectsToConvert">Unity game objects to convert to Model Prefab instances</param>
74
91
/// <param name="path">Path to save Model Prefab; use FbxExportSettings if null</param>
75
92
/// <param name="keepOriginal">If set to <c>true</c> keep original gameobject hierarchy.</param>
76
- public static GameObject [ ] CreateInstantiatedModelPrefab ( GameObject [ ] unityGameObjectsToConvert , string directoryFullPath = null , bool keepOriginal = true )
93
+ public static GameObject [ ] CreateInstantiatedModelPrefab (
94
+ GameObject [ ] unityGameObjectsToConvert ,
95
+ string directoryFullPath = null ,
96
+ KeepOriginal keepOriginal = KeepOriginal . Default )
77
97
{
78
98
if ( directoryFullPath == null ) {
79
99
directoryFullPath = FbxExporters . EditorTools . ExportSettings . GetAbsoluteSavePath ( ) ;
@@ -119,7 +139,7 @@ public static GameObject Convert (
119
139
GameObject toConvert ,
120
140
string directoryFullPath = null ,
121
141
string fbxFullPath = null ,
122
- bool keepOriginal = true )
142
+ KeepOriginal keepOriginal = KeepOriginal . Default )
123
143
{
124
144
if ( string . IsNullOrEmpty ( fbxFullPath ) ) {
125
145
// Generate a unique filename.
@@ -197,7 +217,20 @@ public static GameObject Convert (
197
217
unityGO = PrefabUtility . ConnectGameObjectToPrefab ( unityGO , prefab ) ;
198
218
199
219
// Remove (now redundant) gameobject
200
- if ( ! keepOriginal ) {
220
+ bool actuallyKeepOriginal ;
221
+ switch ( keepOriginal ) {
222
+ case KeepOriginal . Delete :
223
+ actuallyKeepOriginal = false ;
224
+ break ;
225
+ case KeepOriginal . Keep :
226
+ actuallyKeepOriginal = true ;
227
+ break ;
228
+ case KeepOriginal . Default :
229
+ default :
230
+ actuallyKeepOriginal = ExportSettings . keepOriginalAfterConvert ;
231
+ break ;
232
+ }
233
+ if ( ! actuallyKeepOriginal ) {
201
234
Object . DestroyImmediate ( toConvert ) ;
202
235
} else {
203
236
// rename and put under scene root in case we need to check values
@@ -218,6 +251,7 @@ public static string IncrementFileName(string path, string filename)
218
251
{
219
252
string fileWithoutExt = Path . GetFileNameWithoutExtension ( filename ) ;
220
253
string ext = Path . GetExtension ( filename ) ;
254
+ // file, space, number, extension.
221
255
string format = "{0} {1}{2}" ;
222
256
223
257
int index = 1 ;
@@ -226,10 +260,15 @@ public static string IncrementFileName(string path, string filename)
226
260
var result = System . Text . RegularExpressions . Regex . Match ( fileWithoutExt , @"\d+$" ) ;
227
261
if ( result != null ) {
228
262
var number = result . Value ;
263
+
264
+ // Parse the number.
229
265
int tempIndex ;
230
266
if ( int . TryParse ( number , out tempIndex ) ) {
231
267
fileWithoutExt = fileWithoutExt . Remove ( fileWithoutExt . LastIndexOf ( number ) ) ;
232
- format = "{0}{1}{2}" ; // remove space from format
268
+ // Change the format to remove the extra space we'd add
269
+ // if there weren't already a number. Also, try to use the
270
+ // same width (so Cube001 increments to Cube002, not Cube2).
271
+ format = "{0}{1:D" + number . Length + "}{2}" ; // file, number with padding, extension
233
272
index = tempIndex + 1 ;
234
273
}
235
274
}
@@ -350,6 +389,15 @@ private static void CopyComponentsRecursive(GameObject from, GameObject to, bool
350
389
public static void CopyComponents ( GameObject from , GameObject to ) {
351
390
var originalComponents = new List < Component > ( to . GetComponents < Component > ( ) ) ;
352
391
foreach ( var component in from . GetComponents < Component > ( ) ) {
392
+ // UNI-24379: we don't support SkinnedMeshRenderer right
393
+ // now: we just bake the mesh into its current pose. So
394
+ // don't copy the SMR over. There will already be a
395
+ // MeshFilter and MeshRenderer due to the static mesh.
396
+ // Remove this code when we support skinning.
397
+ if ( component is SkinnedMeshRenderer ) {
398
+ continue ;
399
+ }
400
+
353
401
var json = EditorJsonUtility . ToJson ( component ) ;
354
402
355
403
System . Type expectedType = component . GetType ( ) ;
0 commit comments