private void OnClick() { if (((this.mChild == null) && (this.atlas != null)) && ((this.font != null) && (this.items.Count > 1))) { this.mLabelList.Clear(); this.handleEvents = true; if (this.mPanel == null) { this.mPanel = UIPanel.Find(base.transform, true); } Transform child = base.transform; AABBox box = NGUIMath.CalculateRelativeWidgetBounds(child.parent, child); this.mChild = new GameObject("Drop-down List"); this.mChild.layer = base.gameObject.layer; Transform transform = this.mChild.transform; transform.parent = child.parent; transform.localPosition = box.min; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; this.mBackground = NGUITools.AddSprite(this.mChild, this.atlas, this.backgroundSprite); this.mBackground.pivot = UIWidget.Pivot.TopLeft; this.mBackground.depth = NGUITools.CalculateNextDepth(this.mPanel.gameObject); this.mBackground.color = this.backgroundColor; Vector4 border = this.mBackground.border; this.mBgBorder = border.y; this.mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f); this.mHighlight = NGUITools.AddSprite(this.mChild, this.atlas, this.highlightSprite); this.mHighlight.pivot = UIWidget.Pivot.TopLeft; this.mHighlight.color = this.highlightColor; UIAtlas.Sprite sprite = this.mHighlight.sprite; float num = sprite.inner.yMin - sprite.outer.yMin; float num2 = this.font.size * this.textScale; float a = 0f; float y = -this.padding.y; System.Collections.Generic.List <UILabel> list = new System.Collections.Generic.List <UILabel>(); int num5 = 0; int count = this.items.Count; while (num5 < count) { string key = this.items[num5]; UILabel item = NGUITools.AddWidget <UILabel>(this.mChild); item.pivot = UIWidget.Pivot.TopLeft; item.font = this.font; item.text = (!this.isLocalized || (Localization.instance == null)) ? key : Localization.instance.Get(key); item.color = this.textColor; item.cachedTransform.localPosition = new Vector3(border.x, y, 0f); item.MakePixelPerfect(); if (this.textScale != 1f) { Vector3 localScale = item.cachedTransform.localScale; item.cachedTransform.localScale = (Vector3)(localScale * this.textScale); } list.Add(item); y -= num2; y -= this.padding.y; a = Mathf.Max(a, item.relativeSize.x * num2); UIEventListener listener = UIEventListener.Get(item.gameObject); listener.onHover = new UIEventListener.BoolDelegate(this.OnItemHover); listener.onPress = new UIEventListener.BoolDelegate(this.OnItemPress); listener.parameter = key; if (this.mSelectedItem == key) { this.Highlight(item, true); } this.mLabelList.Add(item); num5++; } a = Mathf.Max(a, box.size.x - (border.x * 2f)); Vector3 vector3 = new Vector3((a * 0.5f) / num2, -0.5f, 0f); Vector3 vector4 = new Vector3(a / num2, (num2 + this.padding.y) / num2, 1f); int num7 = 0; int num8 = list.Count; while (num7 < num8) { UILabel label2 = list[num7]; UIHotSpot spot = NGUITools.AddWidgetHotSpot(label2.gameObject); vector3.z = spot.center.z; spot.center = vector3; spot.size = vector4; num7++; } a += border.x * 2f; y -= border.y; this.mBackground.cachedTransform.localScale = new Vector3(a, -y + border.y, 1f); this.mHighlight.cachedTransform.localScale = new Vector3((a - (border.x * 2f)) + ((sprite.inner.xMin - sprite.outer.xMin) * 2f), num2 + (num * 2f), 1f); bool placeAbove = this.position == Position.Above; if (this.position == Position.Auto) { UICamera camera = UICamera.FindCameraForLayer(base.gameObject.layer); if (camera != null) { placeAbove = camera.cachedCamera.WorldToViewportPoint(child.position).y < 0.5f; } } if (this.isAnimated) { float bottom = y + num2; this.Animate(this.mHighlight, placeAbove, bottom); int num10 = 0; int num11 = list.Count; while (num10 < num11) { this.Animate(list[num10], placeAbove, bottom); num10++; } this.AnimateColor(this.mBackground); this.AnimateScale(this.mBackground, placeAbove, bottom); } if (placeAbove) { transform.localPosition = new Vector3(box.min.x, (box.max.y - y) - border.y, box.min.z); } } else { this.OnSelect(false); } }
private void OnClick() { if (!(this.mChild == null) || !(this.atlas != null) || !(this.font != null) || this.items.Count <= 1) { this.OnSelect(false); } else { this.mLabelList.Clear(); this.handleEvents = true; if (this.mPanel == null) { this.mPanel = UIPanel.Find(base.transform, true); } Transform transforms = base.transform; AABBox aABBox = NGUIMath.CalculateRelativeWidgetBounds(transforms.parent, transforms); this.mChild = new GameObject("Drop-down List") { layer = base.gameObject.layer }; Transform vector3 = this.mChild.transform; vector3.parent = transforms.parent; vector3.localPosition = aABBox.min; vector3.localRotation = Quaternion.identity; vector3.localScale = Vector3.one; this.mBackground = NGUITools.AddSprite(this.mChild, this.atlas, this.backgroundSprite); this.mBackground.pivot = UIWidget.Pivot.TopLeft; this.mBackground.depth = NGUITools.CalculateNextDepth(this.mPanel.gameObject); this.mBackground.color = this.backgroundColor; Vector4 vector4 = this.mBackground.border; this.mBgBorder = vector4.y; this.mBackground.cachedTransform.localPosition = new Vector3(0f, vector4.y, 0f); this.mHighlight = NGUITools.AddSprite(this.mChild, this.atlas, this.highlightSprite); this.mHighlight.pivot = UIWidget.Pivot.TopLeft; this.mHighlight.color = this.highlightColor; UIAtlas.Sprite sprite = this.mHighlight.sprite; float single = sprite.inner.yMin - sprite.outer.yMin; float single1 = (float)this.font.size * this.textScale; float single2 = 0f; float single3 = -this.padding.y; List <UILabel> uILabels = new List <UILabel>(); int num = 0; int count = this.items.Count; while (num < count) { string item = this.items[num]; UILabel uILabel = NGUITools.AddWidget <UILabel>(this.mChild); uILabel.pivot = UIWidget.Pivot.TopLeft; uILabel.font = this.font; uILabel.text = (!this.isLocalized || !(Localization.instance != null) ? item : Localization.instance.Get(item)); uILabel.color = this.textColor; uILabel.cachedTransform.localPosition = new Vector3(vector4.x, single3, 0f); uILabel.MakePixelPerfect(); if (this.textScale != 1f) { Vector3 vector31 = uILabel.cachedTransform.localScale; uILabel.cachedTransform.localScale = vector31 * this.textScale; } uILabels.Add(uILabel); single3 = single3 - single1; single3 = single3 - this.padding.y; Vector2 vector2 = uILabel.relativeSize; single2 = Mathf.Max(single2, vector2.x * single1); UIEventListener boolDelegate = UIEventListener.Get(uILabel.gameObject); boolDelegate.onHover = new UIEventListener.BoolDelegate(this.OnItemHover); boolDelegate.onPress = new UIEventListener.BoolDelegate(this.OnItemPress); boolDelegate.parameter = item; if (this.mSelectedItem == item) { this.Highlight(uILabel, true); } this.mLabelList.Add(uILabel); num++; } Vector3 vector32 = aABBox.size; single2 = Mathf.Max(single2, vector32.x - vector4.x * 2f); Vector3 vector33 = new Vector3(single2 * 0.5f / single1, -0.5f, 0f); Vector3 vector34 = new Vector3(single2 / single1, (single1 + this.padding.y) / single1, 1f); int num1 = 0; int count1 = uILabels.Count; while (num1 < count1) { UIHotSpot uIHotSpot = NGUITools.AddWidgetHotSpot(uILabels[num1].gameObject); vector33.z = uIHotSpot.center.z; uIHotSpot.center = vector33; uIHotSpot.size = vector34; num1++; } single2 = single2 + vector4.x * 2f; single3 = single3 - vector4.y; this.mBackground.cachedTransform.localScale = new Vector3(single2, -single3 + vector4.y, 1f); this.mHighlight.cachedTransform.localScale = new Vector3(single2 - vector4.x * 2f + (sprite.inner.xMin - sprite.outer.xMin) * 2f, single1 + single * 2f, 1f); bool flag = this.position == UIPopupList.Position.Above; if (this.position == UIPopupList.Position.Auto) { UICamera uICamera = UICamera.FindCameraForLayer(base.gameObject.layer); if (uICamera != null) { Vector3 viewportPoint = uICamera.cachedCamera.WorldToViewportPoint(transforms.position); flag = viewportPoint.y < 0.5f; } } if (this.isAnimated) { float single4 = single3 + single1; this.Animate(this.mHighlight, flag, single4); int num2 = 0; int count2 = uILabels.Count; while (num2 < count2) { this.Animate(uILabels[num2], flag, single4); num2++; } this.AnimateColor(this.mBackground); this.AnimateScale(this.mBackground, flag, single4); } if (flag) { float single5 = aABBox.min.x; Vector3 vector35 = aABBox.max; float single6 = vector35.y - single3 - vector4.y; Vector3 vector36 = aABBox.min; vector3.localPosition = new Vector3(single5, single6, vector36.z); } } }