mirror of
https://github.com/maxartz15/TextureCombiner.git
synced 2024-11-14 00:55:35 +01:00
1165a4e4a8
P4 -> GitHub sync.
39 lines
874 B
C#
39 lines
874 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TextureCombiner
|
|
{
|
|
[RequireComponent(typeof(RectTransform)), ExecuteInEditMode]
|
|
public class FitRect : MonoBehaviour
|
|
{
|
|
public bool m_fitHeight = false;
|
|
public bool m_fitWidth = false;
|
|
public RectTransform m_rectToFit = null;
|
|
|
|
private RectTransform m_rectTransform = null;
|
|
private Rect m_prevRect = new Rect();
|
|
|
|
private void Awake()
|
|
{
|
|
m_rectTransform = GetComponent<RectTransform>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(!m_rectToFit)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(m_prevRect != m_rectToFit.rect)
|
|
{
|
|
m_prevRect = m_rectToFit.rect;
|
|
|
|
m_rectTransform.sizeDelta = new Vector2(
|
|
m_fitWidth ? m_rectToFit.rect.width : m_rectTransform.rect.width,
|
|
m_fitHeight ? m_rectToFit.rect.height : m_rectToFit.rect.height
|
|
);
|
|
}
|
|
}
|
|
}
|
|
} |