Tilt Five™ Unity API  1.3.0
 
Loading...
Searching...
No Matches
TiltFive.UniformScaleTransform Class Reference

Enforces uniform scaling by setting the x, y, and z scale components of the associated transform to be equal. More...

Inheritance diagram for TiltFive.UniformScaleTransform:
TiltFive.GameBoard

Public Member Functions

void Awake ()
 

Protected Member Functions

void UnifyScale ()
 Synchronizes the component values of the game object's local scale vector (e.g. [1,2,3] becomes [3,3,3]).
 

Properties

float localScale [get, set]
 The size of the object as a single float value, rather than a scale vector.
 
Vector3 position [get, set]
 The position vector for the associated transform.
 
Quaternion rotation [get, set]
 The rotation vector for the associated transform.
 

Private Member Functions

void Update ()
 

Private Attributes

Vector3 _previousScale
 

Detailed Description

Enforces uniform scaling by setting the x, y, and z scale components of the associated transform to be equal.

Definition at line 26 of file UniformScaleTransform.cs.

Member Function Documentation

◆ Awake()

void TiltFive.UniformScaleTransform.Awake ( )

Definition at line 106 of file UniformScaleTransform.cs.

107 {
108 // Initial pass, in case the transform's scale is already non-uniform before UniformScaleTransform is initialized.
109 _previousScale = Vector3.one;
110 UnifyScale();
111
112 _previousScale = transform.localScale;
113 }
void UnifyScale()
Synchronizes the component values of the game object's local scale vector (e.g. [1,...

References TiltFive.UniformScaleTransform._previousScale, and TiltFive.UniformScaleTransform.UnifyScale().

◆ UnifyScale()

void TiltFive.UniformScaleTransform.UnifyScale ( )
protected

Synchronizes the component values of the game object's local scale vector (e.g. [1,2,3] becomes [3,3,3]).

The vector component with the most extreme deviation from the previous uniform scale vector will be selected. If the previous scale was [2,2,2] and the current scale is [5, 15, 50] then the result will be [50, 50, 50]. This also applies for negative values: [5, -20, 10] would result in [-20,-20,-20].

Definition at line 81 of file UniformScaleTransform.cs.

82 {
83 // Compare the current scale against the previous scale.
84 if (transform.localScale == _previousScale)
85 {
86 return;
87 }
88
89 // Get the component that changed the most, and set the scale to that value.
90 var deltaScale = transform.localScale - _previousScale;
91 var largestPositiveChange = Mathf.Max(deltaScale.x, deltaScale.y, deltaScale.z);
92 var largestNegativeChange = Mathf.Min(deltaScale.x, deltaScale.y, deltaScale.z);
93 var largestAbsoluteChange = Mathf.Abs(largestPositiveChange) > Mathf.Abs(largestNegativeChange)
94 ? largestPositiveChange
95 : largestNegativeChange;
96
97 transform.localScale = _previousScale + Vector3.one * largestAbsoluteChange;
98 _previousScale = transform.localScale;
99 }

References TiltFive.UniformScaleTransform._previousScale.

Referenced by TiltFive.UniformScaleTransform.Awake(), and TiltFive.UniformScaleTransform.Update().

◆ Update()

void TiltFive.UniformScaleTransform.Update ( )
private

Definition at line 116 of file UniformScaleTransform.cs.

117 {
118 UnifyScale();
119 }

References TiltFive.UniformScaleTransform.UnifyScale().

Member Data Documentation

◆ _previousScale

Vector3 TiltFive.UniformScaleTransform._previousScale
private

Property Documentation

◆ localScale

float TiltFive.UniformScaleTransform.localScale
getset

The size of the object as a single float value, rather than a scale vector.

Definition at line 33 of file UniformScaleTransform.cs.

34 {
35 get => transform.localScale.x;
36 set
37 {
38 base.transform.localScale = Vector3.one * value;
39 _previousScale = base.transform.localScale;
40 }
41 }

◆ position

Vector3 TiltFive.UniformScaleTransform.position
getset

The position vector for the associated transform.


Definition at line 46 of file UniformScaleTransform.cs.

47 {
48 get => transform.position;
49 set => transform.position = value;
50 }

◆ rotation

Quaternion TiltFive.UniformScaleTransform.rotation
getset

The rotation vector for the associated transform.

Definition at line 55 of file UniformScaleTransform.cs.

56 {
57 get => transform.rotation;
58 set => base.transform.rotation = value;
59 }

Referenced by TiltFive.TrackableCore< TSettings, TState >.GameboardToWorldSpace(), TiltFive.TrackableCore< TSettings, TState >.Update(), and TiltFive.TrackableCore< TSettings, TState >.WorldToGameboardSpace().


The documentation for this class was generated from the following file: