Skip to content

Commit 9e938e8

Browse files
killerantztoddwil
authored andcommitted
Moved OverrideSizeRatio logic to the SetSizeRatio method so we do not duplicate code, but keep the same protection against a DivideByZero error.
1 parent 3bf1ef2 commit 9e938e8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Assets/HoloToolkit/Utilities/Scripts/FixedAngularSize.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ namespace HoloToolkit.Unity
1313
public class FixedAngularSize : MonoBehaviour
1414
{
1515
[Tooltip("Off sets the scale ratio so that text does not scale down too much. (Set to zero for linear scaling)")]
16-
public float SizeRatio = 0;
16+
public float OverrideSizeRatio = 0;
1717

1818
// The ratio between the transform's local scale and its starting
1919
// distance from the camera.
20+
private Vector3 defaultSizeRatios;
2021
private float startingDistance;
2122
private Vector3 startingScale;
2223

@@ -27,7 +28,7 @@ private void Start()
2728
startingDistance = Vector3.Distance(Camera.main.transform.position, transform.position);
2829
startingScale = transform.localScale;
2930

30-
SetSizeRatio(SizeRatio);
31+
SetSizeRatio(OverrideSizeRatio);
3132
}
3233

3334
/// <summary>
@@ -41,7 +42,7 @@ public void SetSizeRatio(float ratio)
4142
if (startingDistance > 0.0f)
4243
{
4344
// set to a linear scale ratio
44-
SizeRatio = 1 / startingDistance;
45+
OverrideSizeRatio = 1 / startingDistance;
4546
}
4647
else
4748
{
@@ -57,7 +58,7 @@ public void SetSizeRatio(float ratio)
5758
}
5859
else
5960
{
60-
SizeRatio = ratio;
61+
OverrideSizeRatio = ratio;
6162
}
6263
}
6364

@@ -66,8 +67,8 @@ private void Update()
6667
float distanceToHologram = Vector3.Distance(Camera.main.transform.position, transform.position);
6768
// create an offset ratio based on the starting position. This value creates a new angle that pivots
6869
// on the starting position that is more or less drastic than the normal scale ratio.
69-
float curvedRatio = 1 - startingDistance * SizeRatio;
70-
transform.localScale = startingScale * (distanceToHologram * SizeRatio + curvedRatio);
70+
float curvedRatio = 1 - startingDistance * OverrideSizeRatio;
71+
transform.localScale = startingScale * (distanceToHologram * OverrideSizeRatio + curvedRatio);
7172
}
7273
}
7374
}

0 commit comments

Comments
 (0)