123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using UnityEngine;
- [ExecuteInEditMode]
- [AddComponentMenu("NGUI/UI/NGUI Panel")]
- public class UIPanel : UIRect
- {
- public static int nextUnusedDepth
- {
- get
- {
- int num = int.MinValue;
- int i = 0;
- int count = UIPanel.list.Count;
- while (i < count)
- {
- num = Mathf.Max(num, UIPanel.list[i].depth);
- i++;
- }
- return (num != int.MinValue) ? (num + 1) : 0;
- }
- }
- public override bool canBeAnchored
- {
- get
- {
- return this.mClipping != UIDrawCall.Clipping.None;
- }
- }
- public override float alpha
- {
- get
- {
- return this.mAlpha;
- }
- set
- {
- float num = Mathf.Clamp01(value);
- if (this.mAlpha != num)
- {
- this.mAlphaFrameID = -1;
- this.mResized = true;
- this.mAlpha = num;
- this.SetDirty();
- }
- }
- }
- public int depth
- {
- get
- {
- return this.mDepth;
- }
- set
- {
- if (this.mDepth != value)
- {
- this.mDepth = value;
- List<UIPanel> list = UIPanel.list;
- if (UIPanel.<>f__mg$cache0 == null)
- {
- UIPanel.<>f__mg$cache0 = new Comparison<UIPanel>(UIPanel.CompareFunc);
- }
- list.Sort(UIPanel.<>f__mg$cache0);
- }
- }
- }
- public int sortingOrder
- {
- get
- {
- return this.mSortingOrder;
- }
- set
- {
- if (this.mSortingOrder != value)
- {
- this.mSortingOrder = value;
- this.UpdateDrawCalls();
- }
- }
- }
- public static int CompareFunc(UIPanel a, UIPanel b)
- {
- if (!(a != b) || !(a != null) || !(b != null))
- {
- return 0;
- }
- if (a.mDepth < b.mDepth)
- {
- return -1;
- }
- if (a.mDepth > b.mDepth)
- {
- return 1;
- }
- return (a.GetInstanceID() >= b.GetInstanceID()) ? 1 : -1;
- }
- public float width
- {
- get
- {
- return this.GetViewSize().x;
- }
- }
- public float height
- {
- get
- {
- return this.GetViewSize().y;
- }
- }
- public bool halfPixelOffset
- {
- get
- {
- return this.mHalfPixelOffset;
- }
- }
- public bool usedForUI
- {
- get
- {
- return base.anchorCamera != null && this.mCam.orthographic;
- }
- }
- public Vector3 drawCallOffset
- {
- get
- {
- if (this.mHalfPixelOffset && base.anchorCamera != null && this.mCam.orthographic)
- {
- float num = 1f / this.GetWindowSize().y / this.mCam.orthographicSize;
- return new Vector3(-num, num);
- }
- return Vector3.zero;
- }
- }
- public UIDrawCall.Clipping clipping
- {
- get
- {
- return this.mClipping;
- }
- set
- {
- if (this.mClipping != value)
- {
- this.mResized = true;
- this.mClipping = value;
- this.mMatrixFrame = -1;
- }
- }
- }
- public UIPanel parentPanel
- {
- get
- {
- return this.mParentPanel;
- }
- }
- public int clipCount
- {
- get
- {
- int num = 0;
- UIPanel uipanel = this;
- while (uipanel != null)
- {
- if (uipanel.mClipping == UIDrawCall.Clipping.SoftClip || uipanel.mClipping == UIDrawCall.Clipping.TextureMask)
- {
- num++;
- }
- uipanel = uipanel.mParentPanel;
- }
- return num;
- }
- }
- public bool hasClipping
- {
- get
- {
- return this.mClipping == UIDrawCall.Clipping.SoftClip || this.mClipping == UIDrawCall.Clipping.TextureMask;
- }
- }
- public bool hasCumulativeClipping
- {
- get
- {
- return this.clipCount != 0;
- }
- }
- [Obsolete("Use 'hasClipping' or 'hasCumulativeClipping' instead")]
- public bool clipsChildren
- {
- get
- {
- return this.hasCumulativeClipping;
- }
- }
- public Vector2 clipOffset
- {
- get
- {
- return this.mClipOffset;
- }
- set
- {
- if (Mathf.Abs(this.mClipOffset.x - value.x) > 0.001f || Mathf.Abs(this.mClipOffset.y - value.y) > 0.001f)
- {
- this.mClipOffset = value;
- this.InvalidateClipping();
- if (this.onClipMove != null)
- {
- this.onClipMove(this);
- }
- }
- }
- }
- private void InvalidateClipping()
- {
- this.mResized = true;
- this.mMatrixFrame = -1;
- this.mCullTime = ((this.mCullTime != 0f) ? (RealTime.time + 0.15f) : 0.001f);
- int i = 0;
- int count = UIPanel.list.Count;
- while (i < count)
- {
- UIPanel uipanel = UIPanel.list[i];
- if (uipanel != this && uipanel.parentPanel == this)
- {
- uipanel.InvalidateClipping();
- }
- i++;
- }
- }
- public Texture2D clipTexture
- {
- get
- {
- return this.mClipTexture;
- }
- set
- {
- if (this.mClipTexture != value)
- {
- this.mClipTexture = value;
- }
- }
- }
- [Obsolete("Use 'finalClipRegion' or 'baseClipRegion' instead")]
- public Vector4 clipRange
- {
- get
- {
- return this.baseClipRegion;
- }
- set
- {
- this.baseClipRegion = value;
- }
- }
- public Vector4 baseClipRegion
- {
- get
- {
- return this.mClipRange;
- }
- set
- {
- if (Mathf.Abs(this.mClipRange.x - value.x) > 0.001f || Mathf.Abs(this.mClipRange.y - value.y) > 0.001f || Mathf.Abs(this.mClipRange.z - value.z) > 0.001f || Mathf.Abs(this.mClipRange.w - value.w) > 0.001f)
- {
- this.mResized = true;
- this.mCullTime = ((this.mCullTime != 0f) ? (RealTime.time + 0.15f) : 0.001f);
- this.mClipRange = value;
- this.mMatrixFrame = -1;
- UIScrollView component = base.GetComponent<UIScrollView>();
- if (component != null)
- {
- component.UpdatePosition();
- }
- if (this.onClipMove != null)
- {
- this.onClipMove(this);
- }
- }
- }
- }
- public Vector4 finalClipRegion
- {
- get
- {
- Vector2 viewSize = this.GetViewSize();
- if (this.mClipping != UIDrawCall.Clipping.None)
- {
- return new Vector4(this.mClipRange.x + this.mClipOffset.x, this.mClipRange.y + this.mClipOffset.y, viewSize.x, viewSize.y);
- }
- return new Vector4(0f, 0f, viewSize.x, viewSize.y);
- }
- }
- public Vector2 clipSoftness
- {
- get
- {
- return this.mClipSoftness;
- }
- set
- {
- if (this.mClipSoftness != value)
- {
- this.mClipSoftness = value;
- }
- }
- }
- public override Vector3[] localCorners
- {
- get
- {
- if (this.mClipping == UIDrawCall.Clipping.None)
- {
- Vector3[] worldCorners = this.worldCorners;
- Transform cachedTransform = base.cachedTransform;
- for (int i = 0; i < 4; i++)
- {
- worldCorners[i] = cachedTransform.InverseTransformPoint(worldCorners[i]);
- }
- return worldCorners;
- }
- float num = this.mClipOffset.x + this.mClipRange.x - 0.5f * this.mClipRange.z;
- float num2 = this.mClipOffset.y + this.mClipRange.y - 0.5f * this.mClipRange.w;
- float x = num + this.mClipRange.z;
- float y = num2 + this.mClipRange.w;
- UIPanel.mCorners[0] = new Vector3(num, num2);
- UIPanel.mCorners[1] = new Vector3(num, y);
- UIPanel.mCorners[2] = new Vector3(x, y);
- UIPanel.mCorners[3] = new Vector3(x, num2);
- return UIPanel.mCorners;
- }
- }
- public override Vector3[] worldCorners
- {
- get
- {
- if (this.mClipping != UIDrawCall.Clipping.None)
- {
- float num = this.mClipOffset.x + this.mClipRange.x - 0.5f * this.mClipRange.z;
- float num2 = this.mClipOffset.y + this.mClipRange.y - 0.5f * this.mClipRange.w;
- float x = num + this.mClipRange.z;
- float y = num2 + this.mClipRange.w;
- Transform cachedTransform = base.cachedTransform;
- UIPanel.mCorners[0] = cachedTransform.TransformPoint(num, num2, 0f);
- UIPanel.mCorners[1] = cachedTransform.TransformPoint(num, y, 0f);
- UIPanel.mCorners[2] = cachedTransform.TransformPoint(x, y, 0f);
- UIPanel.mCorners[3] = cachedTransform.TransformPoint(x, num2, 0f);
- }
- else
- {
- if (base.anchorCamera != null)
- {
- return this.mCam.GetWorldCorners(base.cameraRayDistance);
- }
- Vector2 viewSize = this.GetViewSize();
- float num3 = -0.5f * viewSize.x;
- float num4 = -0.5f * viewSize.y;
- float x2 = num3 + viewSize.x;
- float y2 = num4 + viewSize.y;
- UIPanel.mCorners[0] = new Vector3(num3, num4);
- UIPanel.mCorners[1] = new Vector3(num3, y2);
- UIPanel.mCorners[2] = new Vector3(x2, y2);
- UIPanel.mCorners[3] = new Vector3(x2, num4);
- if (this.anchorOffset && (this.mCam == null || this.mCam.transform.parent != base.cachedTransform))
- {
- Vector3 position = base.cachedTransform.position;
- for (int i = 0; i < 4; i++)
- {
- UIPanel.mCorners[i] += position;
- }
- }
- }
- return UIPanel.mCorners;
- }
- }
- public override Vector3[] GetSides(Transform relativeTo)
- {
- if (this.mClipping != UIDrawCall.Clipping.None)
- {
- float num = this.mClipOffset.x + this.mClipRange.x - 0.5f * this.mClipRange.z;
- float num2 = this.mClipOffset.y + this.mClipRange.y - 0.5f * this.mClipRange.w;
- float num3 = num + this.mClipRange.z;
- float num4 = num2 + this.mClipRange.w;
- float x = (num + num3) * 0.5f;
- float y = (num2 + num4) * 0.5f;
- Transform cachedTransform = base.cachedTransform;
- UIRect.mSides[0] = cachedTransform.TransformPoint(num, y, 0f);
- UIRect.mSides[1] = cachedTransform.TransformPoint(x, num4, 0f);
- UIRect.mSides[2] = cachedTransform.TransformPoint(num3, y, 0f);
- UIRect.mSides[3] = cachedTransform.TransformPoint(x, num2, 0f);
- if (relativeTo != null)
- {
- for (int i = 0; i < 4; i++)
- {
- UIRect.mSides[i] = relativeTo.InverseTransformPoint(UIRect.mSides[i]);
- }
- }
- return UIRect.mSides;
- }
- if (base.anchorCamera != null && this.anchorOffset)
- {
- Vector3[] sides = this.mCam.GetSides(base.cameraRayDistance);
- Vector3 position = base.cachedTransform.position;
- for (int j = 0; j < 4; j++)
- {
- sides[j] += position;
- }
- if (relativeTo != null)
- {
- for (int k = 0; k < 4; k++)
- {
- sides[k] = relativeTo.InverseTransformPoint(sides[k]);
- }
- }
- return sides;
- }
- return base.GetSides(relativeTo);
- }
- public override void Invalidate(bool includeChildren)
- {
- this.mAlphaFrameID = -1;
- base.Invalidate(includeChildren);
- }
- public override float CalculateFinalAlpha(int frameID)
- {
- if (this.mAlphaFrameID != frameID)
- {
- this.mAlphaFrameID = frameID;
- UIRect parent = base.parent;
- this.finalAlpha = ((!(base.parent != null)) ? this.mAlpha : (parent.CalculateFinalAlpha(frameID) * this.mAlpha));
- }
- return this.finalAlpha;
- }
- public override void SetRect(float x, float y, float width, float height)
- {
- int num = Mathf.FloorToInt(width + 0.5f);
- int num2 = Mathf.FloorToInt(height + 0.5f);
- num = num >> 1 << 1;
- num2 = num2 >> 1 << 1;
- Transform transform = base.cachedTransform;
- Vector3 localPosition = transform.localPosition;
- localPosition.x = Mathf.Floor(x + 0.5f);
- localPosition.y = Mathf.Floor(y + 0.5f);
- if (num < 2)
- {
- num = 2;
- }
- if (num2 < 2)
- {
- num2 = 2;
- }
- this.baseClipRegion = new Vector4(localPosition.x, localPosition.y, (float)num, (float)num2);
- if (base.isAnchored)
- {
- transform = transform.parent;
- if (this.leftAnchor.target)
- {
- this.leftAnchor.SetHorizontal(transform, x);
- }
- if (this.rightAnchor.target)
- {
- this.rightAnchor.SetHorizontal(transform, x + width);
- }
- if (this.bottomAnchor.target)
- {
- this.bottomAnchor.SetVertical(transform, y);
- }
- if (this.topAnchor.target)
- {
- this.topAnchor.SetVertical(transform, y + height);
- }
- }
- }
- public bool IsVisible(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
- {
- this.UpdateTransformMatrix();
- a = this.worldToLocal.MultiplyPoint3x4(a);
- b = this.worldToLocal.MultiplyPoint3x4(b);
- c = this.worldToLocal.MultiplyPoint3x4(c);
- d = this.worldToLocal.MultiplyPoint3x4(d);
- UIPanel.mTemp[0] = a.x;
- UIPanel.mTemp[1] = b.x;
- UIPanel.mTemp[2] = c.x;
- UIPanel.mTemp[3] = d.x;
- float num = Mathf.Min(UIPanel.mTemp);
- float num2 = Mathf.Max(UIPanel.mTemp);
- UIPanel.mTemp[0] = a.y;
- UIPanel.mTemp[1] = b.y;
- UIPanel.mTemp[2] = c.y;
- UIPanel.mTemp[3] = d.y;
- float num3 = Mathf.Min(UIPanel.mTemp);
- float num4 = Mathf.Max(UIPanel.mTemp);
- return num2 >= this.mMin.x && num4 >= this.mMin.y && num <= this.mMax.x && num3 <= this.mMax.y;
- }
- public bool IsVisible(Vector3 worldPos)
- {
- if (this.mAlpha < 0.001f)
- {
- return false;
- }
- if (this.mClipping == UIDrawCall.Clipping.None || this.mClipping == UIDrawCall.Clipping.ConstrainButDontClip)
- {
- return true;
- }
- this.UpdateTransformMatrix();
- Vector3 vector = this.worldToLocal.MultiplyPoint3x4(worldPos);
- return vector.x >= this.mMin.x && vector.y >= this.mMin.y && vector.x <= this.mMax.x && vector.y <= this.mMax.y;
- }
- public bool IsVisible(UIWidget w)
- {
- UIPanel uipanel = this;
- Vector3[] array = null;
- while (uipanel != null)
- {
- if ((uipanel.mClipping == UIDrawCall.Clipping.None || uipanel.mClipping == UIDrawCall.Clipping.ConstrainButDontClip) && !w.hideIfOffScreen)
- {
- uipanel = uipanel.mParentPanel;
- }
- else
- {
- if (array == null)
- {
- array = w.worldCorners;
- }
- if (!uipanel.IsVisible(array[0], array[1], array[2], array[3]))
- {
- return false;
- }
- uipanel = uipanel.mParentPanel;
- }
- }
- return true;
- }
- public bool Affects(UIWidget w)
- {
- if (w == null)
- {
- return false;
- }
- UIPanel panel = w.panel;
- if (panel == null)
- {
- return false;
- }
- UIPanel uipanel = this;
- while (uipanel != null)
- {
- if (uipanel == panel)
- {
- return true;
- }
- if (!uipanel.hasCumulativeClipping)
- {
- return false;
- }
- uipanel = uipanel.mParentPanel;
- }
- return false;
- }
- [ContextMenu("Force Refresh")]
- public void RebuildAllDrawCalls()
- {
- this.mRebuild = true;
- }
- public void SetDirty()
- {
- int i = 0;
- int count = this.drawCalls.Count;
- while (i < count)
- {
- if (this.drawCalls[i] != null)
- {
- this.drawCalls[i].isDirty = true;
- }
- i++;
- }
- this.Invalidate(true);
- }
- private void Awake()
- {
- this.mGo = base.gameObject;
- this.mTrans = base.transform;
- this.mHalfPixelOffset = (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.XBOX360 || Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.WindowsEditor);
- if (this.mHalfPixelOffset)
- {
- this.mHalfPixelOffset = (SystemInfo.graphicsShaderLevel < 40 && SystemInfo.graphicsDeviceVersion.Contains("Direct3D"));
- }
- }
- private void FindParent()
- {
- Transform parent = base.cachedTransform.parent;
- this.mParentPanel = ((!(parent != null)) ? null : NGUITools.FindInParents<UIPanel>(parent.gameObject));
- }
- public override void ParentHasChanged()
- {
- base.ParentHasChanged();
- this.FindParent();
- }
- protected override void OnStart()
- {
- this.mLayer = this.mGo.layer;
- }
- protected override void OnEnable()
- {
- this.mRebuild = true;
- this.mAlphaFrameID = -1;
- this.mMatrixFrame = -1;
- this.OnStart();
- base.OnEnable();
- this.mMatrixFrame = -1;
- }
- protected override void OnInit()
- {
- if (UIPanel.list.Contains(this))
- {
- return;
- }
- base.OnInit();
- this.FindParent();
- if (base.GetComponent<Rigidbody>() == null && this.mParentPanel == null)
- {
- UICamera uicamera = (!(base.anchorCamera != null)) ? null : this.mCam.GetComponent<UICamera>();
- if (uicamera != null && (uicamera.eventType == UICamera.EventType.UI_3D || uicamera.eventType == UICamera.EventType.World_3D))
- {
- Rigidbody rigidbody = base.gameObject.AddComponent<Rigidbody>();
- rigidbody.isKinematic = true;
- rigidbody.useGravity = false;
- }
- }
- this.mRebuild = true;
- this.mAlphaFrameID = -1;
- this.mMatrixFrame = -1;
- UIPanel.list.Add(this);
- List<UIPanel> list = UIPanel.list;
- if (UIPanel.<>f__mg$cache1 == null)
- {
- UIPanel.<>f__mg$cache1 = new Comparison<UIPanel>(UIPanel.CompareFunc);
- }
- list.Sort(UIPanel.<>f__mg$cache1);
- }
- protected override void OnDisable()
- {
- int i = 0;
- int count = this.drawCalls.Count;
- while (i < count)
- {
- UIDrawCall uidrawCall = this.drawCalls[i];
- if (uidrawCall != null)
- {
- UIDrawCall.Destroy(uidrawCall);
- }
- i++;
- }
- this.drawCalls.Clear();
- UIPanel.list.Remove(this);
- this.mAlphaFrameID = -1;
- this.mMatrixFrame = -1;
- if (UIPanel.list.Count == 0)
- {
- UIDrawCall.ReleaseAll();
- UIPanel.mUpdateFrame = -1;
- }
- base.OnDisable();
- }
- private void UpdateTransformMatrix()
- {
- int frameCount = Time.frameCount;
- if (this.mMatrixFrame != frameCount)
- {
- this.mMatrixFrame = frameCount;
- this.worldToLocal = base.cachedTransform.worldToLocalMatrix;
- Vector2 vector = this.GetViewSize() * 0.5f;
- float num = this.mClipOffset.x + this.mClipRange.x;
- float num2 = this.mClipOffset.y + this.mClipRange.y;
- this.mMin.x = num - vector.x;
- this.mMin.y = num2 - vector.y;
- this.mMax.x = num + vector.x;
- this.mMax.y = num2 + vector.y;
- }
- }
- protected override void OnAnchor()
- {
- if (this.mClipping == UIDrawCall.Clipping.None)
- {
- return;
- }
- Transform cachedTransform = base.cachedTransform;
- Transform parent = cachedTransform.parent;
- Vector2 viewSize = this.GetViewSize();
- Vector2 vector = cachedTransform.localPosition;
- float num;
- float num2;
- float num3;
- float num4;
- if (this.leftAnchor.target == this.bottomAnchor.target && this.leftAnchor.target == this.rightAnchor.target && this.leftAnchor.target == this.topAnchor.target)
- {
- Vector3[] sides = this.leftAnchor.GetSides(parent);
- if (sides != null)
- {
- num = NGUIMath.Lerp(sides[0].x, sides[2].x, this.leftAnchor.relative) + (float)this.leftAnchor.absolute;
- num2 = NGUIMath.Lerp(sides[0].x, sides[2].x, this.rightAnchor.relative) + (float)this.rightAnchor.absolute;
- num3 = NGUIMath.Lerp(sides[3].y, sides[1].y, this.bottomAnchor.relative) + (float)this.bottomAnchor.absolute;
- num4 = NGUIMath.Lerp(sides[3].y, sides[1].y, this.topAnchor.relative) + (float)this.topAnchor.absolute;
- }
- else
- {
- Vector2 vector2 = base.GetLocalPos(this.leftAnchor, parent);
- num = vector2.x + (float)this.leftAnchor.absolute;
- num3 = vector2.y + (float)this.bottomAnchor.absolute;
- num2 = vector2.x + (float)this.rightAnchor.absolute;
- num4 = vector2.y + (float)this.topAnchor.absolute;
- }
- }
- else
- {
- if (this.leftAnchor.target)
- {
- Vector3[] sides2 = this.leftAnchor.GetSides(parent);
- if (sides2 != null)
- {
- num = NGUIMath.Lerp(sides2[0].x, sides2[2].x, this.leftAnchor.relative) + (float)this.leftAnchor.absolute;
- }
- else
- {
- num = base.GetLocalPos(this.leftAnchor, parent).x + (float)this.leftAnchor.absolute;
- }
- }
- else
- {
- num = this.mClipRange.x - 0.5f * viewSize.x;
- }
- if (this.rightAnchor.target)
- {
- Vector3[] sides3 = this.rightAnchor.GetSides(parent);
- if (sides3 != null)
- {
- num2 = NGUIMath.Lerp(sides3[0].x, sides3[2].x, this.rightAnchor.relative) + (float)this.rightAnchor.absolute;
- }
- else
- {
- num2 = base.GetLocalPos(this.rightAnchor, parent).x + (float)this.rightAnchor.absolute;
- }
- }
- else
- {
- num2 = this.mClipRange.x + 0.5f * viewSize.x;
- }
- if (this.bottomAnchor.target)
- {
- Vector3[] sides4 = this.bottomAnchor.GetSides(parent);
- if (sides4 != null)
- {
- num3 = NGUIMath.Lerp(sides4[3].y, sides4[1].y, this.bottomAnchor.relative) + (float)this.bottomAnchor.absolute;
- }
- else
- {
- num3 = base.GetLocalPos(this.bottomAnchor, parent).y + (float)this.bottomAnchor.absolute;
- }
- }
- else
- {
- num3 = this.mClipRange.y - 0.5f * viewSize.y;
- }
- if (this.topAnchor.target)
- {
- Vector3[] sides5 = this.topAnchor.GetSides(parent);
- if (sides5 != null)
- {
- num4 = NGUIMath.Lerp(sides5[3].y, sides5[1].y, this.topAnchor.relative) + (float)this.topAnchor.absolute;
- }
- else
- {
- num4 = base.GetLocalPos(this.topAnchor, parent).y + (float)this.topAnchor.absolute;
- }
- }
- else
- {
- num4 = this.mClipRange.y + 0.5f * viewSize.y;
- }
- }
- num -= vector.x + this.mClipOffset.x;
- num2 -= vector.x + this.mClipOffset.x;
- num3 -= vector.y + this.mClipOffset.y;
- num4 -= vector.y + this.mClipOffset.y;
- float x = Mathf.Lerp(num, num2, 0.5f);
- float y = Mathf.Lerp(num3, num4, 0.5f);
- float num5 = num2 - num;
- float num6 = num4 - num3;
- float num7 = Mathf.Max(2f, this.mClipSoftness.x);
- float num8 = Mathf.Max(2f, this.mClipSoftness.y);
- if (num5 < num7)
- {
- num5 = num7;
- }
- if (num6 < num8)
- {
- num6 = num8;
- }
- this.baseClipRegion = new Vector4(x, y, num5, num6);
- }
- private void LateUpdate()
- {
- if (UIPanel.mUpdateFrame != Time.frameCount)
- {
- UIPanel.mUpdateFrame = Time.frameCount;
- int i = 0;
- int count = UIPanel.list.Count;
- while (i < count)
- {
- UIPanel.list[i].UpdateSelf();
- i++;
- }
- int num = 3000;
- int j = 0;
- int count2 = UIPanel.list.Count;
- while (j < count2)
- {
- UIPanel uipanel = UIPanel.list[j];
- if (uipanel.renderQueue == UIPanel.RenderQueue.Automatic)
- {
- uipanel.startingRenderQueue = num;
- uipanel.UpdateDrawCalls();
- num += uipanel.drawCalls.Count;
- }
- else if (uipanel.renderQueue == UIPanel.RenderQueue.StartAt)
- {
- uipanel.UpdateDrawCalls();
- if (uipanel.drawCalls.Count != 0)
- {
- num = Mathf.Max(num, uipanel.startingRenderQueue + uipanel.drawCalls.Count);
- }
- }
- else
- {
- uipanel.UpdateDrawCalls();
- if (uipanel.drawCalls.Count != 0)
- {
- num = Mathf.Max(num, uipanel.startingRenderQueue + 1);
- }
- }
- j++;
- }
- }
- }
- private void UpdateSelf()
- {
- this.mUpdateTime = RealTime.time;
- this.UpdateTransformMatrix();
- this.UpdateLayers();
- this.UpdateWidgets();
- if (this.mRebuild)
- {
- this.mRebuild = false;
- this.FillAllDrawCalls();
- }
- else
- {
- int i = 0;
- while (i < this.drawCalls.Count)
- {
- UIDrawCall uidrawCall = this.drawCalls[i];
- if (!(uidrawCall == null))
- {
- if (uidrawCall.isDirty && !this.FillDrawCall(uidrawCall))
- {
- UIDrawCall.Destroy(uidrawCall);
- this.drawCalls.RemoveAt(i);
- }
- else
- {
- i++;
- }
- }
- }
- }
- if (this.mUpdateScroll)
- {
- this.mUpdateScroll = false;
- UIScrollView component = base.GetComponent<UIScrollView>();
- if (component != null)
- {
- component.UpdateScrollbars();
- }
- }
- }
- public void SortWidgets()
- {
- this.mSortWidgets = false;
- List<UIWidget> list = this.widgets;
- if (UIPanel.<>f__mg$cache2 == null)
- {
- UIPanel.<>f__mg$cache2 = new Comparison<UIWidget>(UIWidget.PanelCompareFunc);
- }
- list.Sort(UIPanel.<>f__mg$cache2);
- }
- private void FillAllDrawCalls()
- {
- for (int i = 0; i < this.drawCalls.Count; i++)
- {
- UIDrawCall.Destroy(this.drawCalls[i]);
- }
- this.drawCalls.Clear();
- Material material = null;
- Texture texture = null;
- Shader shader = null;
- UIDrawCall uidrawCall = null;
- int num = 0;
- if (this.mSortWidgets)
- {
- this.SortWidgets();
- }
- for (int j = 0; j < this.widgets.Count; j++)
- {
- UIWidget uiwidget = this.widgets[j];
- if (uiwidget.isVisible && uiwidget.hasVertices)
- {
- Material material2 = uiwidget.material;
- Texture mainTexture = uiwidget.mainTexture;
- Shader shader2 = uiwidget.shader;
- if (material != material2 || texture != mainTexture || shader != shader2)
- {
- if (uidrawCall != null && uidrawCall.verts.size != 0)
- {
- this.drawCalls.Add(uidrawCall);
- uidrawCall.UpdateGeometry(num);
- uidrawCall.onRender = this.mOnRender;
- this.mOnRender = null;
- num = 0;
- uidrawCall = null;
- }
- material = material2;
- texture = mainTexture;
- shader = shader2;
- }
- if (material != null || shader != null || texture != null)
- {
- if (uidrawCall == null)
- {
- uidrawCall = UIDrawCall.Create(this, material, texture, shader);
- uidrawCall.depthStart = uiwidget.depth;
- uidrawCall.depthEnd = uidrawCall.depthStart;
- uidrawCall.panel = this;
- }
- else
- {
- int depth = uiwidget.depth;
- if (depth < uidrawCall.depthStart)
- {
- uidrawCall.depthStart = depth;
- }
- if (depth > uidrawCall.depthEnd)
- {
- uidrawCall.depthEnd = depth;
- }
- }
- uiwidget.drawCall = uidrawCall;
- num++;
- if (this.generateNormals)
- {
- uiwidget.WriteToBuffers(uidrawCall.verts, uidrawCall.uvs, uidrawCall.cols, uidrawCall.norms, uidrawCall.tans);
- }
- else
- {
- uiwidget.WriteToBuffers(uidrawCall.verts, uidrawCall.uvs, uidrawCall.cols, null, null);
- }
- if (uiwidget.mOnRender != null)
- {
- if (this.mOnRender == null)
- {
- this.mOnRender = uiwidget.mOnRender;
- }
- else
- {
- this.mOnRender = (UIDrawCall.OnRenderCallback)Delegate.Combine(this.mOnRender, uiwidget.mOnRender);
- }
- }
- }
- }
- else
- {
- uiwidget.drawCall = null;
- }
- }
- if (uidrawCall != null && uidrawCall.verts.size != 0)
- {
- this.drawCalls.Add(uidrawCall);
- uidrawCall.UpdateGeometry(num);
- uidrawCall.onRender = this.mOnRender;
- this.mOnRender = null;
- }
- }
- private bool FillDrawCall(UIDrawCall dc)
- {
- if (dc != null)
- {
- dc.isDirty = false;
- int num = 0;
- int i = 0;
- while (i < this.widgets.Count)
- {
- UIWidget uiwidget = this.widgets[i];
- if (uiwidget == null)
- {
- this.widgets.RemoveAt(i);
- }
- else
- {
- if (uiwidget.drawCall == dc)
- {
- if (uiwidget.isVisible && uiwidget.hasVertices)
- {
- num++;
- if (this.generateNormals)
- {
- uiwidget.WriteToBuffers(dc.verts, dc.uvs, dc.cols, dc.norms, dc.tans);
- }
- else
- {
- uiwidget.WriteToBuffers(dc.verts, dc.uvs, dc.cols, null, null);
- }
- if (uiwidget.mOnRender != null)
- {
- if (this.mOnRender == null)
- {
- this.mOnRender = uiwidget.mOnRender;
- }
- else
- {
- this.mOnRender = (UIDrawCall.OnRenderCallback)Delegate.Combine(this.mOnRender, uiwidget.mOnRender);
- }
- }
- }
- else
- {
- uiwidget.drawCall = null;
- }
- }
- i++;
- }
- }
- if (dc.verts.size != 0)
- {
- dc.UpdateGeometry(num);
- dc.onRender = this.mOnRender;
- this.mOnRender = null;
- return true;
- }
- }
- return false;
- }
- private void UpdateDrawCalls()
- {
- Transform cachedTransform = base.cachedTransform;
- if (cachedTransform == null)
- {
- return;
- }
- bool usedForUI = this.usedForUI;
- if (this.clipping != UIDrawCall.Clipping.None)
- {
- this.drawCallClipRange = this.finalClipRegion;
- this.drawCallClipRange.z = this.drawCallClipRange.z * 0.5f;
- this.drawCallClipRange.w = this.drawCallClipRange.w * 0.5f;
- }
- else
- {
- this.drawCallClipRange = Vector4.zero;
- }
- if (Application.isPlaying && GameMain.Instance != null && GameMain.Instance.VRMode)
- {
- if (this.drawCallClipRange.z == 0f)
- {
- this.drawCallClipRange.z = 640f;
- }
- if (this.drawCallClipRange.w == 0f)
- {
- this.drawCallClipRange.w = 360f;
- }
- }
- else
- {
- if (this.drawCallClipRange.z == 0f)
- {
- this.drawCallClipRange.z = (float)UICamera.ScreenWidth * 0.5f;
- }
- if (this.drawCallClipRange.w == 0f)
- {
- this.drawCallClipRange.w = (float)UICamera.ScreenHeight * 0.5f;
- }
- }
- if (this.halfPixelOffset)
- {
- this.drawCallClipRange.x = this.drawCallClipRange.x - 0.5f;
- this.drawCallClipRange.y = this.drawCallClipRange.y + 0.5f;
- }
- Vector3 vector;
- if (usedForUI)
- {
- Transform parent = base.cachedTransform.parent;
- vector = base.cachedTransform.localPosition;
- if (this.clipping != UIDrawCall.Clipping.None)
- {
- vector.x = (float)Mathf.RoundToInt(vector.x);
- vector.y = (float)Mathf.RoundToInt(vector.y);
- }
- if (parent != null)
- {
- vector = parent.TransformPoint(vector);
- }
- vector += this.drawCallOffset;
- }
- else
- {
- vector = cachedTransform.position;
- }
- Quaternion rotation = cachedTransform.rotation;
- Vector3 lossyScale = cachedTransform.lossyScale;
- for (int i = 0; i < this.drawCalls.Count; i++)
- {
- UIDrawCall uidrawCall = this.drawCalls[i];
- if (!(uidrawCall == null))
- {
- Transform cachedTransform2 = uidrawCall.cachedTransform;
- cachedTransform2.position = vector;
- cachedTransform2.rotation = rotation;
- cachedTransform2.localScale = lossyScale;
- uidrawCall.renderQueue = ((this.renderQueue != UIPanel.RenderQueue.Explicit) ? (this.startingRenderQueue + i) : this.startingRenderQueue);
- uidrawCall.alwaysOnScreen = (this.alwaysOnScreen && (this.mClipping == UIDrawCall.Clipping.None || this.mClipping == UIDrawCall.Clipping.ConstrainButDontClip));
- uidrawCall.sortingOrder = this.mSortingOrder;
- uidrawCall.clipTexture = this.mClipTexture;
- }
- }
- }
- private void UpdateLayers()
- {
- if (this.mLayer != base.cachedGameObject.layer)
- {
- this.mLayer = this.mGo.layer;
- NGUITools.SetChildLayer(base.cachedTransform, this.mLayer);
- base.ResetAnchors();
- for (int i = 0; i < this.drawCalls.Count; i++)
- {
- if (this.drawCalls[i] != null)
- {
- this.drawCalls[i].gameObject.layer = this.mLayer;
- }
- }
- }
- }
- private void UpdateWidgets()
- {
- bool flag = !this.cullWhileDragging && this.mCullTime > this.mUpdateTime;
- bool flag2 = false;
- if (this.mForced != flag)
- {
- this.mForced = flag;
- this.mResized = true;
- }
- bool hasCumulativeClipping = this.hasCumulativeClipping;
- int i = 0;
- int count = this.widgets.Count;
- while (i < count)
- {
- UIWidget uiwidget = this.widgets[i];
- if (uiwidget.panel == this && uiwidget.enabled)
- {
- int frameCount = Time.frameCount;
- if (uiwidget.UpdateTransform(frameCount) || this.mResized)
- {
- bool visibleByAlpha = flag || uiwidget.CalculateCumulativeAlpha(frameCount) > 0.001f;
- uiwidget.UpdateVisibility(visibleByAlpha, flag || (!hasCumulativeClipping && !uiwidget.hideIfOffScreen) || this.IsVisible(uiwidget));
- }
- if (uiwidget.UpdateGeometry(frameCount))
- {
- flag2 = true;
- if (!this.mRebuild)
- {
- if (uiwidget.drawCall != null)
- {
- uiwidget.drawCall.isDirty = true;
- }
- else
- {
- this.FindDrawCall(uiwidget);
- }
- }
- }
- }
- i++;
- }
- if (flag2 && this.onGeometryUpdated != null)
- {
- this.onGeometryUpdated();
- }
- this.mResized = false;
- }
- public UIDrawCall FindDrawCall(UIWidget w)
- {
- Material material = w.material;
- Texture mainTexture = w.mainTexture;
- int depth = w.depth;
- for (int i = 0; i < this.drawCalls.Count; i++)
- {
- UIDrawCall uidrawCall = this.drawCalls[i];
- if (!(uidrawCall == null))
- {
- int num = (i != 0) ? (this.drawCalls[i - 1].depthEnd + 1) : int.MinValue;
- int num2 = (i + 1 != this.drawCalls.Count) ? (this.drawCalls[i + 1].depthStart - 1) : int.MaxValue;
- if (num <= depth && num2 >= depth)
- {
- if (uidrawCall.baseMaterial == material && uidrawCall.mainTexture == mainTexture)
- {
- if (w.isVisible)
- {
- w.drawCall = uidrawCall;
- if (w.hasVertices)
- {
- uidrawCall.isDirty = true;
- }
- return uidrawCall;
- }
- }
- else
- {
- this.mRebuild = true;
- }
- return null;
- }
- }
- }
- this.mRebuild = true;
- return null;
- }
- public void AddWidget(UIWidget w)
- {
- this.mUpdateScroll = true;
- if (this.widgets.Count == 0)
- {
- this.widgets.Add(w);
- }
- else if (this.mSortWidgets)
- {
- this.widgets.Add(w);
- this.SortWidgets();
- }
- else if (UIWidget.PanelCompareFunc(w, this.widgets[0]) == -1)
- {
- this.widgets.Insert(0, w);
- }
- else
- {
- int i = this.widgets.Count;
- while (i > 0)
- {
- if (UIWidget.PanelCompareFunc(w, this.widgets[--i]) != -1)
- {
- this.widgets.Insert(i + 1, w);
- break;
- }
- }
- }
- this.FindDrawCall(w);
- }
- public void RemoveWidget(UIWidget w)
- {
- if (this.widgets.Remove(w) && w.drawCall != null)
- {
- int depth = w.depth;
- if (depth == w.drawCall.depthStart || depth == w.drawCall.depthEnd)
- {
- this.mRebuild = true;
- }
- w.drawCall.isDirty = true;
- w.drawCall = null;
- }
- }
- public void Refresh()
- {
- this.mRebuild = true;
- UIPanel.mUpdateFrame = -1;
- if (UIPanel.list.Count > 0)
- {
- UIPanel.list[0].LateUpdate();
- }
- }
- public virtual Vector3 CalculateConstrainOffset(Vector2 min, Vector2 max)
- {
- Vector4 finalClipRegion = this.finalClipRegion;
- float num = finalClipRegion.z * 0.5f;
- float num2 = finalClipRegion.w * 0.5f;
- Vector2 minRect = new Vector2(min.x, min.y);
- Vector2 maxRect = new Vector2(max.x, max.y);
- Vector2 minArea = new Vector2(finalClipRegion.x - num, finalClipRegion.y - num2);
- Vector2 maxArea = new Vector2(finalClipRegion.x + num, finalClipRegion.y + num2);
- if (this.softBorderPadding && this.clipping == UIDrawCall.Clipping.SoftClip)
- {
- minArea.x += this.mClipSoftness.x;
- minArea.y += this.mClipSoftness.y;
- maxArea.x -= this.mClipSoftness.x;
- maxArea.y -= this.mClipSoftness.y;
- }
- return NGUIMath.ConstrainRect(minRect, maxRect, minArea, maxArea);
- }
- public bool ConstrainTargetToBounds(Transform target, ref Bounds targetBounds, bool immediate)
- {
- Vector3 vector = targetBounds.min;
- Vector3 vector2 = targetBounds.max;
- float num = 1f;
- if (this.mClipping == UIDrawCall.Clipping.None)
- {
- UIRoot root = base.root;
- if (root != null)
- {
- num = root.pixelSizeAdjustment;
- }
- }
- if (num != 1f)
- {
- vector /= num;
- vector2 /= num;
- }
- Vector3 b = this.CalculateConstrainOffset(vector, vector2) * num;
- if (b.sqrMagnitude > 0f)
- {
- if (immediate)
- {
- target.localPosition += b;
- targetBounds.center += b;
- SpringPosition component = target.GetComponent<SpringPosition>();
- if (component != null)
- {
- component.enabled = false;
- }
- }
- else
- {
- SpringPosition springPosition = SpringPosition.Begin(target.gameObject, target.localPosition + b, 13f);
- springPosition.ignoreTimeScale = true;
- springPosition.worldSpace = false;
- }
- return true;
- }
- return false;
- }
- public bool ConstrainTargetToBounds(Transform target, bool immediate)
- {
- Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(base.cachedTransform, target);
- return this.ConstrainTargetToBounds(target, ref bounds, immediate);
- }
- public static UIPanel Find(Transform trans)
- {
- return UIPanel.Find(trans, false, -1);
- }
- public static UIPanel Find(Transform trans, bool createIfMissing)
- {
- return UIPanel.Find(trans, createIfMissing, -1);
- }
- public static UIPanel Find(Transform trans, bool createIfMissing, int layer)
- {
- UIPanel uipanel = NGUITools.FindInParents<UIPanel>(trans);
- if (uipanel != null)
- {
- return uipanel;
- }
- return (!createIfMissing) ? null : NGUITools.CreateUI(trans, false, layer);
- }
- private Vector2 GetWindowSize()
- {
- UIRoot root = base.root;
- Vector2 vector = NGUITools.screenSize;
- if (root != null)
- {
- vector *= root.GetPixelSizeAdjustment(Mathf.RoundToInt(vector.y));
- }
- return vector;
- }
- public Vector2 GetViewSize()
- {
- if (this.mClipping != UIDrawCall.Clipping.None)
- {
- return new Vector2(this.mClipRange.z, this.mClipRange.w);
- }
- return NGUITools.screenSize;
- }
- public static List<UIPanel> list = new List<UIPanel>();
- public UIPanel.OnGeometryUpdated onGeometryUpdated;
- public bool showInPanelTool = true;
- public bool generateNormals;
- public bool widgetsAreStatic;
- public bool cullWhileDragging = true;
- public bool alwaysOnScreen;
- public bool anchorOffset;
- public bool softBorderPadding = true;
- public UIPanel.RenderQueue renderQueue;
- public int startingRenderQueue = 3000;
- [NonSerialized]
- public List<UIWidget> widgets = new List<UIWidget>();
- [NonSerialized]
- public List<UIDrawCall> drawCalls = new List<UIDrawCall>();
- [NonSerialized]
- public Matrix4x4 worldToLocal = Matrix4x4.identity;
- [NonSerialized]
- public Vector4 drawCallClipRange = new Vector4(0f, 0f, 1f, 1f);
- public UIPanel.OnClippingMoved onClipMove;
- [HideInInspector]
- [SerializeField]
- private Texture2D mClipTexture;
- [HideInInspector]
- [SerializeField]
- private float mAlpha = 1f;
- [HideInInspector]
- [SerializeField]
- private UIDrawCall.Clipping mClipping;
- [HideInInspector]
- [SerializeField]
- private Vector4 mClipRange = new Vector4(0f, 0f, 300f, 200f);
- [HideInInspector]
- [SerializeField]
- private Vector2 mClipSoftness = new Vector2(4f, 4f);
- [HideInInspector]
- [SerializeField]
- private int mDepth;
- [HideInInspector]
- [SerializeField]
- private int mSortingOrder;
- private bool mRebuild;
- private bool mResized;
- [SerializeField]
- private Vector2 mClipOffset = Vector2.zero;
- private float mCullTime;
- private float mUpdateTime;
- private int mMatrixFrame = -1;
- private int mAlphaFrameID;
- private int mLayer = -1;
- private static float[] mTemp = new float[4];
- private Vector2 mMin = Vector2.zero;
- private Vector2 mMax = Vector2.zero;
- private bool mHalfPixelOffset;
- private bool mSortWidgets;
- private bool mUpdateScroll;
- private UIPanel mParentPanel;
- private static Vector3[] mCorners = new Vector3[4];
- private static int mUpdateFrame = -1;
- private UIDrawCall.OnRenderCallback mOnRender;
- private bool mForced;
- [CompilerGenerated]
- private static Comparison<UIPanel> <>f__mg$cache0;
- [CompilerGenerated]
- private static Comparison<UIPanel> <>f__mg$cache1;
- [CompilerGenerated]
- private static Comparison<UIWidget> <>f__mg$cache2;
- public enum RenderQueue
- {
- Automatic,
- StartAt,
- Explicit
- }
- public delegate void OnGeometryUpdated();
- public delegate void OnClippingMoved(UIPanel panel);
- }
|