AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
PointerLine.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 HoloToolkit.Unity.UX;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.InputModule
8 {
9  [RequireComponent(typeof(DistorterGravity))]
10  [RequireComponent(typeof(LineBase))]
11  [RequireComponent(typeof(LineRendererBase))]
13  {
14  [Header("Colors")]
15  [SerializeField]
16  [GradientDefault(GradientDefaultAttribute.ColorEnum.Blue, GradientDefaultAttribute.ColorEnum.White, 1f, 0.25f)]
17  protected Gradient LineColorSelected;
18 
19  [SerializeField]
20  [GradientDefault(GradientDefaultAttribute.ColorEnum.Blue, GradientDefaultAttribute.ColorEnum.White, 1f, 0.5f)]
21  protected Gradient LineColorValid;
22 
23  [SerializeField]
24  [GradientDefault(GradientDefaultAttribute.ColorEnum.Gray, GradientDefaultAttribute.ColorEnum.White, 1f, 0.5f)]
25  protected Gradient LineColorNoTarget;
26 
27  [Range(5, 100)]
28  [SerializeField]
29  protected int LineCastResolution = 25;
30 
31  [SerializeField]
32  protected LineBase LineBase;
33 
34  [SerializeField]
35  [Tooltip("If no line renderers are specified, this array will be auto-populated on startup.")]
37 
39 
43  public bool InteractionEnabled
44  {
45  get
46  {
47 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
48  return ControllerInfo != null;
49 #else
50  return false;
51 #endif
52  }
53  }
54 
55  protected override void OnEnable()
56  {
57  base.OnEnable();
58 
59  LineBase = GetComponent<LineBase>();
60  DistorterGravity = GetComponent<DistorterGravity>();
61  LineBase.AddDistorter(DistorterGravity);
62  if (LineRenderers == null || LineRenderers.Length == 0)
63  {
64  LineRenderers = LineBase.GetComponentsInChildren<LineRendererBase>();
65  }
66 
67  LineBase.enabled = false;
68  }
69 
70  public void UpdateRenderedLine(RayStep[] lines, PointerResult result, bool selectPressed, float extent)
71  {
72  if (LineBase == null) { return; }
73 
74  Gradient lineColor = LineColorNoTarget;
75 
76  if (InteractionEnabled)
77  {
78  LineBase.enabled = true;
79 
80  // If we hit something
81  if (result.End.Object != null)
82  {
83  lineColor = LineColorValid;
84  LineBase.LastPoint = result.End.Point;
85  }
86  else
87  {
88  LineBase.LastPoint = RayStep.GetPointByDistance(lines, extent);
89  }
90 
91  if (selectPressed)
92  {
93  lineColor = LineColorSelected;
94  }
95  }
96  else
97  {
98  LineBase.enabled = false;
99  }
100 
101  for (int i = 0; i < LineRenderers.Length; i++)
102  {
103  LineRenderers[i].LineColor = lineColor;
104  }
105  }
106  }
107 }
void UpdateRenderedLine(RayStep[] lines, PointerResult result, bool selectPressed, float extent)
Definition: PointerLine.cs:70
static Vector3 GetPointByDistance(RayStep[] steps, float distance)
Returns a point along an array of RaySteps by distance
Definition: RayStep.cs:59
void AddDistorter(Distorter newDistorter)
Definition: LineBase.cs:147