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/PositionLayout.cs

108 lines
2.0 KiB
C#

4 weeks 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 PositionLayout : MonoBehaviour
{
public bool paddingLeft;
public float paddingLeftValue;
public bool paddingRight;
public float paddingRightValue;
public bool paddingTop;
public float paddingTopValue;
public bool paddingBottom;
public float paddingBottomValue;
public bool minLeft;
public float minLeftValue;
public bool maxRight;
public float maxRightValue;
public bool minBottom;
public float minBottomValue;
public bool maxTop;
public float maxTopValue;
private RectTransform parentRt;
private void Start()
{
parentRt = base.transform.parent.GetComponent<RectTransform>();
}
private void Update()
{
Vector3 localPosition = base.transform.localPosition;
float num = localPosition.x;
Vector3 localPosition2 = base.transform.localPosition;
float num2 = localPosition2.y;
if (paddingLeft)
{
num = (0f - parentRt.rect.width) / 2f + paddingLeftValue;
}
if (paddingRight)
{
num = parentRt.rect.width / 2f - paddingRightValue;
}
if (paddingTop)
{
num2 = parentRt.rect.height / 2f - paddingTopValue;
}
if (paddingBottom)
{
num2 = (0f - parentRt.rect.height) / 2f + paddingBottomValue;
}
if (minLeft && num < minLeftValue)
{
num = minLeftValue;
}
if (maxRight && num > maxRightValue)
{
num = maxRightValue;
}
if (minBottom && num2 < minBottomValue)
{
num2 = minBottomValue;
}
if (maxTop && num2 > maxTopValue)
{
num2 = maxTopValue;
}
Transform transform = base.transform;
float x = num;
float y = num2;
Vector3 localPosition3 = base.transform.localPosition;
transform.localPosition = new Vector3(x, y, localPosition3.z);
}
private void OnDisable()
{
}
}