[+] UIExtension

[+] UIExtension
This commit is contained in:
ALEXTANG
2023-04-13 15:35:54 +08:00
parent 7a80f79b16
commit fe69c18b4e
8 changed files with 214 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
using UnityEngine;
namespace GameMain
{
/// <summary>
/// 背景图片等比拉伸
/// </summary>
public class ImageBackGroundStretch : MonoBehaviour
{
protected virtual void Start()
{
DoImageStretch(9/16f);
}
private void DoImageStretch(float standardAspect)
{
float deviceAspect = Screen.width / (float)Screen.height;
if (standardAspect > deviceAspect)
{
float scale = standardAspect / deviceAspect;
transform.localScale = new Vector3(scale, scale, 1f);
}
else if (standardAspect < deviceAspect)
{
float scale = deviceAspect / standardAspect;
transform.localScale = new Vector3(scale, scale, 1f);
}
}
}
}