Skip to content

Commit f390b2d

Browse files
Ported updated build tools form xrtk
1 parent b2d229d commit f390b2d

26 files changed

+1355
-1286
lines changed

Assets/MixedRealityToolkit/Extensions/ProcessExtensions.cs

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
#if UNITY_EDITOR || !UNITY_WSA
5+
using System;
56
using System.Collections.Generic;
67
using System.Diagnostics;
8+
using System.Threading;
79
using System.Threading.Tasks;
810
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
9-
using Debug = UnityEngine.Debug;
1011

1112
namespace Microsoft.MixedReality.Toolkit.Core.Extensions
1213
{
@@ -22,8 +23,9 @@ public static class ProcessExtensions
2223
/// <param name="fileName">The process executable to run.</param>
2324
/// <param name="args">The Process arguments.</param>
2425
/// <param name="showDebug">Should output debug code to Editor Console?</param>
26+
/// <param name="cancellationToken"></param>
2527
/// <returns><see cref="Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities.ProcessResult"/></returns>
26-
public static async Task<ProcessResult> StartProcessAsync(this Process process, string fileName, string args, bool showDebug = false)
28+
public static async Task<ProcessResult> StartProcessAsync(this Process process, string fileName, string args, bool showDebug = false, CancellationToken cancellationToken = default)
2729
{
2830
return await StartProcessAsync(process, new ProcessStartInfo
2931
{
@@ -33,7 +35,7 @@ public static async Task<ProcessResult> StartProcessAsync(this Process process,
3335
RedirectStandardOutput = true,
3436
RedirectStandardError = true,
3537
Arguments = args
36-
}, showDebug);
38+
}, showDebug, cancellationToken);
3739
}
3840

3941
/// <summary>
@@ -43,8 +45,9 @@ public static async Task<ProcessResult> StartProcessAsync(this Process process,
4345
/// <param name="process">This Process.</param>
4446
/// <param name="startInfo">The Process start info.</param>
4547
/// <param name="showDebug">Should output debug code to Editor Console?</param>
48+
/// <param name="cancellationToken"></param>
4649
/// <returns><see cref="Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities.ProcessResult"/></returns>
47-
public static async Task<ProcessResult> StartProcessAsync(this Process process, ProcessStartInfo startInfo, bool showDebug = false)
50+
public static async Task<ProcessResult> StartProcessAsync(this Process process, ProcessStartInfo startInfo, bool showDebug = false, CancellationToken cancellationToken = default)
4851
{
4952
Debug.Assert(!startInfo.UseShellExecute, "Process Start Info must not use shell execution.");
5053
Debug.Assert(startInfo.RedirectStandardOutput, "Process Start Info must redirect standard output.");
@@ -59,51 +62,91 @@ public static async Task<ProcessResult> StartProcessAsync(this Process process,
5962
var outputCodeResult = new TaskCompletionSource<string[]>();
6063
var outputList = new List<string>();
6164

62-
process.Exited += async (sender, args) =>
65+
process.Exited += OnProcessExited;
66+
process.ErrorDataReceived += OnErrorDataReceived;
67+
process.OutputDataReceived += OnOutputDataReceived;
68+
69+
async void OnProcessExited(object sender, EventArgs args)
6370
{
6471
processResult.TrySetResult(new ProcessResult(process.ExitCode, await errorCodeResult.Task, await outputCodeResult.Task));
6572
process.Close();
6673
process.Dispose();
67-
};
74+
}
6875

69-
process.ErrorDataReceived += (sender, args) =>
76+
void OnErrorDataReceived(object sender, DataReceivedEventArgs args)
7077
{
71-
if (!string.IsNullOrEmpty(args.Data))
78+
if (args.Data != null)
7279
{
7380
errorList.Add(args.Data);
74-
if (showDebug) { Debug.LogError(args.Data); }
81+
82+
if (!showDebug)
83+
{
84+
return;
85+
}
86+
87+
UnityEngine.Debug.LogError(args.Data);
7588
}
7689
else
7790
{
7891
errorCodeResult.TrySetResult(errorList.ToArray());
7992
}
80-
};
93+
}
8194

82-
process.OutputDataReceived += (sender, args) =>
95+
void OnOutputDataReceived(object sender, DataReceivedEventArgs args)
8396
{
84-
if (!string.IsNullOrEmpty(args.Data))
97+
if (args.Data != null)
8598
{
8699
outputList.Add(args.Data);
87-
if (showDebug) { Debug.Log(args.Data); }
100+
101+
if (!showDebug)
102+
{
103+
return;
104+
}
105+
106+
UnityEngine.Debug.Log(args.Data);
88107
}
89108
else
90109
{
91110
outputCodeResult.TrySetResult(outputList.ToArray());
92111
}
93-
};
112+
}
94113

95114
if (!process.Start())
96115
{
97116
if (showDebug)
98117
{
99-
Debug.LogError("Failed to start process!");
118+
UnityEngine.Debug.LogError("Failed to start process!");
100119
}
101120

102121
processResult.TrySetResult(new ProcessResult(process.ExitCode, new[] { "Failed to start process!" }, null));
103122
}
123+
else
124+
{
125+
process.BeginOutputReadLine();
126+
process.BeginErrorReadLine();
127+
CancellationWatcher(process);
128+
}
104129

105-
process.BeginOutputReadLine();
106-
process.BeginErrorReadLine();
130+
async void CancellationWatcher(Process _process)
131+
{
132+
await Task.Run(() =>
133+
{
134+
try
135+
{
136+
while (!_process.HasExited)
137+
{
138+
if (cancellationToken.IsCancellationRequested)
139+
{
140+
_process.Kill();
141+
}
142+
}
143+
}
144+
catch
145+
{
146+
// ignored
147+
}
148+
});
149+
}
107150

108151
return await processResult.Task;
109152
}
Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using System.Collections.Generic;
45
using Microsoft.MixedReality.Toolkit.Core.Utilities.Editor;
56
using UnityEditor;
67
using UnityEngine;
@@ -11,8 +12,8 @@ internal static class MixedRealityPreferences
1112
{
1213
#region Lock Profile Preferences
1314

14-
private static readonly GUIContent LockContent = new GUIContent("Lock SDK Profiles", "Locks the SDK profiles from being edited.\n\nThis setting only applies to the currently running project.");
15-
private const string LockKey = "_LockProfiles";
15+
private static readonly GUIContent LockContent = new GUIContent("Lock SDK profiles", "Locks the SDK profiles from being edited.\n\nThis setting only applies to the currently running project.");
16+
private const string LOCK_KEY = "LockProfiles";
1617
private static bool lockPrefLoaded;
1718
private static bool lockProfiles;
1819

@@ -25,24 +26,21 @@ public static bool LockProfiles
2526
{
2627
if (!lockPrefLoaded)
2728
{
28-
lockProfiles = EditorPrefsUtility.GetEditorPref(LockKey, true);
29+
lockProfiles = EditorPreferences.Get(LOCK_KEY, true);
2930
lockPrefLoaded = true;
3031
}
3132

3233
return lockProfiles;
3334
}
34-
set
35-
{
36-
EditorPrefsUtility.SetEditorPref(LockKey, lockProfiles = value);
37-
}
35+
set => EditorPreferences.Set(LOCK_KEY, lockProfiles = value);
3836
}
3937

4038
#endregion Lock Profile Preferences
4139

4240
#region Ignore startup settings prompt
4341

44-
private static readonly GUIContent IgnoreContent = new GUIContent("Ignore Settings Prompt on Startup", "Prevents settings dialog pop-up from showing on startup.\n\nThis setting applies to all projects using MRTK.");
45-
private const string IgnoreKey = "_MixedRealityToolkit_Editor_IgnoreSettingsPrompts";
42+
private static readonly GUIContent IgnoreContent = new GUIContent("Ignore settings prompt on startup", "Prevents settings dialog popup from showing on startup.\n\nThis setting applies to all projects using MRTK.");
43+
private const string IGNORE_KEY = "MixedRealityToolkit_Editor_IgnoreSettingsPrompts";
4644
private static bool ignorePrefLoaded;
4745
private static bool ignoreSettingsPrompt;
4846

@@ -55,24 +53,21 @@ public static bool IgnoreSettingsPrompt
5553
{
5654
if (!ignorePrefLoaded)
5755
{
58-
ignoreSettingsPrompt = EditorPrefs.GetBool(IgnoreKey, false);
56+
ignoreSettingsPrompt = EditorPrefs.GetBool(IGNORE_KEY, false);
5957
ignorePrefLoaded = true;
6058
}
6159

6260
return ignoreSettingsPrompt;
6361
}
64-
set
65-
{
66-
EditorPrefs.SetBool(IgnoreKey, ignoreSettingsPrompt = value);
67-
}
62+
set => EditorPrefs.SetBool(IGNORE_KEY, ignoreSettingsPrompt = value);
6863
}
6964

7065
#endregion Ignore startup settings prompt
7166

7267
#region Show Canvas Utility Prompt
7368

74-
private static readonly GUIContent CanvasUtilityContent = new GUIContent("Canvas World Space utility dialogs", "Enable or disable the dialog pop-ups for the world space canvas settings.\n\nThis setting only applies to the currently running project.");
75-
private const string CanvasKey = "_EnableCanvasUtilityDialog";
69+
private static readonly GUIContent CanvasUtilityContent = new GUIContent("Canvas world space utility dialogs", "Enable or disable the dialog popups for the world space canvas settings.\n\nThis setting only applies to the currently running project.");
70+
private const string CANVAS_KEY = "EnableCanvasUtilityDialog";
7671
private static bool isCanvasUtilityPrefLoaded;
7772
private static bool showCanvasUtilityPrompt;
7873

@@ -85,58 +80,82 @@ public static bool ShowCanvasUtilityPrompt
8580
{
8681
if (!isCanvasUtilityPrefLoaded)
8782
{
88-
showCanvasUtilityPrompt = EditorPrefsUtility.GetEditorPref("_EnableCanvasUtilityDialog", true);
83+
showCanvasUtilityPrompt = EditorPreferences.Get(CANVAS_KEY, true);
8984
isCanvasUtilityPrefLoaded = true;
9085
}
9186

9287
return showCanvasUtilityPrompt;
9388
}
94-
set
95-
{
96-
EditorPrefsUtility.SetEditorPref(CanvasKey, showCanvasUtilityPrompt = value);
97-
}
89+
set => EditorPreferences.Set(CANVAS_KEY, showCanvasUtilityPrompt = value);
9890
}
9991

10092
#endregion Show Canvas Utility Prompt
10193

102-
[PreferenceItem("Mixed Reality Toolkit")]
103-
private static void Preferences()
94+
[SettingsProvider]
95+
private static SettingsProvider Preferences()
10496
{
105-
EditorGUI.BeginChangeCheck();
106-
lockProfiles = EditorGUILayout.Toggle(LockContent, LockProfiles);
107-
108-
// Save the preference
109-
if (EditorGUI.EndChangeCheck())
97+
var provider = new SettingsProvider("Project/MRTK")
11098
{
111-
LockProfiles = lockProfiles;
112-
}
99+
label = "MRTK",
113100

114-
if (!LockProfiles)
115-
{
116-
EditorGUILayout.HelpBox("This is only to be used to update the default SDK profiles. If any edits are made, and not checked into the MRTK's GitHub, the changes may be lost next time you update your local copy.", MessageType.Warning);
117-
}
101+
guiHandler = GUIHandler,
118102

119-
EditorGUI.BeginChangeCheck();
120-
ignoreSettingsPrompt = EditorGUILayout.Toggle(IgnoreContent, IgnoreSettingsPrompt);
103+
keywords = new HashSet<string>(new[] { "Mixed", "Reality", "Toolkit" })
104+
};
121105

122-
// Save the preference
123-
if (EditorGUI.EndChangeCheck())
106+
void GUIHandler(string searchContext)
124107
{
125-
IgnoreSettingsPrompt = ignoreSettingsPrompt;
126-
}
108+
var prevLabelWidth = EditorGUIUtility.labelWidth;
109+
EditorGUIUtility.labelWidth = 200f;
127110

128-
EditorGUI.BeginChangeCheck();
129-
showCanvasUtilityPrompt = EditorGUILayout.Toggle(CanvasUtilityContent, ShowCanvasUtilityPrompt);
111+
EditorGUI.BeginChangeCheck();
112+
lockProfiles = EditorGUILayout.Toggle(LockContent, LockProfiles);
130113

131-
if (EditorGUI.EndChangeCheck())
132-
{
133-
ShowCanvasUtilityPrompt = showCanvasUtilityPrompt;
134-
}
114+
// Save the preference
115+
if (EditorGUI.EndChangeCheck())
116+
{
117+
LockProfiles = lockProfiles;
118+
}
135119

136-
if (!ShowCanvasUtilityPrompt)
137-
{
138-
EditorGUILayout.HelpBox("Be aware that if a Canvas needs to receive input events it is required to have the CanvasUtility attached or the Focus Provider's UIRaycast Camera assigned to the canvas' camera reference.", MessageType.Warning);
120+
if (!LockProfiles)
121+
{
122+
EditorGUILayout.HelpBox("This is only to be used to update the default SDK profiles. If any edits are made, and not checked into the MRTK's Github, the changes may be lost next time you update your local copy.", MessageType.Warning);
123+
}
124+
125+
EditorGUI.BeginChangeCheck();
126+
ignoreSettingsPrompt = EditorGUILayout.Toggle(IgnoreContent, IgnoreSettingsPrompt);
127+
128+
// Save the preference
129+
if (EditorGUI.EndChangeCheck())
130+
{
131+
IgnoreSettingsPrompt = ignoreSettingsPrompt;
132+
}
133+
134+
EditorGUI.BeginChangeCheck();
135+
showCanvasUtilityPrompt = EditorGUILayout.Toggle(CanvasUtilityContent, ShowCanvasUtilityPrompt);
136+
137+
if (EditorGUI.EndChangeCheck())
138+
{
139+
ShowCanvasUtilityPrompt = showCanvasUtilityPrompt;
140+
}
141+
142+
if (!ShowCanvasUtilityPrompt)
143+
{
144+
EditorGUILayout.HelpBox("Be aware that if a Canvas needs to receive input events it is required to have the CanvasUtility attached or the Focus Provider's UIRaycast Camera assigned to the canvas' camera reference.", MessageType.Warning);
145+
}
146+
147+
EditorGUI.BeginChangeCheck();
148+
var scriptLock = EditorGUILayout.Toggle("Is Script Reloading locked?", EditorAssemblyReloadManager.LockReloadAssemblies);
149+
150+
if (EditorGUI.EndChangeCheck())
151+
{
152+
EditorAssemblyReloadManager.LockReloadAssemblies = scriptLock;
153+
}
154+
155+
EditorGUIUtility.labelWidth = prevLabelWidth;
139156
}
157+
158+
return provider;
140159
}
141160
}
142161
}

0 commit comments

Comments
 (0)