Skip to content

Commit 8758b9b

Browse files
committed
Fixes MixedRealityControllerAttribute to work on the .NET scripting backend
Types.GetCustomAttributes() doesn't exist on .NET UWP, so we have to use some indirection to get attributes instead.
1 parent 6b7fb91 commit 8758b9b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Assets/MixedRealityToolkit/Attributes/MixedRealityControllerAttribute.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
66
using System;
77
using System.Linq;
8+
using System.Reflection;
89

910
#if WINDOWS_UWP && !ENABLE_IL2CPP
1011
using Microsoft.MixedReality.Toolkit.Core.Extensions;
@@ -60,9 +61,18 @@ public MixedRealityControllerAttribute(
6061
/// <summary>
6162
/// Convenience function for retrieving the attribute given a certain class type.
6263
/// </summary>
64+
/// <remarks>
65+
/// This function is only available in a UnityEditor context.
66+
/// </remarks>
6367
public static MixedRealityControllerAttribute Find(Type type)
6468
{
69+
#if WINDOWS_UWP && !ENABLE_IL2CPP
70+
// Type.GetCustomAttributes() doesn't exist on UWP .NET, so we have to indirectly use
71+
// the TypeInfo instead.
72+
return type.GetTypeInfo().GetCustomAttributes(typeof(MixedRealityControllerAttribute), true).FirstOrDefault() as MixedRealityControllerAttribute;
73+
#else
6574
return type.GetCustomAttributes(typeof(MixedRealityControllerAttribute), true).FirstOrDefault() as MixedRealityControllerAttribute;
75+
#endif
6676
}
6777
}
6878
}

0 commit comments

Comments
 (0)