Skip to content

Commit 18f3dac

Browse files
Magnifer Sample Adjustments (#139)
1 parent 8900877 commit 18f3dac

37 files changed

Lines changed: 1957 additions & 2590 deletions

com.microsoft.mrtk.graphicstools.unity/Samples~/Experimental/Magnifier/Scenes.meta renamed to com.microsoft.mrtk.graphicstools.unity/Editor/Experimental/Magnifier.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#if GT_USE_URP
5+
using UnityEditor;
6+
using UnityEngine;
7+
8+
namespace Microsoft.MixedReality.GraphicsTools.Editor
9+
{
10+
/// <summary>
11+
/// Custom inspector that helps with magnifier configuration.
12+
/// </summary>
13+
[CustomEditor(typeof(MagnifierManager))]
14+
public class MagnifierManagerInspector : UnityEditor.Editor
15+
{
16+
private SerializedProperty m_Script;
17+
private SerializedProperty renderObjectsSettings;
18+
19+
private bool showRenderObjects = false;
20+
21+
private void OnEnable()
22+
{
23+
m_Script = serializedObject.FindProperty(nameof(m_Script));
24+
renderObjectsSettings = serializedObject.FindProperty(nameof(renderObjectsSettings));
25+
}
26+
27+
/// <summary>
28+
/// Renders a custom inspector GUI.
29+
/// </summary>
30+
public override void OnInspectorGUI()
31+
{
32+
using (var check = new EditorGUI.ChangeCheckScope())
33+
{
34+
InspectorUtilities.DrawReadonlyPropertyField(m_Script);
35+
36+
DrawPropertiesExcluding(serializedObject, nameof(m_Script), nameof(renderObjectsSettings));
37+
38+
showRenderObjects = EditorGUILayout.Foldout(showRenderObjects, "Render Objects Settings");
39+
40+
if (showRenderObjects)
41+
{
42+
EditorGUI.indentLevel++;
43+
EditorGUILayout.PropertyField(renderObjectsSettings);
44+
EditorGUI.indentLevel--;
45+
}
46+
47+
if (check.changed)
48+
{
49+
MagnifierManager magnifier = target as MagnifierManager;
50+
51+
if (magnifier != null)
52+
{
53+
magnifier.ApplyMagnification();
54+
}
55+
56+
serializedObject.ApplyModifiedProperties();
57+
}
58+
}
59+
}
60+
}
61+
}
62+
#endif // GT_USE_URP

com.microsoft.mrtk.graphicstools.unity/Editor/Experimental/Magnifier/MagnifierManagerInspector.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.microsoft.mrtk.graphicstools.unity/Editor/Inspectors/BaseMeshOutlineInspector.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private void OnEnable()
108108
/// <inheritdoc />
109109
public override void OnInspectorGUI()
110110
{
111-
DrawReadonlyPropertyField(m_Script);
111+
InspectorUtilities.DrawReadonlyPropertyField(m_Script);
112112

113113
EditorGUI.BeginChangeCheck();
114114

@@ -305,12 +305,5 @@ private static bool IsCorrectMaterial(Material material, MaterialSettings materi
305305

306306
return true;
307307
}
308-
309-
private static void DrawReadonlyPropertyField(SerializedProperty property, params GUILayoutOption[] options)
310-
{
311-
GUI.enabled = false;
312-
EditorGUILayout.PropertyField(property, options);
313-
GUI.enabled = true;
314-
}
315308
}
316309
}

com.microsoft.mrtk.graphicstools.unity/Editor/Inspectors/ClippingPrimitiveInspector.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public override void OnInspectorGUI()
4848

4949
using (var check = new EditorGUI.ChangeCheckScope())
5050
{
51-
DrawReadonlyPropertyField(m_Script);
51+
InspectorUtilities.DrawReadonlyPropertyField(m_Script);
5252

5353
if (HasNoRenderers(previousRenderers))
5454
{
5555
EditorGUILayout.PropertyField(applyToSharedMaterial);
5656
}
5757
else
5858
{
59-
DrawReadonlyPropertyField(applyToSharedMaterial);
59+
InspectorUtilities.DrawReadonlyPropertyField(applyToSharedMaterial);
6060
}
6161

6262
DrawPropertiesExcluding(serializedObject, nameof(m_Script), nameof(applyToSharedMaterial));
@@ -99,13 +99,6 @@ public override void OnInspectorGUI()
9999
}
100100
}
101101

102-
private static void DrawReadonlyPropertyField(SerializedProperty property, params GUILayoutOption[] options)
103-
{
104-
GUI.enabled = false;
105-
EditorGUILayout.PropertyField(property, options);
106-
GUI.enabled = true;
107-
}
108-
109102
private static bool HasNoRenderers(IEnumerable<Renderer> renderers)
110103
{
111104
foreach (var renderer in renderers)

com.microsoft.mrtk.graphicstools.unity/Editor/Utilities/InspectorUtilities.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Microsoft.MixedReality.GraphicsTools.Editor
88
{
99
/// <summary>
10-
/// General utility methods to help with shader inspector development.
10+
/// General utility methods to help with inspector development.
1111
/// </summary>
1212
public static class InspectorUtilities
1313
{
@@ -28,5 +28,15 @@ public static GameObject CreateGameObjectFromMenu<T>(MenuCommand menuCommand) wh
2828

2929
return gameObject;
3030
}
31+
32+
/// <summary>
33+
/// Draws a property that is greyed out and non-interactible.
34+
/// </summary>
35+
public static void DrawReadonlyPropertyField(SerializedProperty property, params GUILayoutOption[] options)
36+
{
37+
GUI.enabled = false;
38+
EditorGUILayout.PropertyField(property, options);
39+
GUI.enabled = true;
40+
}
3141
}
3242
}

com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Materials.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.microsoft.mrtk.graphicstools.unity/Samples~/Experimental/Magnifier/Materials/BlitMaterial.mat renamed to com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Materials/Blit.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Material:
77
m_CorrespondingSourceObject: {fileID: 0}
88
m_PrefabInstance: {fileID: 0}
99
m_PrefabAsset: {fileID: 0}
10-
m_Name: BlitMaterial
10+
m_Name: Blit
1111
m_Shader: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
1212
m_ShaderKeywords:
1313
m_LightmapFlags: 4

com.microsoft.mrtk.graphicstools.unity/Samples~/Experimental/Magnifier/Materials/BlitMaterial.mat.meta renamed to com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Materials/Blit.mat.meta

File renamed without changes.

com.microsoft.mrtk.graphicstools.unity/Samples~/Experimental/Magnifier/Materials/MagnifierMaterial.mat renamed to com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Materials/Magnifier.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Material:
2020
m_CorrespondingSourceObject: {fileID: 0}
2121
m_PrefabInstance: {fileID: 0}
2222
m_PrefabAsset: {fileID: 0}
23-
m_Name: MagnifierMaterial
23+
m_Name: Magnifier
2424
m_Shader: {fileID: 4800000, guid: 708bca655443cdd41b94ee29b5572b6e, type: 3}
2525
m_ShaderKeywords:
2626
m_LightmapFlags: 4

0 commit comments

Comments
 (0)