You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Scripts/SizeBySize.cs

59 lines
1.2 KiB
C#

2 months ago
/*
http://www.cgsoso.com/forum-211-1.html
CG Unity3d Unity3d VIP
CGSOSO CG
daily assets update for try.
U should buy the asset from home store if u use it in your project!
*/
using UnityEngine;
[ExecuteInEditMode]
public class SizeBySize : MonoBehaviour
{
public bool heightByWidth;
public float heightByWidthRatio;
public bool widthByHeight;
public float widthByHeightRatio;
private RectTransform rt;
private void OnEnable()
{
rt = GetComponent<RectTransform>();
}
private void Update()
{
if (heightByWidth)
{
RectTransform rectTransform = rt;
Vector2 sizeDelta = rt.sizeDelta;
float x = sizeDelta.x;
Vector2 sizeDelta2 = rt.sizeDelta;
rectTransform.sizeDelta = new Vector2(x, sizeDelta2.x * heightByWidthRatio);
}
if (widthByHeight)
{
RectTransform rectTransform2 = rt;
Vector2 sizeDelta3 = rt.sizeDelta;
float x2 = sizeDelta3.y * widthByHeightRatio;
Vector2 sizeDelta4 = rt.sizeDelta;
rectTransform2.sizeDelta = new Vector2(x2, sizeDelta4.y);
}
}
private void OnDisable()
{
}
}