11// Copyright (c) Mixed Reality Toolkit Contributors
22// Licensed under the BSD 3-Clause
33
4- // Disable "missing XML comment" warning for samples. While nice to have, this XML documentation is not required for samples.
5- #pragma warning disable CS1591
6-
4+ using MixedReality . Toolkit . Input ;
75using System ;
86using System . IO ;
97using System . Linq ;
@@ -18,7 +16,7 @@ namespace MixedReality.Toolkit.Examples.Build
1816 /// </summary>
1917 public static class BuildApp
2018 {
21- private static string [ ] scenes =
19+ private static string [ ] scenes =
2220 {
2321 "Assets/Scenes/BoundsControlExamples.unity" ,
2422 "Assets/Scenes/CanvasExample.unity" ,
@@ -151,6 +149,10 @@ private static void ParseBuildCommandLine()
151149 case "-buildOutput" :
152150 buildPath = arguments [ ++ i ] ;
153151 break ;
152+ case "-debug" :
153+ // Add hand joints to hand visualization for debugging purposes
154+ PatchDebugHands ( ) ;
155+ break ;
154156 }
155157 }
156158 }
@@ -160,6 +162,107 @@ private static string[] SplitSceneList(string sceneList)
160162 return ( from scene in sceneList . Split ( new char [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries )
161163 select scene . Trim ( ) ) . ToArray ( ) ;
162164 }
165+
166+ #region Hand Debug Patching
167+
168+ private const string LeftHandVisualizerGuid = "2b468cc4fe6d2b44ebc53b958b38b91a" ;
169+ private const string RightHandVisualizerGuid = "da93d751ddc0f64468dfc02f18d02d00" ;
170+ private const string HandJointMaterialGuid = "f115122e8379c044faecfec013fda057" ;
171+
172+ [ MenuItem ( "Mixed Reality/MRTK3/Examples/Patch debug hand visualization..." ) ]
173+ private static void PatchDebugHands ( ) => PatchHands ( true ) ;
174+
175+ [ MenuItem ( "Mixed Reality/MRTK3/Examples/Patch debug hand visualization..." , true ) ]
176+ private static bool ValidatePatchDebugHands ( ) => ! AreHandsPatched ( ) ;
177+
178+ [ MenuItem ( "Mixed Reality/MRTK3/Examples/Unpatch debug hand visualization..." ) ]
179+ private static void UnpatchDebugHands ( ) => PatchHands ( false ) ;
180+
181+ [ MenuItem ( "Mixed Reality/MRTK3/Examples/Unpatch debug hand visualization..." , true ) ]
182+ private static bool ValidateUnpatchDebugHands ( ) => AreHandsPatched ( ) ;
183+
184+ /// <summary>
185+ /// Checks both hand prefabs for a <see cref="HandJointVisualizer"/>.
186+ /// </summary>
187+ /// <returns>Whether the left and right hands both have <see cref="HandJointVisualizer"/> scripts.</returns>
188+ private static bool AreHandsPatched ( )
189+ {
190+ bool isPatched = true ;
191+
192+ string rightHandPath = AssetDatabase . GUIDToAssetPath ( RightHandVisualizerGuid ) ;
193+ {
194+ GameObject rightHandVisualizer = PrefabUtility . LoadPrefabContents ( rightHandPath ) ;
195+ if ( rightHandVisualizer != null )
196+ {
197+ isPatched &= rightHandVisualizer . TryGetComponent < HandJointVisualizer > ( out _ ) ;
198+ }
199+ PrefabUtility . UnloadPrefabContents ( rightHandVisualizer ) ;
200+ }
201+
202+ string leftHandPath = AssetDatabase . GUIDToAssetPath ( LeftHandVisualizerGuid ) ;
203+ {
204+ GameObject leftHandVisualizer = PrefabUtility . LoadPrefabContents ( leftHandPath ) ;
205+ if ( leftHandVisualizer != null )
206+ {
207+ isPatched &= leftHandVisualizer . TryGetComponent < HandJointVisualizer > ( out _ ) ;
208+ }
209+ PrefabUtility . UnloadPrefabContents ( leftHandVisualizer ) ;
210+ }
211+
212+ return isPatched ;
213+ }
214+
215+ /// <summary>
216+ /// Updates both the left and right hand prefabs with <see cref="HandJointVisualizer"/> scripts.
217+ /// </summary>
218+ /// <param name="addDebug">If <see langword="true"/>, <see cref="HandJointVisualizer"/> will be added. If <see langword="false"/>, it'll be removed.</param>
219+ private static void PatchHands ( bool addDebug )
220+ {
221+ string rightHandPath = AssetDatabase . GUIDToAssetPath ( RightHandVisualizerGuid ) ;
222+ {
223+ GameObject rightHandVisualizer = PrefabUtility . LoadPrefabContents ( rightHandPath ) ;
224+ if ( rightHandVisualizer != null )
225+ {
226+ if ( addDebug )
227+ {
228+ HandJointVisualizer visualizer = rightHandVisualizer . EnsureComponent < HandJointVisualizer > ( ) ;
229+ visualizer . HandNode = UnityEngine . XR . XRNode . RightHand ;
230+ visualizer . JointMaterial = AssetDatabase . LoadAssetAtPath < Material > ( AssetDatabase . GUIDToAssetPath ( HandJointMaterialGuid ) ) ;
231+ visualizer . JointMesh = Resources . GetBuiltinResource < Mesh > ( "Cube.fbx" ) ;
232+ }
233+ else if ( rightHandVisualizer . TryGetComponent ( out HandJointVisualizer handJointVisualizer ) )
234+ {
235+ UnityEngine . Object . DestroyImmediate ( handJointVisualizer ) ;
236+ }
237+ PrefabUtility . SaveAsPrefabAsset ( rightHandVisualizer , rightHandPath ) ;
238+ }
239+ PrefabUtility . UnloadPrefabContents ( rightHandVisualizer ) ;
240+ }
241+
242+ string leftHandPath = AssetDatabase . GUIDToAssetPath ( LeftHandVisualizerGuid ) ;
243+ {
244+ GameObject leftHandVisualizer = PrefabUtility . LoadPrefabContents ( leftHandPath ) ;
245+ if ( leftHandVisualizer != null )
246+ {
247+ if ( addDebug )
248+ {
249+ HandJointVisualizer visualizer = leftHandVisualizer . EnsureComponent < HandJointVisualizer > ( ) ;
250+ visualizer . HandNode = UnityEngine . XR . XRNode . LeftHand ;
251+ visualizer . JointMaterial = AssetDatabase . LoadAssetAtPath < Material > ( AssetDatabase . GUIDToAssetPath ( HandJointMaterialGuid ) ) ;
252+ visualizer . JointMesh = Resources . GetBuiltinResource < Mesh > ( "Cube.fbx" ) ;
253+ }
254+ #if UNITY_6000_0_OR_NEWER
255+ else
256+ {
257+ PrefabUtility . RemoveUnusedOverrides ( new [ ] { leftHandVisualizer } , UnityEditor . InteractionMode . UserAction ) ;
258+ }
259+ #endif
260+ PrefabUtility . SaveAsPrefabAsset ( leftHandVisualizer , leftHandPath ) ;
261+ }
262+ PrefabUtility . UnloadPrefabContents ( leftHandVisualizer ) ;
263+ }
264+ }
265+
266+ #endregion Hand Debug Patching
163267 }
164268}
165- #pragma warning restore CS1591
0 commit comments