Skip to content

Commit 44f9aee

Browse files
committed
Property to method and docs
1 parent 7f5e800 commit 44f9aee

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

org.mixedrealitytoolkit.core/Editor/MRTKBuildPreferences.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private static SettingsProvider BuildPreferences()
5151

5252
static void GUIHandler(string searchContext)
5353
{
54-
EditorGUILayout.HelpBox($"These settings are serialized into MRTKSettings.asset in {MRTKFiles.GeneratedFolderPath}.\nThis file can be checked into source control to maintain consistent settings across collaborators.", MessageType.Info);
54+
EditorGUILayout.HelpBox($"These settings are serialized into MRTKSettings.asset in {MRTKFiles.GetOrCreateGeneratedFolderPath()}.\nThis file can be checked into source control to maintain consistent settings across collaborators.", MessageType.Info);
5555
DrawAppLauncherModelField();
5656
}
5757

org.mixedrealitytoolkit.core/Editor/MRTKFiles.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace MixedReality.Toolkit.Editor
1010
{
11+
/// <summary>
12+
/// Provides helper methods for accessing MRTK-defined files and folders.
13+
/// </summary>
1114
public class MRTKFiles
1215
{
1316
private const string GeneratedName = "MRTK.Generated";
@@ -17,38 +20,43 @@ public class MRTKFiles
1720
private static readonly string DefaultSentinelFilePath = Path.Combine(DefaultGeneratedFolderPath, GeneratedSentinelFileName);
1821
private static string generatedFolderPath = string.Empty;
1922

20-
public static string GeneratedFolderPath
23+
/// <summary>
24+
/// Finds the current MRTK.Generated folder based on the sentinel file. If a sentinel file is not found,
25+
/// a new MRTK.Generated folder and sentinel are created and this new path is returned.
26+
/// </summary>
27+
/// <returns>The AssetDatabase-compatible path to the MRTK.Generated folder.</returns>
28+
public static string GetOrCreateGeneratedFolderPath()
2129
{
22-
get
30+
if (string.IsNullOrWhiteSpace(generatedFolderPath))
2331
{
24-
if (string.IsNullOrWhiteSpace(generatedFolderPath))
32+
foreach (string guid in AssetDatabase.FindAssets(GeneratedName))
2533
{
26-
foreach (string guid in AssetDatabase.FindAssets(GeneratedName))
34+
string path = AssetDatabase.GUIDToAssetPath(guid);
35+
if (path.Contains(GeneratedSentinelFileName))
2736
{
28-
string path = AssetDatabase.GUIDToAssetPath(guid);
29-
if (path.Contains(GeneratedSentinelFileName))
30-
{
31-
generatedFolderPath = Path.GetDirectoryName(path);
32-
return generatedFolderPath;
33-
}
37+
generatedFolderPath = Path.GetDirectoryName(path);
38+
return generatedFolderPath;
3439
}
40+
}
3541

36-
if (!Directory.Exists(DefaultGeneratedFolderPath))
37-
{
38-
Directory.CreateDirectory(DefaultGeneratedFolderPath);
39-
}
42+
if (!Directory.Exists(DefaultGeneratedFolderPath))
43+
{
44+
Directory.CreateDirectory(DefaultGeneratedFolderPath);
45+
}
4046

41-
if (!File.Exists(DefaultSentinelFilePath))
42-
{
43-
// Make sure we create and dispose/close the filestream just created
44-
using FileStream f = File.Create(DefaultSentinelFilePath);
45-
}
46-
generatedFolderPath = DefaultGeneratedFolderPath;
47+
if (!File.Exists(DefaultSentinelFilePath))
48+
{
49+
// Make sure we create and dispose/close the filestream just created
50+
using FileStream f = File.Create(DefaultSentinelFilePath);
4751
}
48-
return generatedFolderPath;
52+
generatedFolderPath = DefaultGeneratedFolderPath;
4953
}
54+
return generatedFolderPath;
5055
}
5156

57+
/// <summary>
58+
/// Checks for an existing MRTK.Generated sentinel file on asset import. Allows the path to be pre-cached before use.
59+
/// </summary>
5260
private class AssetPostprocessor : UnityEditor.AssetPostprocessor
5361
{
5462
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)

org.mixedrealitytoolkit.core/Editor/MRTKSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace MixedReality.Toolkit.Editor
1414
[System.Serializable]
1515
public class MRTKSettings : ScriptableObject
1616
{
17-
internal static string MRTKSettingsPath => Path.Combine(MRTKFiles.GeneratedFolderPath, "MRTKSettings.asset");
17+
internal static string MRTKSettingsPath => Path.Combine(MRTKFiles.GetOrCreateGeneratedFolderPath(), "MRTKSettings.asset");
1818

1919
[SerializeField]
2020
private SerializableDictionary<BuildTargetGroup, MRTKProfile> settings = new SerializableDictionary<BuildTargetGroup, MRTKProfile>();

org.mixedrealitytoolkit.tools/SubsystemWizard/SubsystemGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void Generate(
159159
{
160160
// Make sure there is a folder in which to create the new files.
161161
DirectoryInfo outputFolder = new DirectoryInfo(
162-
Path.Combine(MRTKFiles.GeneratedFolderPath, SubsystemName));
162+
Path.Combine(MRTKFiles.GetOrCreateGeneratedFolderPath(), SubsystemName));
163163
if (!outputFolder.Exists)
164164
{
165165
outputFolder.Create();

org.mixedrealitytoolkit.tools/SubsystemWizard/SubsystemWizardWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private void RenderWizardPreGeneratePage()
247247
}
248248

249249
EditorGUILayout.LabelField(
250-
$"The new subsystem will be created in your project's {Path.Combine(MRTKFiles.GeneratedFolderPath, subsystemGenerator.SubsystemName)} folder.",
250+
$"The new subsystem will be created in your project's {Path.Combine(MRTKFiles.GetOrCreateGeneratedFolderPath(), subsystemGenerator.SubsystemName)} folder.",
251251
EditorStyles.boldLabel);
252252

253253
EditorGUILayout.Space(6);
@@ -345,7 +345,7 @@ private void RenderWizardCompletePage()
345345
{
346346
StringBuilder sb = new StringBuilder();
347347
int step = 1;
348-
sb.AppendLine($" {step}. In the Project view, navigate to {Path.Combine(MRTKFiles.GeneratedFolderPath, subsystemGenerator.SubsystemName)}");
348+
sb.AppendLine($" {step}. In the Project view, navigate to {Path.Combine(MRTKFiles.GetOrCreateGeneratedFolderPath(), subsystemGenerator.SubsystemName)}");
349349
step++;
350350
sb.AppendLine($" {step}. Open {subsystemGenerator.DescriptorName}.cs");
351351
step++;

0 commit comments

Comments
 (0)