mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
31 lines
841 B
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|