AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ObjectDisplayScript.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.UX
9 {
14  public class ObjectDisplayScript : MonoBehaviour
15  {
16  [Header("How fast does object rotate?")]
17  [SerializeField]
18  private float rotationIncrement = 200;
19 
20  [Header("Start scale of the object?")]
21  [SerializeField]
22  private float minScale = 1.0f;
23 
24  [Header("Final scale of the object?")]
25  [SerializeField]
26  private float maxScale = 9.0f;
27 
28  [Header("How fast does object grow?")]
29  [SerializeField]
30  private float scaleSpeed = 30.0f;
31 
32  [Header("Should object rotate after growing?")]
33  [SerializeField]
34  private bool rotationActive = false;
35 
36  [Header("Should object grow before rotating?")]
37  [SerializeField]
38  private bool growingActive = true;
39 
40  [Header("Rotation occurs about which axes?")]
41  [SerializeField]
42  private bool xAxisRotation = false;
43  [SerializeField]
44  private bool yAxisRotation = true;
45  [SerializeField]
46  private bool zAxisRotation = false;
47 
48  private float currentScale;
49  private float elapsedTime;
50 
51  private void Start()
52  {
53  Reset();
54  }
55 
56  public void Reset()
57  {
58  elapsedTime = 0.0f;
59  currentScale = minScale;
60  }
61 
62  private void Update()
63  {
64  elapsedTime += Time.unscaledDeltaTime;
65 
66  if (growingActive && currentScale < maxScale)
67  {
68  currentScale = minScale + (scaleSpeed * (maxScale * Mathf.Pow(elapsedTime, 2.0f)));
69  }
70 
71  transform.localScale = new Vector3(currentScale, currentScale, currentScale);
72 
73  if (rotationActive)
74  {
75  float increment = Time.deltaTime * rotationIncrement;
76  float xRotation = xAxisRotation ? increment : 0;
77  float yRotation = yAxisRotation ? increment : 0;
78  float zRotation = zAxisRotation ? increment : 0;
79  transform.Rotate(xRotation, yRotation, zRotation);
80  }
81  }
82  }
83 }
This class manages how a gameobject rotates and/or scales when activated as part of a Progress Indica...