AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
CustomInputSelector.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using System.Collections.Generic;
6 using UnityEngine;
7 #if UNITY_2017_2_OR_NEWER
8 using UnityEngine.XR;
9 #else
10 using UnityEngine.VR;
11 #endif
12 
13 namespace HoloToolkit.Unity.InputModule
14 {
18  public class CustomInputSelector : MonoBehaviour
19  {
20  private enum InputSourceType
21  {
22  Hand,
23  Mouse
24  }
25 
26  private enum InputSourceNumber
27  {
28  One,
29  Two
30  }
31 
32  [SerializeField]
33  private bool simulateHandsInEditor = true;
34 
35  [SerializeField]
36  private InputSourceType sourceType;
37 
38  [SerializeField]
39  private InputSourceNumber sourceNumber;
40 
41  public List<GameObject> Inputs = new List<GameObject>(0);
42 
43  [SerializeField]
44  private GameObject mouse = null;
45 
46  [SerializeField]
47  private GameObject leftHand = null;
48 
49  [SerializeField]
50  private GameObject rightHand = null;
51 
52  private void Awake()
53  {
54  bool spawnControllers = false;
55 
56 #if UNITY_2017_2_OR_NEWER
57  spawnControllers = !XRDevice.isPresent && XRSettings.enabled && simulateHandsInEditor;
58 #else
59  spawnControllers = simulateHandsInEditor;
60 #endif
61  if (spawnControllers)
62  {
63  sourceType = InputSourceType.Hand;
64  sourceNumber = InputSourceNumber.Two;
65  }
66 
67  if (!spawnControllers) { return; }
68 
69  switch (sourceType)
70  {
71  case InputSourceType.Hand:
72  GameObject newRightInputSource = Instantiate(rightHand);
73 
74  newRightInputSource.name = "Right_" + sourceType.ToString();
75  newRightInputSource.transform.SetParent(transform);
76  Inputs.Add(newRightInputSource);
77 
78  if (sourceNumber == InputSourceNumber.Two)
79  {
80  GameObject newLeftInputSource = Instantiate(leftHand);
81  newLeftInputSource.name = "Left_" + sourceType.ToString();
82  newLeftInputSource.transform.SetParent(transform);
83  Inputs.Add(newLeftInputSource);
84  }
85  break;
86  case InputSourceType.Mouse:
87  GameObject newMouseInputSource = Instantiate(mouse);
88  newMouseInputSource.transform.SetParent(transform);
89  Inputs.Add(newMouseInputSource);
90 
91  break;
92  default:
93  throw new ArgumentOutOfRangeException();
94  }
95  }
96  }
97 }
This class is used to select input for the Editor and applications built outside of the UWP build tar...