Skip to content

Commit 580c7a8

Browse files
authored
Merge pull request #3630 from wiwei/mrtk_development
Enable .NET backend scripting support
2 parents d8f41fb + 3a7fb87 commit 580c7a8

File tree

55 files changed

+518
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+518
-155
lines changed

Assets/MixedRealityToolkit.Examples/Demos/UX/Interactables/Scenes/InteractablesGallery.unity

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ Prefab:
317317
propertyPath: Events.Array.data[0].ClassName
318318
value: InteractableAudioReceiver
319319
objectReference: {fileID: 0}
320+
- target: {fileID: 114718788154663760, guid: 51cc6641d88b49d46bd38572540efe6c,
321+
type: 2}
322+
propertyPath: Events.Array.data[0].AssemblyQualifiedName
323+
value: Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.Events.InteractableAudioReceiver,
324+
Microsoft.MixedReality.Toolkit.SDK
325+
objectReference: {fileID: 0}
320326
- target: {fileID: 114718788154663760, guid: 51cc6641d88b49d46bd38572540efe6c,
321327
type: 2}
322328
propertyPath: Events.Array.data[0].HideUnityEvents
@@ -504,6 +510,8 @@ MonoBehaviour:
504510
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
505511
Culture=neutral, PublicKeyToken=null
506512
ClassName: CustomInteractablesReceiver
513+
AssemblyQualifiedName: Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.Events.CustomInteractablesReceiver,
514+
MixedRealityToolkit-Examples.Demos.UX.Interactables
507515
Settings: []
508516
HideUnityEvents: 1
509517
--- !u!4 &519184499 stripped
@@ -1154,6 +1162,12 @@ Prefab:
11541162
propertyPath: Events.Array.data[0].ClassName
11551163
value: InteractableOnFocusReceiver
11561164
objectReference: {fileID: 0}
1165+
- target: {fileID: 114818926546564510, guid: 02c524b22137b5449904f5395141cc73,
1166+
type: 2}
1167+
propertyPath: Events.Array.data[0].AssemblyQualifiedName
1168+
value: Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.Events.InteractableOnFocusReceiver,
1169+
Microsoft.MixedReality.Toolkit.SDK
1170+
objectReference: {fileID: 0}
11571171
- target: {fileID: 114818926546564510, guid: 02c524b22137b5449904f5395141cc73,
11581172
type: 2}
11591173
propertyPath: Events.Array.data[0].HideUnityEvents
@@ -1855,6 +1869,8 @@ MonoBehaviour:
18551869
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
18561870
Culture=neutral, PublicKeyToken=null
18571871
ClassName: CustomInteractablesReceiver
1872+
AssemblyQualifiedName: Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.Events.CustomInteractablesReceiver,
1873+
MixedRealityToolkit-Examples.Demos.UX.Interactables
18581874
Settings: []
18591875
HideUnityEvents: 1
18601876
--- !u!4 &1441615695 stripped

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Events/InteractableEvent.cs

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

44
using Microsoft.MixedReality.Toolkit.Core.Utilities.InspectorFields;
5+
using Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.TypeResolution;
56
using System;
67
using System.Collections;
78
using System.Collections.Generic;
@@ -22,23 +23,24 @@ public class InteractableEvent
2223
public string Name;
2324
public UnityEvent Event;
2425
public string ClassName;
26+
public string AssemblyQualifiedName;
2527
public ReceiverBase Receiver;
2628
public List<InspectorPropertySetting> Settings;
2729
public bool HideUnityEvents;
2830

29-
public struct EventLists
30-
{
31-
public List<Type> EventTypes;
32-
public List<String> EventNames;
33-
}
34-
3531
public struct ReceiverData
3632
{
3733
public string Name;
3834
public bool HideUnityEvents;
3935
public List<InspectorFieldData> Fields;
4036
}
41-
37+
38+
/// <summary>
39+
/// The list of base classes whose derived classes will be included in interactable event
40+
/// selection dropdowns.
41+
/// </summary>
42+
private static readonly List<Type> candidateEventTypes = new List<Type>() { typeof(ReceiverBase) };
43+
4244
public ReceiverData AddOnClick()
4345
{
4446
return AddReceiver(typeof(InteractableOnClickReceiver));
@@ -95,41 +97,24 @@ public ReceiverData AddReceiver(Type type)
9597
/// Get the recieverBase types that contain event logic
9698
/// </summary>
9799
/// <returns></returns>
98-
public static EventLists GetEventTypes()
100+
public static InteractableTypesContainer GetEventTypes()
99101
{
100-
List<Type> eventTypes = new List<Type>();
101-
List<string> names = new List<string>();
102-
103-
var assemblys = AppDomain.CurrentDomain.GetAssemblies();
104-
foreach (var assembly in assemblys)
105-
{
106-
foreach (Type type in assembly.GetTypes())
107-
{
108-
TypeInfo info = type.GetTypeInfo();
109-
if (info.BaseType != null && info.BaseType.Equals(typeof(ReceiverBase)))
110-
{
111-
eventTypes.Add(type);
112-
names.Add(type.Name);
113-
}
114-
}
115-
}
116-
117-
EventLists lists = new EventLists();
118-
lists.EventTypes = eventTypes;
119-
lists.EventNames = names;
120-
return lists;
102+
return InteractableTypeFinder.Find(candidateEventTypes, TypeRestriction.DerivedOnly);
121103
}
122104

123105
/// <summary>
124106
/// Create the event and setup the values from the inspector
125107
/// </summary>
126108
/// <param name="iEvent"></param>
127-
/// <param name="lists"></param>
128109
/// <returns></returns>
129-
public static ReceiverBase GetReceiver(InteractableEvent iEvent, EventLists lists)
110+
public static ReceiverBase GetReceiver(InteractableEvent iEvent, InteractableTypesContainer interactableTypes)
130111
{
131-
int index = InspectorField.ReverseLookup(iEvent.ClassName, lists.EventNames.ToArray());
132-
Type eventType = lists.EventTypes[index];
112+
#if UNITY_EDITOR
113+
int index = InspectorField.ReverseLookup(iEvent.ClassName, interactableTypes.ClassNames);
114+
Type eventType = interactableTypes.Types[index];
115+
#else
116+
Type eventType = Type.GetType(iEvent.AssemblyQualifiedName);
117+
#endif
133118
// apply the settings?
134119
ReceiverBase newEvent = (ReceiverBase)Activator.CreateInstance(eventType, iEvent.Event);
135120
InspectorGenericFields<ReceiverBase>.LoadSettings(newEvent, iEvent.Settings);

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Events/InteractableReceiver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ protected virtual void SetupEvents()
3030
{
3131
if (Events.Count > 0)
3232
{
33-
InteractableEvent.EventLists lists = InteractableEvent.GetEventTypes();
34-
Events[0].Receiver = InteractableEvent.GetReceiver(Events[0], lists);
33+
InteractableTypesContainer interactableTypes = InteractableEvent.GetEventTypes();
34+
Events[0].Receiver = InteractableEvent.GetReceiver(Events[0], interactableTypes);
3535
Events[0].Receiver.Host = this;
3636
}
3737
}

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Events/InteractableReceiverList.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ protected virtual void Awake()
2929
/// </summary>
3030
protected virtual void SetupEvents()
3131
{
32-
InteractableEvent.EventLists lists = InteractableEvent.GetEventTypes();
32+
InteractableTypesContainer interactableTypes = InteractableEvent.GetEventTypes();
3333

3434
for (int i = 0; i < Events.Count; i++)
3535
{
36-
Events[i].Receiver = InteractableEvent.GetReceiver(Events[i], lists);
36+
Events[i].Receiver = InteractableEvent.GetReceiver(Events[i], interactableTypes);
3737
Events[i].Receiver.Host = this;
3838
}
3939
}

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Interactable.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,12 @@ protected virtual void SetupStates()
291291
/// </summary>
292292
protected virtual void SetupEvents()
293293
{
294-
InteractableEvent.EventLists lists = InteractableEvent.GetEventTypes();
294+
InteractableTypesContainer interactableTypes = InteractableEvent.GetEventTypes();
295295

296296
for (int i = 0; i < Events.Count; i++)
297297
{
298-
Events[i].Receiver = InteractableEvent.GetReceiver(Events[i], lists);
298+
Events[i].Receiver = InteractableEvent.GetReceiver(Events[i], interactableTypes);
299299
Events[i].Receiver.Host = this;
300-
//Events[i].Settings = InteractableEvent.GetSettings(Events[i].Receiver);
301-
// apply settings
302300
}
303301
}
304302

@@ -307,7 +305,6 @@ protected virtual void SetupEvents()
307305
/// </summary>
308306
protected virtual void SetupThemes()
309307
{
310-
InteractableProfileItem.ThemeLists lists = InteractableProfileItem.GetThemeTypes();
311308
runningThemesList = new List<InteractableThemeBase>();
312309
runningProfileSettings = new List<ProfileSettings>();
313310
for (int i = 0; i < Profiles.Count; i++)
@@ -325,8 +322,7 @@ protected virtual void SetupThemes()
325322
{
326323
InteractableThemePropertySettings settings = theme.Settings[n];
327324

328-
settings.Theme = InteractableProfileItem.GetTheme(settings, Profiles[i].Target, lists);
329-
325+
settings.Theme = InteractableProfileItem.GetTheme(settings, Profiles[i].Target);
330326
// add themes to theme list based on dimension
331327
if (j == dimensionIndex)
332328
{

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Profile/InteractableProfileItem.cs

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.MixedReality.Toolkit.Core.Utilities.InspectorFields;
55
using Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.Themes;
6+
using Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.TypeResolution;
67
using System;
78
using System.Collections;
89
using System.Collections.Generic;
@@ -19,44 +20,28 @@ namespace Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.Profile
1920
[System.Serializable]
2021
public class InteractableProfileItem
2122
{
22-
[System.Serializable]
23-
public struct ThemeLists
24-
{
25-
public List<Type> Types;
26-
public List<String> Names;
27-
}
28-
2923
public GameObject Target;
3024
public List<Theme> Themes;
3125
public bool HadDefaultTheme;
26+
27+
/// <summary>
28+
/// The list of base classes whose derived classes will be included in interactable theme
29+
/// selection dropdowns.
30+
/// </summary>
31+
private static readonly List<Type> candidateThemeTypes = new List<Type>()
32+
{
33+
typeof(InteractableThemeBase),
34+
typeof(InteractableShaderTheme),
35+
typeof(InteractableColorTheme)
36+
};
3237

3338
/// <summary>
3439
/// Get a list of themes
3540
/// </summary>
3641
/// <returns></returns>
37-
public static ThemeLists GetThemeTypes()
42+
public static InteractableTypesContainer GetThemeTypes()
3843
{
39-
List<Type> themeTypes = new List<Type>();
40-
List<string> names = new List<string>();
41-
42-
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
43-
foreach (var assembly in assemblies)
44-
{
45-
foreach (Type type in assembly.GetTypes())
46-
{
47-
TypeInfo info = type.GetTypeInfo();
48-
if (info.BaseType != null && (info.BaseType.Equals(typeof(InteractableThemeBase)) || info.BaseType.Equals(typeof(InteractableShaderTheme)) || info.BaseType.Equals(typeof(InteractableColorTheme))))
49-
{
50-
themeTypes.Add(type);
51-
names.Add(type.Name);
52-
}
53-
}
54-
}
55-
56-
ThemeLists lists = new ThemeLists();
57-
lists.Types = themeTypes;
58-
lists.Names = names;
59-
return lists;
44+
return InteractableTypeFinder.Find(candidateThemeTypes, TypeRestriction.DerivedOnly);
6045
}
6146

6247
/// <summary>
@@ -66,14 +51,12 @@ public static ThemeLists GetThemeTypes()
6651
/// <param name="host"></param>
6752
/// <param name="lists"></param>
6853
/// <returns></returns>
69-
public static InteractableThemeBase GetTheme(InteractableThemePropertySettings settings, GameObject host, ThemeLists lists)
54+
public static InteractableThemeBase GetTheme(InteractableThemePropertySettings settings, GameObject host)
7055
{
71-
int index = InspectorField.ReverseLookup(settings.Name, lists.Names.ToArray());
72-
Type themeType = lists.Types[index];
73-
InteractableThemeBase theme = (InteractableThemeBase)Activator.CreateInstance(themeType, host);
74-
theme.Init(host ,settings);
56+
Type themeType = Type.GetType(settings.AssemblyQualifiedName);
57+
InteractableThemeBase theme = (InteractableThemeBase)Activator.CreateInstance(themeType);
58+
theme.Init(host, settings);
7559
return theme;
7660
}
77-
7861
}
7962
}

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/States/States.cs

Lines changed: 11 additions & 24 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 Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.TypeResolution;
45
using System;
56
using System.Collections;
67
using System.Collections.Generic;
@@ -15,9 +16,15 @@ public class States : ScriptableObject
1516
public List<State> StateList;
1617
public int DefaultIndex = 0;
1718
public Type StateType;
18-
public string[] StateOptions;
19-
public Type[] StateTypes;
19+
public InteractableTypesContainer StateOptions;
2020
public string StateLogicName = "InteractableStates";
21+
public string AssemblyQualifiedName = typeof(InteractableStates).AssemblyQualifiedName;
22+
23+
/// <summary>
24+
/// The list of base classes whose derived classes will be included in interactable state
25+
/// selection dropdowns.
26+
/// </summary>
27+
private static readonly List<Type> candidateStateTypes = new List<Type>() { typeof(InteractableStates) };
2128

2229
//!!! finish making states work, they should initiate the type and run the logic during play mode.
2330
private void OnEnable()
@@ -32,8 +39,7 @@ public State[] GetStates()
3239

3340
public InteractableStates SetupLogic()
3441
{
35-
int index = ReverseLookup(StateLogicName, StateOptions);
36-
StateType = StateTypes[index];
42+
StateType = Type.GetType(AssemblyQualifiedName);
3743
InteractableStates stateLogic = (InteractableStates)Activator.CreateInstance(StateType, StateList[DefaultIndex]);
3844
List<State> stateListCopy = new List<State>();
3945
for (int i = 0; i < StateList.Count; i++)
@@ -53,26 +59,7 @@ public InteractableStates SetupLogic()
5359

5460
public void SetupStateOptions()
5561
{
56-
List<Type> stateTypes = new List<Type>();
57-
List<string> names = new List<string>();
58-
59-
60-
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
61-
foreach (var assembly in assemblies)
62-
{
63-
foreach (Type type in assembly.GetTypes())
64-
{
65-
TypeInfo info = type.GetTypeInfo();
66-
if (info.BaseType != null && (info.BaseType.Equals(typeof(InteractableStates)) || type.Equals(typeof(InteractableStates))))
67-
{
68-
stateTypes.Add(type);
69-
names.Add(type.Name);
70-
}
71-
}
72-
}
73-
74-
StateOptions = names.ToArray();
75-
StateTypes = stateTypes.ToArray();
62+
StateOptions = InteractableTypeFinder.Find(candidateStateTypes, TypeRestriction.AllowBase);
7663
}
7764

7865
// redundant method, put in a utils with static methods!!!

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Themes/InteractableThemeBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public abstract class InteractableThemeBase
2222
public Easing Ease;
2323
public bool NoEasing;
2424
public bool Loaded;
25+
public string AssemblyQualifiedName;
2526

2627
private bool hasFirstState = false;
2728

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Themes/InteractableThemePropertySettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class ThemeTarget
4343
public struct InteractableThemePropertySettings
4444
{
4545
public string Name;
46+
public string AssemblyQualifiedName;
4647
public Type Type;
4748
public InteractableThemeBase Theme;
4849
public List<InteractableThemeProperty> Properties;

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/TypeResolution.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.

0 commit comments

Comments
 (0)