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/CanvasHelper.cs

54 lines
1.0 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;
using UnityEngine.UI;
[ExecuteInEditMode]
public class CanvasHelper : MonoBehaviour
{
public float minAspect;
public float maxAspect;
public float minMatch;
public float maxMatch;
private CanvasScaler canvasScaler;
private void Start()
{
canvasScaler = GetComponent<CanvasScaler>();
Update();
}
private void Update()
{
float num = (float)Screen.width / (float)Screen.height;
if (num > maxAspect)
{
canvasScaler.matchWidthOrHeight = maxMatch;
}
else if (num < minAspect)
{
canvasScaler.matchWidthOrHeight = minMatch;
}
else
{
canvasScaler.matchWidthOrHeight = (num - minAspect) / (maxAspect - minAspect) * (maxMatch - minMatch) + minMatch;
}
}
}