AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ToolTipBackgroundMesh.cs
Go to the documentation of this file.
1 //
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 // Licensed under the MIT License. See LICENSE in the project root for license information.
4 //
5 using UnityEngine;
6 
7 namespace HoloToolkit.UX.ToolTips
8 {
14  {
18  [SerializeField]
19  [Tooltip("Transform that scale and offset will be applied to.")]
20  private Transform backgroundTransform;
21 
22  private float depth = 1f;
23 
24  protected Bounds localContentBounds;
25 
29  public MeshRenderer BackgroundRenderer;
30 
34  public bool IsVisible
35  {
36  set
37  {
38  if (BackgroundRenderer)
39  {
40  BackgroundRenderer.enabled = value;
41  }
42  }
43  }
44 
48  public Transform BackgroundTransform
49  {
50  get
51  {
52  return backgroundTransform;
53  }
54 
55  set
56  {
57  backgroundTransform = value;
58  }
59  }
60 
61  protected override void ScaleToFitContent()
62  {
63  if (BackgroundRenderer != null)
64  {
65  //Get the local size of the content - this is the scale of the text under the content parent
66  Vector3 localContentSize = toolTip.LocalContentSize;
67  Vector3 localContentOffset = toolTip.LocalContentOffset;
68 
69  //Get the size of the mesh and use this to adjust the local content size on the x / y axis
70  //This will accomodate meshes that aren't built to 1,1 scale
71  Bounds meshBounds = BackgroundRenderer.GetComponent<MeshFilter>().sharedMesh.bounds;
72  localContentSize.x /= meshBounds.size.x;
73  localContentSize.y /= meshBounds.size.y;
74  localContentSize.z = depth;
75 
76  //Don't use the mesh bounds for local content since an offset center may be used for design effect
77  if (localContentSize.x > 0 && localContentSize.y > 0)
78  {
79  localContentBounds = new Bounds(localContentOffset, localContentSize);
80  }
81  }
82  }
83 
84  private void OnDrawGizmos()
85  {
86  if (Application.isPlaying)
87  return;
88 
89  if (toolTip == null)
90  toolTip = gameObject.GetComponent<ToolTip>();
91 
92  if (toolTip == null)
93  return;
94 
95  ScaleToFitContent();
96  }
97 
98 
99  }
100 }
Renders a background mesh for a tool tip using a mesh renderer If the mesh has an offset anchor point...
Class for Tooltip object Creates a floating tooltip that is attached to an object and moves to stay i...
Definition: ToolTip.cs:18
Base class for a tool tip background Automatically finds a ToolTip and subscribes to ContentChange ac...
MeshRenderer BackgroundRenderer
Mesh renderer button for mesh background.