mirror of
https://github.com/ConjureETS/ProjectClubCore.git
synced 2026-03-24 17:40:59 +00:00
30 lines
667 B
C#
30 lines
667 B
C#
using UnityEngine;
|
|
|
|
//[ExecuteInEditMode]
|
|
public class TelemetryElement : MonoBehaviour {
|
|
|
|
/// <summary>
|
|
/// The aspect ratio this element should maintain. 2 = twice as wide as tall.
|
|
/// </summary>
|
|
public float AspectRatio = 2;
|
|
|
|
// cached
|
|
RectTransform _rectTrans;
|
|
float _prevWidth;
|
|
|
|
void Update() {
|
|
|
|
if (_rectTrans == null)
|
|
_rectTrans = GetComponent<RectTransform>();
|
|
|
|
// Rescale the element to maintain the desired aspect ratio
|
|
var newWidth = _rectTrans.sizeDelta.x;
|
|
if (newWidth != _prevWidth) {
|
|
_rectTrans.sizeDelta = new Vector2(newWidth, newWidth / AspectRatio);
|
|
_prevWidth = newWidth;
|
|
}
|
|
|
|
|
|
}
|
|
}
|