Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arbitrary generated folder location #969

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@
"depth": 0,
"source": "local",
"dependencies": {
"org.mixedrealitytoolkit.core": "3.0.0"
"org.mixedrealitytoolkit.core": "3.3.0"
}
},
"org.mixedrealitytoolkit.uxcomponents": {
Expand Down
9 changes: 6 additions & 3 deletions org.mixedrealitytoolkit.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [3.2.3-development] - 2024-06-24
## Unreleased

### Added

* Added support for moving the MRTK.Generated folder around the project's Assets folder structure instead of enforcing a root location. [PR #969](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/969)

### Fixed

Expand All @@ -29,8 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
* Added IsProximityHovered property of type TimedFlag to detect when a button starts being hovered or on interactor proximity and when it stops being hovered or on proximity of any interactor. [PR #611](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/611)
* Adding ProximityHover events (Entered & Exited) to PressableButton class. [PR #611](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/611)


### Fixed

* Fixed support for UPM package publishing in the Unity Asset Store. [PR #519](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/519)
* Fix warning and event triggered on disabled StatefulInteractable after changing speech settings [PR #591](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/591) [PR #608](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/608)
* Fix warning and event triggered on disabled StatefulInteractable after changing speech settings [PR #591](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/591) [PR #608](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/608)
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static SettingsProvider BuildPreferences()

static void GUIHandler(string searchContext)
{
EditorGUILayout.HelpBox("These settings are serialized into MRTKSettings.asset in the MRTK.Generated folder.\nThis file can be checked into source control to maintain consistent settings across collaborators.", MessageType.Info);
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);
DrawAppLauncherModelField();
}

Expand Down
93 changes: 93 additions & 0 deletions org.mixedrealitytoolkit.core/Editor/MRTKFiles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (c) Mixed Reality Toolkit Contributors
// Licensed under the BSD 3-Clause

using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace MixedReality.Toolkit.Editor
{
/// <summary>
/// Provides helper methods for accessing MRTK-defined files and folders.
/// </summary>
public class MRTKFiles
{
private const string GeneratedName = "MRTK.Generated";
private const string GeneratedSentinelFileName = GeneratedName + ".sentinel";

private static readonly string DefaultGeneratedFolderPath = Path.Combine("Assets", GeneratedName);
private static readonly string DefaultSentinelFilePath = Path.Combine(DefaultGeneratedFolderPath, GeneratedSentinelFileName);
private static string generatedFolderPath = string.Empty;

/// <summary>
/// Finds the current MRTK.Generated folder based on the sentinel file. If a sentinel file is not found,
/// a new MRTK.Generated folder and sentinel are created and this new path is returned.
/// </summary>
/// <returns>The AssetDatabase-compatible path to the MRTK.Generated folder.</returns>
public static string GetOrCreateGeneratedFolderPath()
{
if (string.IsNullOrWhiteSpace(generatedFolderPath))
{
foreach (string guid in AssetDatabase.FindAssets(GeneratedName))
{
string path = AssetDatabase.GUIDToAssetPath(guid);
if (path.Contains(GeneratedSentinelFileName))
{
generatedFolderPath = Path.GetDirectoryName(path);
return generatedFolderPath;
}
}

if (!Directory.Exists(DefaultGeneratedFolderPath))
{
Directory.CreateDirectory(DefaultGeneratedFolderPath);
}

if (!File.Exists(DefaultSentinelFilePath))
{
// Make sure we create and dispose/close the filestream just created
using FileStream f = File.Create(DefaultSentinelFilePath);
}
generatedFolderPath = DefaultGeneratedFolderPath;
}
return generatedFolderPath;
}

/// <summary>
/// Checks for an existing MRTK.Generated sentinel file on asset import. Allows the path to be pre-cached before use.
/// </summary>
private class AssetPostprocessor : UnityEditor.AssetPostprocessor
{
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (string asset in deletedAssets.Concat(movedFromAssetPaths))
{
if (Path.GetFileName(asset) == GeneratedSentinelFileName && Path.GetDirectoryName(asset) == generatedFolderPath)
{
generatedFolderPath = string.Empty;
break;
}
}

foreach (string asset in importedAssets.Concat(movedAssets))
{
if (Path.GetFileName(asset) == GeneratedSentinelFileName)
{
string newPath = Path.GetDirectoryName(asset);
if (generatedFolderPath != newPath)
{
if (generatedFolderPath != string.Empty)
{
Debug.LogWarning($"Previous MRTK.Generated folder was not unregistered properly: {generatedFolderPath}.\nReplacing with {newPath}");
}
Debug.Log($"Found MRTK.Generated sentinel at {newPath}.");
generatedFolderPath = newPath;
}
break;
}
}
}
}
}
}
11 changes: 11 additions & 0 deletions org.mixedrealitytoolkit.core/Editor/MRTKFiles.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions org.mixedrealitytoolkit.core/Editor/MRTKSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace MixedReality.Toolkit.Editor
[System.Serializable]
public class MRTKSettings : ScriptableObject
{
internal const string MRTKGeneratedFolder = "Assets/MRTK.Generated";
internal const string MRTKSettingsPath = MRTKGeneratedFolder + "/MRTKSettings.asset";
internal static string MRTKSettingsPath => Path.Combine(MRTKFiles.GetOrCreateGeneratedFolderPath(), "MRTKSettings.asset");

[SerializeField]
private SerializableDictionary<BuildTargetGroup, MRTKProfile> settings = new SerializableDictionary<BuildTargetGroup, MRTKProfile>();
Expand Down Expand Up @@ -83,11 +82,6 @@ internal static MRTKSettings GetOrCreateSettings()
var settings = AssetDatabase.LoadAssetAtPath<MRTKSettings>(MRTKSettingsPath);
if (settings == null)
{
if (!Directory.Exists(MRTKGeneratedFolder))
{
Directory.CreateDirectory(MRTKGeneratedFolder);
}

settings = CreateInstance<MRTKSettings>();
AssetDatabase.CreateAsset(settings, MRTKSettingsPath);
AssetDatabase.SaveAssets();
Expand Down
2 changes: 1 addition & 1 deletion org.mixedrealitytoolkit.core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "org.mixedrealitytoolkit.core",
"version": "3.2.3-development",
"version": "3.3.0-development",
"description": "A limited collection of common interfaces and utilities that most MRTK packages share. Most implementations of these interfaces are contained in other packages in the MRTK ecosystem.",
"displayName": "MRTK Core Definitions",
"msftFeatureCategory": "MRTK3",
Expand Down
12 changes: 9 additions & 3 deletions org.mixedrealitytoolkit.tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [3.0.4-development] - 2024-08-29
## Unreleased

### Changed

* Updated MRTK Core Definitions dependency to 3.3.0. [PR #969](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/969)

## [3.0.4] - 2024-09-18

### Changed

* Package patch version update to allow UPM publishing

## [3.0.3] - 2024-04-17
## [3.0.3] - 2024-06-12

### Fixed

* Fixing .asmdef for Editor Unit Tests, so it now contains proper `defineConstraints`.

## [3.0.2] - 2024-03-20
## [3.0.2] - 2024-03-27

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the BSD 3-Clause

using Microsoft.CSharp;
using MixedReality.Toolkit.Editor;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -33,7 +34,6 @@ internal class SubsystemGenerator

private const bool DefaultCreateConfiguration = false;
private static readonly string DefaultBaseSubsystemName = $"NewSubsystem";
private static readonly string OutputFolderRoot = Path.Combine("Assets", "MRTK.Generated");

[SerializeField]
private SubsystemWizardState state = SubsystemWizardState.Start;
Expand Down Expand Up @@ -159,7 +159,7 @@ public void Generate(
{
// Make sure there is a folder in which to create the new files.
DirectoryInfo outputFolder = new DirectoryInfo(
Path.Combine(OutputFolderRoot, SubsystemName));
Path.Combine(MRTKFiles.GetOrCreateGeneratedFolderPath(), SubsystemName));
if (!outputFolder.Exists)
{
outputFolder.Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private void RenderWizardPreGeneratePage()
}

EditorGUILayout.LabelField(
$"The new subsystem will be created in your project's MRTK.Generated/{subsystemGenerator.SubsystemName} folder.",
$"The new subsystem will be created in your project's {Path.Combine(MRTKFiles.GetOrCreateGeneratedFolderPath(), subsystemGenerator.SubsystemName)} folder.",
EditorStyles.boldLabel);

EditorGUILayout.Space(6);
Expand Down Expand Up @@ -345,7 +345,7 @@ private void RenderWizardCompletePage()
{
StringBuilder sb = new StringBuilder();
int step = 1;
sb.AppendLine($" {step}. In the Project view, navigate to Assets/MRTK.Generated/{subsystemGenerator.SubsystemName}");
sb.AppendLine($" {step}. In the Project view, navigate to {Path.Combine(MRTKFiles.GetOrCreateGeneratedFolderPath(), subsystemGenerator.SubsystemName)}");
step++;
sb.AppendLine($" {step}. Open {subsystemGenerator.DescriptorName}.cs");
step++;
Expand Down
4 changes: 2 additions & 2 deletions org.mixedrealitytoolkit.tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "org.mixedrealitytoolkit.tools",
"version": "3.0.4-development",
"version": "3.0.5-development",
"description": "A collection of tools, utilities, and wizards that can be used to create and analyze components for use with MRTK3.",
"displayName": "MRTK Tools",
"msftFeatureCategory": "MRTK3",
Expand All @@ -17,6 +17,6 @@
"unityRelease": "26f1",
"documentationUrl": "https://www.mixedrealitytoolkit.org",
"dependencies": {
"org.mixedrealitytoolkit.core": "3.0.0"
"org.mixedrealitytoolkit.core": "3.3.0"
}
}