@@ -14,10 +14,25 @@ public class MixedRealityProfileCloneWindow : EditorWindow
14
14
{
15
15
public enum ProfileCloneBehavior
16
16
{
17
- UseExisting , // Use the existing reference
18
- CloneExisting , // Create a clone of the sub-profile
19
- UseSubstitution , // Manually select a profile
20
- LeaveEmpty , // Set the reference to null
17
+ /// <summary>
18
+ /// Use the existing reference.
19
+ /// </summary>
20
+ UseExisting ,
21
+
22
+ /// <summary>
23
+ /// Create a clone of the sub-profile.
24
+ /// </summary>
25
+ CloneExisting ,
26
+
27
+ /// <summary>
28
+ /// Manually select a profile.
29
+ /// </summary>
30
+ UseSubstitution ,
31
+
32
+ /// <summary>
33
+ /// Set the reference to null.
34
+ /// </summary>
35
+ LeaveEmpty ,
21
36
}
22
37
23
38
private struct SubProfileAction
@@ -70,7 +85,7 @@ public static void OpenWindow(BaseMixedRealityProfile parentProfile, BaseMixedRe
70
85
cloneWindow . Close ( ) ;
71
86
}
72
87
73
- cloneWindow = ( MixedRealityProfileCloneWindow ) GetWindow < MixedRealityProfileCloneWindow > ( true , "Clone Profile" , true ) ;
88
+ cloneWindow = GetWindow < MixedRealityProfileCloneWindow > ( true , "Clone Profile" , true ) ;
74
89
cloneWindow . Initialize ( parentProfile , childProfile , childProperty , selectionTarget ) ;
75
90
cloneWindow . Show ( true ) ;
76
91
}
@@ -125,7 +140,7 @@ private void Initialize(BaseMixedRealityProfile parentProfile, BaseMixedRealityP
125
140
126
141
cloneWindow . maxSize = MinWindowSizeBasic ;
127
142
128
- targetFolder = EnsureTargetFolder ( targetFolder ) ;
143
+ targetFolder = EnsureTargetFolder ( targetFolder , false ) ;
129
144
}
130
145
131
146
private void OnGUI ( )
@@ -195,7 +210,7 @@ private void OnGUI()
195
210
if ( GUILayout . Button ( "Put in original folder" , EditorStyles . miniButton , GUILayout . MaxWidth ( 120 ) ) )
196
211
{
197
212
string profilePath = AssetDatabase . GetAssetPath ( action . Property . objectReferenceValue ) ;
198
- action . TargetFolder = AssetDatabase . LoadAssetAtPath < Object > ( System . IO . Path . GetDirectoryName ( profilePath ) ) ;
213
+ action . TargetFolder = AssetDatabase . LoadAssetAtPath < Object > ( Path . GetDirectoryName ( profilePath ) ) ;
199
214
}
200
215
}
201
216
break ;
@@ -220,10 +235,10 @@ private void OnGUI()
220
235
using ( new EditorGUILayout . HorizontalScope ( ) )
221
236
{
222
237
targetFolder = EditorGUILayout . ObjectField ( "Target Folder" , targetFolder , typeof ( DefaultAsset ) , false ) ;
223
- if ( GUILayout . Button ( "Put in original folder" , EditorStyles . miniButton , GUILayout . MaxWidth ( 120 ) ) )
238
+ if ( GUILayout . Button ( "Put in original folder" , EditorStyles . miniButton , GUILayout . MaxWidth ( 125 ) ) )
224
239
{
225
240
string profilePath = AssetDatabase . GetAssetPath ( childProfile ) ;
226
- targetFolder = AssetDatabase . LoadAssetAtPath < Object > ( System . IO . Path . GetDirectoryName ( profilePath ) ) ;
241
+ targetFolder = AssetDatabase . LoadAssetAtPath < Object > ( Path . GetDirectoryName ( profilePath ) ) ;
227
242
}
228
243
}
229
244
@@ -263,7 +278,7 @@ private void OnGUI()
263
278
264
279
private void CloneMainProfile ( )
265
280
{
266
- var newChildProfile = CloneProfile ( parentProfile , childProfile , childProfileTypeName , childProperty , targetFolder , childProfileAssetName ) ;
281
+ var newChildProfile = CloneProfile ( childProfileTypeName , childProperty , targetFolder , childProfileAssetName ) ;
267
282
SerializedObject newChildSerializedObject = new SerializedObject ( newChildProfile ) ;
268
283
// First paste all values outright
269
284
PasteProfileValues ( parentProfile , childProfile , newChildSerializedObject ) ;
@@ -302,7 +317,7 @@ private void CloneMainProfile()
302
317
303
318
// Clone the sub profile
304
319
Object subTargetFolder = ( action . TargetFolder == null ) ? targetFolder : action . TargetFolder ;
305
- var newSubProfile = CloneProfile ( newChildProfile , subProfileToClone , action . ProfileType . Name , actionProperty , subTargetFolder , action . CloneName ) ;
320
+ var newSubProfile = CloneProfile ( action . ProfileType . Name , actionProperty , subTargetFolder , action . CloneName ) ;
306
321
SerializedObject newSubProfileSerializedObject = new SerializedObject ( newSubProfile ) ;
307
322
// Paste values from existing profile
308
323
PasteProfileValues ( newChildProfile , subProfileToClone , newSubProfileSerializedObject ) ;
@@ -334,7 +349,7 @@ private void CloneMainProfile()
334
349
cloneWindow . Close ( ) ;
335
350
}
336
351
337
- private static BaseMixedRealityProfile CloneProfile ( BaseMixedRealityProfile parentProfile , BaseMixedRealityProfile profileToClone , string childProfileTypeName , SerializedProperty childProperty , Object targetFolder , string profileName )
352
+ private static BaseMixedRealityProfile CloneProfile ( string childProfileTypeName , SerializedProperty childProperty , Object targetFolder , string profileName )
338
353
{
339
354
ScriptableObject instance = CreateInstance ( childProfileTypeName ) ;
340
355
instance . name = string . IsNullOrEmpty ( profileName ) ? childProfileTypeName : profileName ;
@@ -394,21 +409,21 @@ private static System.Type FindProfileType(string profileTypeName)
394
409
/// If the targetFolder is invalid asset folder, this will create the CustomProfiles
395
410
/// folder and use that as the default target.
396
411
/// </summary>
397
- private static Object EnsureTargetFolder ( Object targetFolder )
412
+ private static Object EnsureTargetFolder ( Object targetFolder , bool createDefaultIfNeeded = true )
398
413
{
399
414
if ( targetFolder != null && AssetDatabase . IsValidFolder ( AssetDatabase . GetAssetPath ( targetFolder ) ) )
400
415
{
401
416
return targetFolder ;
402
417
}
403
418
404
419
string customProfilesFolderPath = DefaultCustomProfileFolder ;
405
- if ( ! AssetDatabase . IsValidFolder ( customProfilesFolderPath ) )
420
+ if ( createDefaultIfNeeded && ! AssetDatabase . IsValidFolder ( customProfilesFolderPath ) )
406
421
{
407
422
// AssetDatabase.CreateFolder must be called to create each child of the asset folder
408
- // path individually.
423
+ // path individually.
409
424
410
- // If the packages have been imported via NugetForUnity, MixedRealityToolkitFiles.GetGeneratedFolder
411
- // will also create the MixedRealityToolkit.Generated Folder and return the path to the folder .
425
+ // MixedRealityToolkitFiles.GetGeneratedFolder will create the MixedRealityToolkit.Generated
426
+ // folder if needed .
412
427
AssetDatabase . CreateFolder ( MixedRealityToolkitFiles . GetGeneratedFolder , "CustomProfiles" ) ;
413
428
}
414
429
return AssetDatabase . LoadAssetAtPath ( DefaultCustomProfileFolder , typeof ( Object ) ) ;
0 commit comments