You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Scripts/WidthLayout.cs

78 lines
1.5 KiB
C#

3 months ago
/*
http://www.cgsoso.com/forum-211-1.html
CG Unity3d Unity3d VIP
CGSOSO CG
daily assets update for try.
U should buy the asset from home store if u use it in your project!
*/
using UnityEngine;
[ExecuteInEditMode]
public class WidthLayout : MonoBehaviour
{
public bool padding;
public float paddingValue;
public bool maxWidth;
public float maxWidthValue;
public bool minWidth;
public float minWidthValue;
private RectTransform rt;
private RectTransform parentRt;
private void OnEnable()
{
rt = GetComponent<RectTransform>();
parentRt = base.transform.parent.GetComponent<RectTransform>();
}
private void Update()
{
Vector2 sizeDelta = rt.sizeDelta;
float num = sizeDelta.x;
if (padding)
{
num = parentRt.rect.width - paddingValue * 2f;
}
if (maxWidth && num > maxWidthValue)
{
num = maxWidthValue;
}
if (minWidth && num < minWidthValue)
{
num = minWidthValue;
}
RectTransform rectTransform = rt;
float x = num;
Vector2 sizeDelta2 = rt.sizeDelta;
rectTransform.sizeDelta = new Vector2(x, sizeDelta2.y);
Vector2 pivot = rt.pivot;
if (pivot.x == 0f)
{
RectTransform rectTransform2 = rt;
float x2 = (0f - num) / 2f;
Vector3 localPosition = rt.localPosition;
float y = localPosition.y;
Vector3 localPosition2 = rt.localPosition;
rectTransform2.localPosition = new Vector3(x2, y, localPosition2.z);
}
}
private void OnDisable()
{
}
}