Skip to content

Commit 61f60e5

Browse files
author
David Kline
authored
Merge pull request #7215 from CDiaz-MS/issue_7184
Fix MixedRealityToolkit.Generated folder creation location
2 parents 517876e + 504915a commit 61f60e5

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

Assets/MixedRealityToolkit/Inspectors/Profiles/MixedRealityProfileCloneWindow.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.MixedReality.Toolkit.Utilities.Editor;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.Reflection;
78
using UnityEditor;
89
using UnityEngine;
@@ -24,7 +25,7 @@ private struct SubProfileAction
2425
public SubProfileAction(
2526
ProfileCloneBehavior behavior,
2627
SerializedProperty property,
27-
Object substitutionReference,
28+
Object substitutionReference,
2829
System.Type profileType)
2930
{
3031
Behavior = behavior;
@@ -46,7 +47,7 @@ public SubProfileAction(
4647

4748
private const string AdvancedModeKey = "MRTK_ProfileCloneWindow_AdvancedMode_Key";
4849
private static bool AdvancedMode = false;
49-
private const string DefaultCustomProfileFolder = "Assets/MixedRealityToolkit.Generated/CustomProfiles";
50+
protected static string DefaultCustomProfileFolder => Path.Combine(MixedRealityToolkitFiles.MapModulePath(MixedRealityToolkitModuleType.Generated), "CustomProfiles");
5051
private const string IsCustomProfileProperty = "isCustomProfile";
5152
private static readonly Vector2 MinWindowSizeBasic = new Vector2(500, 180);
5253
private const float SubProfileSizeMultiplier = 95f;
@@ -241,7 +242,7 @@ private void OnGUI()
241242
{
242243
cloneWindow.Close();
243244
}
244-
}
245+
}
245246

246247
// If there are no sub profiles, limit the max so the window isn't spawned too large
247248
if (subProfileActions.Count <= 0 || !AdvancedMode)
@@ -400,14 +401,15 @@ private static Object EnsureTargetFolder(Object targetFolder)
400401
return targetFolder;
401402
}
402403

403-
if (!AssetDatabase.IsValidFolder(DefaultCustomProfileFolder))
404+
string customProfilesFolderPath = DefaultCustomProfileFolder;
405+
if (!AssetDatabase.IsValidFolder(customProfilesFolderPath))
404406
{
405407
// AssetDatabase.CreateFolder must be called to create each child of the asset folder
406408
// path individually.
407-
// Calling AssetDatabase.CreateFolder("Assets", "MixedRealityToolkit.Generated/CustomProfiles")
408-
// generates a folder that looks like "Assets/MixedRealityToolkit.Generated_CustomProfiles".
409-
AssetDatabase.CreateFolder("Assets", "MixedRealityToolkit.Generated");
410-
AssetDatabase.CreateFolder("Assets/MixedRealityToolkit.Generated", "CustomProfiles");
409+
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.
412+
AssetDatabase.CreateFolder(MixedRealityToolkitFiles.GetGeneratedFolder, "CustomProfiles");
411413
}
412414
return AssetDatabase.LoadAssetAtPath(DefaultCustomProfileFolder, typeof(Object));
413415
}

Assets/MixedRealityToolkit/Utilities/Editor/Setup/MixedRealityToolkitFiles.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static void OnPostprocessAllAssets(string[] importedAssets, string[] dele
101101
private static Task searchForFoldersTask = null;
102102
private static CancellationTokenSource searchForFoldersToken;
103103

104-
private static string NormalizeSeparators(string path) =>
104+
private static string NormalizeSeparators(string path) =>
105105
path?.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
106106

107107
private static string FormatSeparatorsForUnity(string path) => path?.Replace('\\', '/');
@@ -350,6 +350,19 @@ public static MixedRealityToolkitModuleType GetModuleFromPackageFolder(string pa
350350
return moduleNameMap.TryGetValue(packageFolder, out moduleType) ? moduleType : MixedRealityToolkitModuleType.None;
351351
}
352352

353+
/// <summary>
354+
/// Creates the MixedRealityToolkit.Generated folder if it does not exist and returns the
355+
/// path to the generated folder.
356+
/// </summary>
357+
public static string GetGeneratedFolder
358+
{
359+
get
360+
{
361+
TryToCreateGeneratedFolder();
362+
return MapModulePath(MixedRealityToolkitModuleType.Generated);
363+
}
364+
}
365+
353366
private static async Task SearchForFoldersAsync(string rootPath)
354367
{
355368
if (searchForFoldersToken != null)
@@ -376,6 +389,9 @@ private static void SearchForFolders(string rootPath, CancellationToken ct)
376389
ct.ThrowIfCancellationRequested();
377390
}
378391
}
392+
393+
// Create the Generated folder, if the user tries to delete the Generated folder it will be created again
394+
TryToCreateGeneratedFolder();
379395
}
380396
catch (OperationCanceledException)
381397
{
@@ -408,20 +424,15 @@ private static void RegisterFolderToModule(string folderPath, MixedRealityToolki
408424
}
409425

410426
modFolders.Add(normalizedFolder);
411-
412-
if (module == MixedRealityToolkitModuleType.Core)
413-
{
414-
TryToCreateGeneratedFolder(folderPath);
415-
}
416427
}
417428

418-
private static void TryToCreateGeneratedFolder(string folderPath)
429+
private static void TryToCreateGeneratedFolder()
419430
{
431+
// Always add the the MixedRealityToolkit.Generated folder to Assets
420432
var generatedDirs = GetDirectories(MixedRealityToolkitModuleType.Generated);
421433
if (generatedDirs == null || !generatedDirs.Any())
422434
{
423-
string parentFolderPath = Directory.GetParent(folderPath).FullName;
424-
string generatedFolderPath = Path.Combine(parentFolderPath, "MixedRealityToolkit.Generated");
435+
string generatedFolderPath = Path.Combine("Assets", "MixedRealityToolkit.Generated");
425436
if (!Directory.Exists(generatedFolderPath))
426437
{
427438
Directory.CreateDirectory(generatedFolderPath);

0 commit comments

Comments
 (0)