Files
TEngine/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs
ALEXTANG fe69c18b4e [+] UIExtension
[+] UIExtension
2023-04-13 15:35:54 +08:00

31 lines
841 B
C#

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);
}
}
}
}