Files
JJBB/Assets/Project/Script/GUI/Base/UIBGImageSize.cs

33 lines
829 B
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using UnityEngine;
// public class BGAnchorObj
// {
// public Transform _AnchorObj;
// public Vector2 _Position;
// }
public class UIBGImageSize : MonoBehaviour
{
public float _HeightFix;
public float _WidthFix;
// public List<BGAnchorObj> _AnchorInfos;
private RectTransform _RectTransform;
private void Awake()
{
_RectTransform = GetComponent<RectTransform>();
}
private void Start()
{
SetScreenSize();
}
private void SetScreenSize()
{
if (_HeightFix > 0)
_RectTransform.sizeDelta = new Vector2(_RectTransform.sizeDelta.x, _RectTransform.rect.width * _HeightFix);
else if (_WidthFix > 0)
_RectTransform.sizeDelta = new Vector2(_RectTransform.rect.height / _WidthFix, _RectTransform.sizeDelta.y);
}
}