AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
MeasureManager.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 UnityEngine;
5 using System.Collections;
6 using HoloToolkit.Unity;
7 using System.Collections.Generic;
8 using System;
10 
11 namespace HoloToolkit.Examples.GazeRuler
12 {
16  public class MeasureManager : Singleton<MeasureManager>, IHoldHandler, IInputClickHandler
17  {
18  private IGeometry manager;
20 
21  // set up prefabs
22  public GameObject LinePrefab;
23  public GameObject PointPrefab;
24  public GameObject ModeTipObject;
25  public GameObject TextPrefab;
26 
27  private void Start()
28  {
29  InputManager.Instance.PushFallbackInputHandler(gameObject);
30 
31  // inti measure mode
32  switch (Mode)
33  {
34  case GeometryMode.Polygon:
35  manager = PolygonManager.Instance;
36  break;
37  default:
38  manager = LineManager.Instance;
39  break;
40  }
41  }
42 
43  // place spatial point
44  public void OnSelect()
45  {
46  manager.AddPoint(LinePrefab, PointPrefab, TextPrefab);
47  }
48 
49  // delete latest line or geometry
50  public void DeleteLine()
51  {
52  manager.Delete();
53  }
54 
55  // delete all lines or geometry
56  public void ClearAll()
57  {
58  manager.Clear();
59  }
60 
61  // if current mode is geometry mode, try to finish geometry
62  public void OnPolygonClose()
63  {
65  client.ClosePolygon(LinePrefab, TextPrefab);
66  }
67 
68  // change measure mode
69  public void OnModeChange()
70  {
71  try
72  {
73  manager.Reset();
74  if (Mode == GeometryMode.Line)
75  {
76  Mode = GeometryMode.Polygon;
77  manager = PolygonManager.Instance;
78  }
79  else
80  {
81  Mode = GeometryMode.Line;
82  manager = LineManager.Instance;
83  }
84  }
85  catch (Exception ex)
86  {
87  Debug.Log(ex.Message);
88  }
89  ModeTipObject.SetActive(true);
90  }
91 
92  public void OnHoldStarted(HoldEventData eventData)
93  {
94  OnPolygonClose();
95  }
96 
97  public void OnHoldCompleted(HoldEventData eventData)
98  {
99  // Nothing to do
100  }
101 
102  public void OnHoldCanceled(HoldEventData eventData)
103  {
104  // Nothing to do
105  }
106 
107  public void OnInputClicked(InputClickedEventData eventData)
108  {
109  OnSelect();
110  }
111 }
112 
113  public class Point
114  {
115  public Vector3 Position { get; set; }
116 
117  public GameObject Root { get; set; }
118  public bool IsStart { get; set; }
119  }
120 
121 
122  public enum GeometryMode
123  {
124  Line,
125  Triangle,
126  Rectangle,
127  Cube,
128  Polygon
129  }
130 }
Input Manager is responsible for managing input sources and dispatching relevant events to the approp...
Definition: InputManager.cs:19
void OnHoldCompleted(HoldEventData eventData)
Manages all lines in the scene
Definition: LineManager.cs:14
void ClosePolygon(GameObject LinePrefab, GameObject TextPrefab)
Interface to implement to react to simple click input.
void OnHoldCanceled(HoldEventData eventData)
void OnInputClicked(InputClickedEventData eventData)
void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject TextPrefab)
static T Instance
Returns the Singleton instance of the classes type. If no instance is found, then we search for an in...
Definition: Singleton.cs:26
Interface to implement to react to hold gestures.
Definition: IHoldHandler.cs:11
void OnHoldStarted(HoldEventData eventData)
interface for geometry class
Definition: IGeometry.cs:12
manager all geometries in the scene
Describes an input event that involves a tap.
any geometry class inherit this interface should be closeable
Event dispatched when a hold gesture is detected.
Singleton behaviour class, used for components that should only have one instance.
Definition: Singleton.cs:14