using System; using UnityEngine; [RequireComponent(typeof(UIWidget))] [AddComponentMenu("NGUI/Examples/Envelop Content")] public class EnvelopContent : MonoBehaviour { private void Start() { this.mStarted = true; this.Execute(); } private void OnEnable() { if (this.mStarted) { this.Execute(); } } [ContextMenu("Execute")] public void Execute() { if (this.targetRoot == base.transform) { Debug.LogError("Target Root object cannot be the same object that has Envelop Content. Make it a sibling instead.", this); } else if (NGUITools.IsChild(this.targetRoot, base.transform)) { Debug.LogError("Target Root object should not be a parent of Envelop Content. Make it a sibling instead.", this); } else { Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(base.transform.parent, this.targetRoot, false, true); float num = bounds.min.x + (float)this.padLeft; float num2 = bounds.min.y + (float)this.padBottom; float num3 = bounds.max.x + (float)this.padRight; float num4 = bounds.max.y + (float)this.padTop; UIWidget component = base.GetComponent(); component.SetRect(num, num2, num3 - num, num4 - num2); base.BroadcastMessage("UpdateAnchors", SendMessageOptions.DontRequireReceiver); } } public Transform targetRoot; public int padLeft; public int padRight; public int padBottom; public int padTop; private bool mStarted; }