mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] UIExtension
[+] UIExtension
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user