AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
PanelTransformSizeOffset.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.Collections;
5 using System.Collections.Generic;
6 using UnityEngine;
7 
8 namespace HoloToolkit.Examples.Prototyping
9 {
18  [ExecuteInEditMode]
19  public class PanelTransformSizeOffset : MonoBehaviour
20  {
21  [Tooltip("A pixel to Unity unit conversion, Default: 2048x2048 pixels covers a 1x1 Unity Unit or default primitive size")]
22  public float BasePixelScale = 2048;
23 
24  [Tooltip("The transform this object should be linked and aligned to")]
25  public Transform AnchorTransform;
26 
27  [Tooltip(" The z-depth or size of this element using the pixel base size ratio")]
28  public float Depth = 20;
29 
30  [Tooltip("The amount of pixel based distance between the top edge of the Anchor and this element's top edge")]
31  public float TopBuffer = 10;
32 
33  [Tooltip("The amount of pixel based distance between the top edge of the Anchor and this element's right edge")]
34  public float RightBuffer = 10;
35 
36  [Tooltip("The amount of pixel based distance between the left edge of the Anchor and this element's left edge")]
37  public float LeftBuffer = 10;
38 
39  [Tooltip("The amount of pixel based distance between the top edge of the Anchor and this element's bottom edge")]
40  public float BottomBuffer = 10;
41 
42  [Tooltip("The amount of pixel based distance to offset the position along the z axis")]
43  public float ZOffset = -5;
44 
48  private void UpdatePosition()
49  {
50  float xOffset = (RightBuffer - LeftBuffer) / 2;
51  float yOffset = (TopBuffer - BottomBuffer) / 2;
52 
53  Vector3 newPosition = AnchorTransform.localPosition + Vector3.right * (xOffset / BasePixelScale) + Vector3.down * (yOffset / BasePixelScale) + Vector3.forward * (ZOffset / BasePixelScale);
54  transform.localPosition = newPosition;
55  }
56 
60  private void UpdateSize()
61  {
62  Vector3 newScale = new Vector3((AnchorTransform.localScale.x * BasePixelScale - (RightBuffer + LeftBuffer)) / BasePixelScale, (AnchorTransform.localScale.y * BasePixelScale - (TopBuffer + BottomBuffer)) / BasePixelScale, Depth / BasePixelScale);
63  transform.localScale = newScale;
64  }
65 
66  // Update is called once per frame
67  void Update()
68  {
69  if (AnchorTransform != null)
70  {
71  UpdateSize();
72  UpdatePosition();
73  }
74  }
75  }
76 }
Adds margins or buffers using size values, similar to RectTransorm size values or pixel values used i...