/// <summary> /// 右边自己的UI /// </summary> /// <param name="text"></param> private void SetChatMsgUI_Right(ChatInfo text) { Vector3 origin = m_trans_redPacket.localPosition; m_trans_redPacket.localPosition = new Vector3(187, origin.y, 0); if (m_headIcon != null) { //m_headIcon.ChangeSprite(text.job); //m_headIcon.MakePixelPerfect(); m_headIcon.transform.localPosition = new Vector3(m_panelWidth * 0.5f - BorderX - m_headIcon.width, 0, 0); table.SelectRoleDataBase sdb = table.SelectRoleDataBase.Where((GameCmd.enumProfession)text.job, (GameCmd.enmCharSex) 1); if (sdb != null) { UIManager.GetTextureAsyn(sdb.strprofessionIcon, ref iuiIcon, () => { if (m_headIcon != null) { m_headIcon.mainTexture = null; } }, m_headIcon, false); } } if (m_spriteNameBg != null) { m_spriteNameBg.enabled = false; } m_lableChannel.text = ""; m_lableName.text = ""; UISprite sp = m_bgSprite as UISprite; sp.spriteName = "biankuang_duihuayou"; m_bgSprite.width = GetMaxWidth() - 10;//右边小箭头 if (!string.IsNullOrEmpty(text.voiceFileid)) { m_goVoiceTip.gameObject.SetActive(false); //m_spriteVoiceBg.transform.localPosition = new UnityEngine.Vector3(85, -57, 0); m_goVoice.SetActive(true); m_labelVoice.text = string.Format("{0}'", text.voiceLegth.ToString()); m_normalRichTextContext.offset = new Vector2(15f, 0); //没有执行AddNewLine()先指定m_layout m_normalRichTextContext.m_layout = new Vector2(15f, -60f); } else { m_goVoice.gameObject.SetActive(false); m_normalRichTextContext.offset = new Vector2(15f, 0); //没有执行AddNewLine()先指定m_layout m_normalRichTextContext.m_layout = new Vector2(15f, -10f); } m_normalRichTextContext.AddXml(text.Content); m_bgSprite.height = Mathf.CeilToInt(-m_normalRichTextContext.m_layout.y) + 10; if (m_normalRichTextContext.overline) { m_bgSprite.width = GetMaxWidth(); } else { m_bgSprite.width = Mathf.CeilToInt(m_normalRichTextContext.m_layout.x) + 25; } if (!string.IsNullOrEmpty(text.voiceFileid)) { if (m_bgSprite.width < VOICEBGWIDTH) { m_bgSprite.width = VOICEBGWIDTH; } float posx = m_headIcon.transform.localPosition.x - BorderX - m_bgSprite.width; m_bgSprite.transform.localPosition = new Vector3(posx, -m_headIcon.height * 0.5f, 0); posx = m_headIcon.transform.localPosition.x - m_spriteVoiceBg.width * 0.5f - 40; m_goVoice.transform.localPosition = new UnityEngine.Vector3(posx, -m_headIcon.height * 0.5f - 28, 0); m_goVoice.transform.localRotation = Quaternion.Euler(new Vector3(0, 180, 0)); m_labelVoice.transform.localRotation = Quaternion.Euler(new Vector3(0, 180, 0)); m_labelVoice.transform.localPosition = new UnityEngine.Vector3(-m_labelVoice.transform.localPosition.x, 0, 0); } else { float posx = m_headIcon.transform.localPosition.x - BorderX - m_bgSprite.width; m_bgSprite.transform.localPosition = new Vector3(posx, -m_headIcon.height * 0.5f, 0); } bound = NGUIMath.CalculateRelativeWidgetBounds(transform, false); }
// Token: 0x060036D8 RID: 14040 RVA: 0x0011842C File Offset: 0x0011682C private void Update() { if (this.mAnim != null && this.mAnim.isPlaying) { return; } if (this.style != UIStretch.Style.None) { UIWidget uiwidget = (!(this.container == null)) ? this.container.GetComponent <UIWidget>() : null; UIPanel uipanel = (!(this.container == null) || !(uiwidget == null)) ? this.container.GetComponent <UIPanel>() : null; float num = 1f; if (uiwidget != null) { Bounds bounds = uiwidget.CalculateBounds(base.transform.parent); this.mRect.x = bounds.min.x; this.mRect.y = bounds.min.y; this.mRect.width = bounds.size.x; this.mRect.height = bounds.size.y; } else if (uipanel != null) { if (uipanel.clipping == UIDrawCall.Clipping.None) { float num2 = (!(this.mRoot != null)) ? 0.5f : ((float)this.mRoot.activeHeight / (float)Screen.height * 0.5f); this.mRect.xMin = (float)(-(float)Screen.width) * num2; this.mRect.yMin = (float)(-(float)Screen.height) * num2; this.mRect.xMax = -this.mRect.xMin; this.mRect.yMax = -this.mRect.yMin; } else { Vector4 finalClipRegion = uipanel.finalClipRegion; this.mRect.x = finalClipRegion.x - finalClipRegion.z * 0.5f; this.mRect.y = finalClipRegion.y - finalClipRegion.w * 0.5f; this.mRect.width = finalClipRegion.z; this.mRect.height = finalClipRegion.w; } } else if (this.container != null) { Transform parent = base.transform.parent; Bounds bounds2 = (!(parent != null)) ? NGUIMath.CalculateRelativeWidgetBounds(this.container.transform) : NGUIMath.CalculateRelativeWidgetBounds(parent, this.container.transform); this.mRect.x = bounds2.min.x; this.mRect.y = bounds2.min.y; this.mRect.width = bounds2.size.x; this.mRect.height = bounds2.size.y; } else { if (!(this.uiCamera != null)) { return; } this.mRect = this.uiCamera.pixelRect; if (this.mRoot != null) { num = this.mRoot.pixelSizeAdjustment; } } float num3 = this.mRect.width; float num4 = this.mRect.height; if (num != 1f && num4 > 1f) { float num5 = (float)this.mRoot.activeHeight / num4; num3 *= num5; num4 *= num5; } Vector3 vector = (!(this.mWidget != null)) ? this.mTrans.localScale : new Vector3((float)this.mWidget.width, (float)this.mWidget.height); if (this.style == UIStretch.Style.BasedOnHeight) { vector.x = this.relativeSize.x * num4; vector.y = this.relativeSize.y * num4; } else if (this.style == UIStretch.Style.FillKeepingRatio) { float num6 = num3 / num4; float num7 = this.initialSize.x / this.initialSize.y; if (num7 < num6) { float num8 = num3 / this.initialSize.x; vector.x = num3; vector.y = this.initialSize.y * num8; } else { float num9 = num4 / this.initialSize.y; vector.x = this.initialSize.x * num9; vector.y = num4; } } else if (this.style == UIStretch.Style.FitInternalKeepingRatio) { float num10 = num3 / num4; float num11 = this.initialSize.x / this.initialSize.y; if (num11 > num10) { float num12 = num3 / this.initialSize.x; vector.x = num3; vector.y = this.initialSize.y * num12; } else { float num13 = num4 / this.initialSize.y; vector.x = this.initialSize.x * num13; vector.y = num4; } } else { if (this.style != UIStretch.Style.Vertical) { vector.x = this.relativeSize.x * num3; } if (this.style != UIStretch.Style.Horizontal) { vector.y = this.relativeSize.y * num4; } } if (this.mSprite != null) { float num14 = (!(this.mSprite.atlas != null)) ? 1f : this.mSprite.atlas.pixelSize; vector.x -= this.borderPadding.x * num14; vector.y -= this.borderPadding.y * num14; if (this.style != UIStretch.Style.Vertical) { this.mSprite.width = Mathf.RoundToInt(vector.x); } if (this.style != UIStretch.Style.Horizontal) { this.mSprite.height = Mathf.RoundToInt(vector.y); } vector = Vector3.one; } else if (this.mWidget != null) { if (this.style != UIStretch.Style.Vertical) { this.mWidget.width = Mathf.RoundToInt(vector.x - this.borderPadding.x); } if (this.style != UIStretch.Style.Horizontal) { this.mWidget.height = Mathf.RoundToInt(vector.y - this.borderPadding.y); } vector = Vector3.one; } else if (this.mPanel != null) { Vector4 baseClipRegion = this.mPanel.baseClipRegion; if (this.style != UIStretch.Style.Vertical) { baseClipRegion.z = vector.x - this.borderPadding.x; } if (this.style != UIStretch.Style.Horizontal) { baseClipRegion.w = vector.y - this.borderPadding.y; } this.mPanel.baseClipRegion = baseClipRegion; vector = Vector3.one; } else { if (this.style != UIStretch.Style.Vertical) { vector.x -= this.borderPadding.x; } if (this.style != UIStretch.Style.Horizontal) { vector.y -= this.borderPadding.y; } } if (this.mTrans.localScale != vector) { this.mTrans.localScale = vector; } if (this.runOnlyOnce && Application.isPlaying) { base.enabled = false; } } }
public void AddChips(byte bViewID, long nUserChip, byte chipArea, Vector3 point) { int nChipCount = _chiplist.Count; float x, y, x1, x2, y1, y2, z; //计算筹码 GameObject obj = Instantiate(ChipPrefabs, Vector3.zero, Quaternion.Euler(new Vector3(0f, 0f, 0f))) as GameObject; // GameObject obj = (GameObject)Instantiate (ChipPrefabs); obj.transform.parent = transform; obj.transform.localScale = new Vector3(1, 1, 1); obj.GetComponent <UISprite>().depth = BaseDepth; if (bViewID != (byte)GameEngine.Instance.MySelf.DeskStation) { bounds = NGUIMath.CalculateRelativeWidgetBounds(Area_Chips.transform); x = UnityEngine.Random.Range(0, bounds.size.x) - bounds.size.x / 2; y = UnityEngine.Random.Range(0, bounds.size.y / 2) - bounds.size.y / 3; vec = new Vector3(x, y, 0); obj.transform.localPosition = vec; } else { obj.transform.position = point; } // for(int i=1; i<4; i++) // { // obj.transform.FindChild("effect"+i).GetComponent<UISprite>().spriteName = "blank"; // } switch (nUserChip) { case 1: obj.GetComponent <UISprite>().spriteName = "chip_1"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 5: obj.GetComponent <UISprite>().spriteName = "chip_5"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 10: obj.GetComponent <UISprite>().spriteName = "chip_10"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 50: obj.GetComponent <UISprite>().spriteName = "chip_50"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 100: obj.GetComponent <UISprite>().spriteName = "chip_100"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 500: obj.GetComponent <UISprite>().spriteName = "chip_500"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 1000: obj.GetComponent <UISprite>().spriteName = "chip_1000"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 5000: obj.GetComponent <UISprite>().spriteName = "chip_5000"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 10000: obj.GetComponent <UISprite>().spriteName = "chip_1w"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 50000: obj.GetComponent <UISprite>().spriteName = "chip_5w"; obj.transform.FindChild("effect1").gameObject.SetActive(true); break; case 100000: obj.GetComponent <UISprite>().spriteName = "chip_10w"; obj.transform.FindChild("effect2").gameObject.SetActive(true); break; case 500000: obj.GetComponent <UISprite>().spriteName = "chip_50w"; obj.transform.FindChild("effect2").gameObject.SetActive(true); break; case 1000000: obj.GetComponent <UISprite>().spriteName = "chip_100w"; obj.transform.FindChild("effect3").gameObject.SetActive(true); break; } _chiplist.Add(obj); }
/// <summary> /// Show the popup list dialog. /// </summary> public void Show() { if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0) { mLabelList.Clear(); // Automatically locate the panel responsible for this object if (mPanel == null) { mPanel = UIPanel.Find(transform); if (mPanel == null) { return; } } // Disable the navigation script handleEvents = true; // Calculate the dimensions of the object triggering the popup list so we can position it below it Transform myTrans = transform; Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans); // Create the root object for the list mChild = new GameObject("Drop-down List"); mChild.layer = gameObject.layer; Transform t = mChild.transform; t.parent = myTrans.parent; Vector3 min; Vector3 max; Vector3 pos; // Manually triggered popup list on some other game object if (openOn == OpenOn.Manual && UICamera.selectedObject != gameObject && bounds.size == Vector3.zero) { StopCoroutine("CloseIfUnselected"); min = t.parent.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(UICamera.lastTouchPosition)); max = min; t.localPosition = min; pos = t.position; StartCoroutine("CloseIfUnselected"); } else { min = bounds.min; max = bounds.max; t.localPosition = min; pos = myTrans.position; } t.localRotation = Quaternion.identity; t.localScale = Vector3.one; // Add a sprite for the background mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite); mBackground.pivot = UIWidget.Pivot.TopLeft; mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject); mBackground.color = backgroundColor; // We need to know the size of the background sprite for padding purposes Vector4 bgPadding = mBackground.border; mBgBorder = bgPadding.y; mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f); // Add a sprite used for the selection mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite); mHighlight.pivot = UIWidget.Pivot.TopLeft; mHighlight.color = highlightColor; UISpriteData hlsp = mHighlight.GetAtlasSprite(); if (hlsp == null) { return; } float hlspHeight = hlsp.borderTop; float fontHeight = activeFontSize; float dynScale = activeFontScale; float labelHeight = fontHeight * dynScale; float x = 0f, y = -padding.y; List <UILabel> labels = new List <UILabel>(); // Clear the selection if it's no longer present if (!items.Contains(mSelectedItem)) { mSelectedItem = null; } // Run through all items and create labels for each one for (int i = 0, imax = items.Count; i < imax; ++i) { string s = items[i]; UILabel lbl = NGUITools.AddWidget <UILabel>(mChild); lbl.name = i.ToString(); lbl.pivot = UIWidget.Pivot.TopLeft; lbl.bitmapFont = bitmapFont; lbl.trueTypeFont = trueTypeFont; lbl.fontSize = fontSize; lbl.fontStyle = fontStyle; lbl.text = isLocalized ? Localization.Get(s) : s; lbl.color = textColor; lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x - lbl.pivotOffset.x, y, -1f); lbl.overflowMethod = UILabel.Overflow.ResizeFreely; lbl.alignment = alignment; labels.Add(lbl); y -= labelHeight; y -= padding.y; x = Mathf.Max(x, lbl.printedSize.x); // Add an event listener UIEventListener listener = UIEventListener.Get(lbl.gameObject); listener.onHover = OnItemHover; listener.onPress = OnItemPress; listener.onClick = OnItemClick; listener.parameter = s; // Move the selection here if this is the right label if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem))) { Highlight(lbl, true); } // Add this label to the list mLabelList.Add(lbl); } // The triggering widget's width should be the minimum allowed width x = Mathf.Max(x, bounds.size.x * dynScale - (bgPadding.x + padding.x) * 2f); float cx = x; Vector3 bcCenter = new Vector3(cx * 0.5f, -labelHeight * 0.5f, 0f); Vector3 bcSize = new Vector3(cx, (labelHeight + padding.y), 1f); // Run through all labels and add colliders for (int i = 0, imax = labels.Count; i < imax; ++i) { UILabel lbl = labels[i]; NGUITools.AddWidgetCollider(lbl.gameObject); lbl.autoResizeBoxCollider = false; BoxCollider bc = lbl.GetComponent <BoxCollider>(); if (bc != null) { bcCenter.z = bc.center.z; bc.center = bcCenter; bc.size = bcSize; } else { BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>(); #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 b2d.center = bcCenter; #else b2d.offset = bcCenter; #endif b2d.size = bcSize; } } int lblWidth = Mathf.RoundToInt(x); x += (bgPadding.x + padding.x) * 2f; y -= bgPadding.y; // Scale the background sprite to envelop the entire set of items mBackground.width = Mathf.RoundToInt(x); mBackground.height = Mathf.RoundToInt(-y + bgPadding.y); // Set the label width to make alignment work for (int i = 0, imax = labels.Count; i < imax; ++i) { UILabel lbl = labels[i]; lbl.overflowMethod = UILabel.Overflow.ShrinkContent; lbl.width = lblWidth; } // Scale the highlight sprite to envelop a single item float scaleFactor = 2f * atlas.pixelSize; float w = x - (bgPadding.x + padding.x) * 2f + hlsp.borderLeft * scaleFactor; float h = labelHeight + hlspHeight * scaleFactor; mHighlight.width = Mathf.RoundToInt(w); mHighlight.height = Mathf.RoundToInt(h); bool placeAbove = (position == Position.Above); if (position == Position.Auto) { UICamera cam = UICamera.FindCameraForLayer((UICamera.selectedObject ?? gameObject).layer); if (cam != null) { Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(pos); placeAbove = (viewPos.y < 0.5f); } } // If the list should be animated, let's animate it by expanding it if (isAnimated) { float bottom = y + labelHeight; Animate(mHighlight, placeAbove, bottom); for (int i = 0, imax = labels.Count; i < imax; ++i) { Animate(labels[i], placeAbove, bottom); } AnimateColor(mBackground); AnimateScale(mBackground, placeAbove, bottom); } // If we need to place the popup list above the item, we need to reposition everything by the size of the list if (placeAbove) { t.localPosition = new Vector3(min.x, max.y - y - bgPadding.y, min.z); } min = t.localPosition; max.x = min.x + mBackground.width; max.y = min.y + mBackground.height; max.z = min.z; Vector3 offset = mPanel.CalculateConstrainOffset(min, max); t.localPosition += offset; } else { OnSelect(false); } }
/// <summary> /// Display the drop-down list when the game object gets clicked on. /// </summary> void OnClick() { if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0) { mLabelList.Clear(); // Disable the navigation script handleEvents = true; // Automatically locate the panel responsible for this object if (mPanel == null) { mPanel = UIPanel.Find(transform, true); } // Calculate the dimensions of the object triggering the popup list so we can position it below it Transform myTrans = transform; Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans); // Create the root object for the list mChild = new GameObject("Drop-down List"); mChild.layer = gameObject.layer; Transform t = mChild.transform; t.parent = myTrans.parent; t.localPosition = bounds.min; t.localRotation = Quaternion.identity; t.localScale = Vector3.one; // Add a sprite for the background mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite); mBackground.pivot = UIWidget.Pivot.TopLeft; mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject); mBackground.color = backgroundColor; // We need to know the size of the background sprite for padding purposes Vector4 bgPadding = mBackground.border; mBgBorder = bgPadding.y; mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f); // Add a sprite used for the selection mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite); mHighlight.pivot = UIWidget.Pivot.TopLeft; mHighlight.color = highlightColor; UISpriteData hlsp = mHighlight.GetAtlasSprite(); if (hlsp == null) { return; } float hlspHeight = hlsp.borderTop; float pixelSize = (bitmapFont != null) ? bitmapFont.pixelSize : 1f; float fontHeight = activeFontSize * pixelSize; float dynScale = activeFontScale; float labelHeight = fontHeight * dynScale; float x = 0f, y = -padding.y; List <UILabel> labels = new List <UILabel>(); // Run through all items and create labels for each one for (int i = 0, imax = items.Count; i < imax; ++i) { string s = items[i]; UILabel lbl = NGUITools.AddWidget <UILabel>(mChild); lbl.pivot = UIWidget.Pivot.TopLeft; lbl.bitmapFont = bitmapFont; lbl.trueTypeFont = trueTypeFont; lbl.fontSize = fontSize; lbl.fontStyle = fontStyle; lbl.text = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s; lbl.color = textColor; lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -1f); lbl.overflowMethod = UILabel.Overflow.ResizeFreely; lbl.MakePixelPerfect(); if (dynScale != 1f) { lbl.cachedTransform.localScale = Vector3.one * dynScale; } labels.Add(lbl); y -= labelHeight; y -= padding.y; x = Mathf.Max(x, labelHeight); // Add an event listener UIEventListener listener = UIEventListener.Get(lbl.gameObject); listener.onHover = OnItemHover; listener.onPress = OnItemPress; listener.parameter = s; // Move the selection here if this is the right label if (mSelectedItem == s) { Highlight(lbl, true); } // Add this label to the list mLabelList.Add(lbl); } // The triggering widget's width should be the minimum allowed width x = Mathf.Max(x, bounds.size.x * dynScale - (bgPadding.x + padding.x) * 2f); float cx = x / dynScale; Vector3 bcCenter = new Vector3(cx * 0.5f, -fontHeight * 0.5f, 0f); Vector3 bcSize = new Vector3(cx, (labelHeight + padding.y) / dynScale, 1f); // Run through all labels and add colliders for (int i = 0, imax = labels.Count; i < imax; ++i) { UILabel lbl = labels[i]; BoxCollider bc = NGUITools.AddWidgetCollider(lbl.gameObject); bcCenter.z = bc.center.z; bc.center = bcCenter; bc.size = bcSize; } x += (bgPadding.x + padding.x) * 2f; y -= bgPadding.y; // Scale the background sprite to envelop the entire set of items mBackground.width = Mathf.RoundToInt(x); mBackground.height = Mathf.RoundToInt(-y + bgPadding.y); // Scale the highlight sprite to envelop a single item float scaleFactor = 2f * atlas.pixelSize; float w = x - (bgPadding.x + padding.x) * 2f + hlsp.borderLeft * scaleFactor; float h = labelHeight + hlspHeight * scaleFactor; mHighlight.width = Mathf.RoundToInt(w); mHighlight.height = Mathf.RoundToInt(h); bool placeAbove = (position == Position.Above); if (position == Position.Auto) { UICamera cam = UICamera.FindCameraForLayer(gameObject.layer); if (cam != null) { Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position); placeAbove = (viewPos.y < 0.5f); } } // If the list should be animated, let's animate it by expanding it if (isAnimated) { float bottom = y + labelHeight; Animate(mHighlight, placeAbove, bottom); for (int i = 0, imax = labels.Count; i < imax; ++i) { Animate(labels[i], placeAbove, bottom); } AnimateColor(mBackground); AnimateScale(mBackground, placeAbove, bottom); } // If we need to place the popup list above the item, we need to reposition everything by the size of the list if (placeAbove) { t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z); } } else { OnSelect(false); } }
private void OnClick() { if (((this.mChild == null) && (this.atlas != null)) && ((this.font != null) && (this.items.Count > 0))) { this.mLabelList.Clear(); this.handleEvents = true; if (this.mPanel == null) { this.mPanel = UIPanel.Find(base.transform, true); } Transform child = base.transform; Bounds bounds = 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 = bounds.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 atlasSprite = this.mHighlight.GetAtlasSprite(); if (atlasSprite != null) { float num = atlasSprite.inner.yMin - atlasSprite.outer.yMin; float num2 = (this.font.size * this.font.pixelSize) * this.textScale; float a = 0f; float y = -this.padding.y; List <UILabel> list = new 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 + this.padding.x, y, -1f); 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, bounds.size.x - ((border.x + this.padding.x) * 2f)); Vector3 vector5 = new Vector3((a * 0.5f) / num2, -0.5f, 0f); Vector3 vector6 = new Vector3(a / num2, (num2 + this.padding.y) / num2, 1f); int num7 = 0; int num8 = list.Count; while (num7 < num8) { UILabel label2 = list[num7]; BoxCollider collider = NGUITools.AddWidgetCollider(label2.gameObject); vector5.z = collider.center.z; collider.center = vector5; collider.size = vector6; num7++; } a += (border.x + this.padding.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 + this.padding.x) * 2f)) + ((atlasSprite.inner.xMin - atlasSprite.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(bounds.min.x, (bounds.max.y - y) - border.y, bounds.min.z); } } } else { this.OnSelect(false); } }
private void Update() { if (this.mAnim != null && this.mAnim.enabled && this.mAnim.isPlaying) { return; } bool flag = false; UIWidget uIWidget = (!(this.container == null)) ? this.container.GetComponent <UIWidget>() : null; UIPanel uIPanel = (!(this.container == null) || !(uIWidget == null)) ? this.container.GetComponent <UIPanel>() : null; if (uIWidget != null) { Bounds bounds = uIWidget.CalculateBounds(this.container.transform.parent); this.mRect.x = bounds.min.x; this.mRect.y = bounds.min.y; this.mRect.width = bounds.size.x; this.mRect.height = bounds.size.y; } else if (uIPanel != null) { if (uIPanel.clipping == UIDrawCall.Clipping.None) { float num = (!(this.mRoot != null)) ? 0.5f : ((float)this.mRoot.activeHeight / (float)Screen.height * 0.5f); this.mRect.xMin = (float)(-(float)Screen.width) * num; this.mRect.yMin = (float)(-(float)Screen.height) * num; this.mRect.xMax = -this.mRect.xMin; this.mRect.yMax = -this.mRect.yMin; } else { Vector4 finalClipRegion = uIPanel.finalClipRegion; this.mRect.x = finalClipRegion.x - finalClipRegion.z * 0.5f; this.mRect.y = finalClipRegion.y - finalClipRegion.w * 0.5f; this.mRect.width = finalClipRegion.z; this.mRect.height = finalClipRegion.w; } } else if (this.container != null) { Transform parent = this.container.transform.parent; Bounds bounds2 = (!(parent != null)) ? NGUIMath.CalculateRelativeWidgetBounds(this.container.transform) : NGUIMath.CalculateRelativeWidgetBounds(parent, this.container.transform); this.mRect.x = bounds2.min.x; this.mRect.y = bounds2.min.y; this.mRect.width = bounds2.size.x; this.mRect.height = bounds2.size.y; } else { if (!(this.uiCamera != null)) { return; } flag = true; this.mRect = this.uiCamera.pixelRect; } float x = (this.mRect.xMin + this.mRect.xMax) * 0.5f; float y = (this.mRect.yMin + this.mRect.yMax) * 0.5f; Vector3 vector = new Vector3(x, y, 0f); if (this.side != UIAnchor.Side.Center) { if (this.side == UIAnchor.Side.Right || this.side == UIAnchor.Side.TopRight || this.side == UIAnchor.Side.BottomRight) { vector.x = this.mRect.xMax; } else if (this.side == UIAnchor.Side.Top || this.side == UIAnchor.Side.Center || this.side == UIAnchor.Side.Bottom) { vector.x = x; } else { vector.x = this.mRect.xMin; } if (this.side == UIAnchor.Side.Top || this.side == UIAnchor.Side.TopRight || this.side == UIAnchor.Side.TopLeft) { vector.y = this.mRect.yMax; } else if (this.side == UIAnchor.Side.Left || this.side == UIAnchor.Side.Center || this.side == UIAnchor.Side.Right) { vector.y = y; } else { vector.y = this.mRect.yMin; } } float width = this.mRect.width; float height = this.mRect.height; vector.x += this.pixelOffset.x + this.relativeOffset.x * width; vector.y += this.pixelOffset.y + this.relativeOffset.y * height; if (flag) { if (this.uiCamera.orthographic) { vector.x = Mathf.Round(vector.x); vector.y = Mathf.Round(vector.y); } vector.z = this.uiCamera.WorldToScreenPoint(this.mTrans.position).z; vector = this.uiCamera.ScreenToWorldPoint(vector); } else { vector.x = Mathf.Round(vector.x); vector.y = Mathf.Round(vector.y); if (uIPanel != null) { vector = uIPanel.cachedTransform.TransformPoint(vector); } else if (this.container != null) { Transform parent2 = this.container.transform.parent; if (parent2 != null) { vector = parent2.TransformPoint(vector); } } vector.z = this.mTrans.position.z; } if (flag && this.uiCamera.orthographic && this.mTrans.parent != null) { vector = this.mTrans.parent.InverseTransformPoint(vector); vector.x = (float)Mathf.RoundToInt(vector.x); vector.y = (float)Mathf.RoundToInt(vector.y); if (this.mTrans.localPosition != vector) { this.mTrans.localPosition = vector; } } else if (this.mTrans.position != vector) { this.mTrans.position = vector; } if (this.runOnlyOnce && Application.isPlaying) { base.enabled = false; } }
/// <summary> /// 刷新聊天内容数据 /// </summary> public void ShowContent(ChatInfo _info) { if (_info == null) { return; } curInfo = _info; if (chatfuncshion != null) { chatfuncshion.init(_info); } if (headSprite != null) { if (_info.sendProf > 0) { PlayerConfig Ref = ConfigMng.Instance.GetPlayerConfig(_info.sendProf); if (Ref != null) { headSprite.spriteName = Ref.res_head_Icon; headSprite.MakePixelPerfect(); } } else { headSprite.gameObject.SetActive(false); if (headObj != null) { headObj.SetActive(false); } } } if (vipLv != null) { vipLv.text = _info.sendVipLv.ToString(); if (vipObj != null) { vipObj.gameObject.SetActive(_info.sendVipLv > 0); } } if (chatContentObj == null) { if (chatContent == null) { return; } if (_info.chatTypeID == 5) { chatContent.transform.localPosition = new Vector3(chatContent.transform.localPosition.x - 30, chatContent.transform.localPosition.y, chatContent.transform.localPosition.z); } chatContent.text = _info.ChatContent; if (NGUIMath.CalculateRelativeWidgetBounds(chatContent.transform).size.x >= 650) { chatContent.overflowMethod = UILabel.Overflow.ResizeHeight; chatContent.width = 650; } ShowSprite(_info.isSystemInfo); //switch (_info.chatTypeID) //{ // case 5: ShowSprite(3); break; // case 2: ShowSprite(2); break; // default: ShowSprite(1); // break; //} } else { if (chatContent != null) { chatContent.text = _info.ChatContent; } if (NGUIMath.CalculateRelativeWidgetBounds(chatContent.transform).size.x >= 422) { chatContent.overflowMethod = UILabel.Overflow.ResizeHeight; chatContent.width = 422; } chatContentObj.SetActive(true); } if (otherWords != null) { otherWords.SetActive(_info.senderID != GameCenter.mainPlayerMng.MainPlayerInfo.ServerInstanceID && !_info.isSystemInfo); } if (selfWords != null) { selfWords.SetActive(_info.senderID == GameCenter.mainPlayerMng.MainPlayerInfo.ServerInstanceID && !_info.isSystemInfo); } }
public unsafe static long $Invoke5(long instance, long *args) { return(GCHandledObjects.ObjectToGCHandle(NGUIMath.CalculateRelativeWidgetBounds((Transform)GCHandledObjects.GCHandleToObject(*args)))); }
private void OnDrag(Vector2 delta) { if ((base.enabled && base.gameObject.activeInHierarchy) && (this.target != null)) { UICamera.currentTouch.clickNotification = UICamera.ClickNotification.BasedOnDelta; Ray ray = UICamera.currentCamera.ScreenPointToRay((Vector3)UICamera.currentTouch.pos); float enter = 0f; if (this.mPlane.Raycast(ray, out enter)) { Vector3 point = ray.GetPoint(enter); Vector3 direction = point - this.mLastPos; this.mLastPos = point; if ((direction.x != 0f) || (direction.y != 0f)) { direction = this.target.InverseTransformDirection(direction); direction.Scale(this.scale); direction = this.target.TransformDirection(direction); } this.mMomentum = Vector3.Lerp(this.mMomentum, this.mMomentum + ((Vector3)(direction * (0.01f * this.momentumAmount))), 0.67f); if (this.restrictWithinPanel) { Vector3 localPosition = this.target.localPosition; this.target.position += direction; this.mBounds.center += this.target.localPosition - localPosition; if (((this.dragEffect != DragEffect.MomentumAndSpring) && (this.mPanel.clipping != UIDrawCall.Clipping.None)) && this.mPanel.ConstrainTargetToBounds(this.target, ref this.mBounds, true)) { this.mMomentum = Vector3.zero; this.mScroll = 0f; } } else if (this.restrictToScreen) { Vector2 localScale; this.target.position += direction; if (this.sizeParent != null) { localScale = this.sizeParent.transform.localScale; } else { localScale = NGUIMath.CalculateRelativeWidgetBounds(this.target).size; } Rect rect = screenBorder.Add(new Rect(0f, (float)-Screen.height, (float)Screen.width, (float)Screen.height)); Vector3 vector5 = this.target.localPosition; bool flag = true; if ((vector5.x + localScale.x) > rect.xMax) { vector5.x = rect.xMax - localScale.x; } else if (vector5.x < rect.xMin) { vector5.x = rect.xMin; } else { flag = false; } bool flag2 = true; if (vector5.y > rect.yMax) { vector5.y = rect.yMax; } else if ((vector5.y - localScale.y) < rect.yMin) { vector5.y = rect.yMin + localScale.y; } else { flag2 = false; } if (flag || flag2) { this.target.localPosition = vector5; } } } } }
/// <summary> /// 语音聊天刷新 /// </summary> /// <param name="_info"></param> public void ShowPrivateContent(ChatInfo _info) { if (_info == null) { return; } if (chatfuncshion != null) { chatfuncshion.init(_info); } curInfo = _info; if (voiceRedObj != null) { voiceRedObj.SetActive(false); } StopAni(); if (headSprite != null && _info.sendProf != 0) { PlayerConfig Ref = ConfigMng.Instance.GetPlayerConfig(_info.sendProf); if (Ref != null) { headSprite.spriteName = Ref.res_head_Icon; headSprite.MakePixelPerfect(); } else { headSprite.gameObject.SetActive(false); if (headObj != null) { headObj.SetActive(false); } } } if (chatContent == null) { return; } //聊天类型 string[] str = _info.ChatContent.Split(':'); if (str.Length >= 2) { chatContent.text = str[1]; } else { Debug.LogError("聊天信息数据错误 by黄洪兴"); } if (NGUIMath.CalculateRelativeWidgetBounds(chatContent.transform).size.x >= 650) { chatContent.overflowMethod = UILabel.Overflow.ResizeHeight; chatContent.width = 650; } if (sendName != null) { if (curInfo.senderID != GameCenter.mainPlayerMng.MainPlayerInfo.ServerInstanceID) { sendName.text = "[u]" + curInfo.senderName + curInfo.sendTime; } else { UIwenbenRef Ref = ConfigMng.Instance.GetUITextRef(86); if (Ref != null) { sendName.text = curInfo.sendTime + Ref.text; } else { sendName.text = curInfo.sendTime; } } } if (curInfo.isVoice) { if (chatContent != null) { chatContent.text = string.Empty; UIEventListener.Get(chatContent.gameObject).onClick = PlayVoice; } if (voiceCount != null) { voiceCount.text = curInfo.voiceCont.ToString() + "\""; } if (voiceContentSprite != null) { voiceContentSprite.ResetAnchors(); voiceContentSprite.width = 120; } if (selfVoiceContentSprite != null) { selfVoiceContentSprite.ResetAnchors(); selfVoiceContentSprite.width = 120; } if (voiceRedObj != null) { voiceRedObj.SetActive(curInfo.voiceRed); } } if (voiceSprite != null) { voiceSprite.SetActive(curInfo.isVoice); } if (otherWords != null) { otherWords.SetActive(_info.senderID != GameCenter.mainPlayerMng.MainPlayerInfo.ServerInstanceID && !_info.isSystemInfo); } if (selfWords != null) { selfWords.SetActive(_info.senderID == GameCenter.mainPlayerMng.MainPlayerInfo.ServerInstanceID && !_info.isSystemInfo); } }
/// <summary> /// 添加Item /// </summary> /// <param name="pDirection"></param> protected void AddItem(Direction pDirection) { if (pDirection == Direction.None) { return; } var tItemControllers = itemControllers; if (tItemControllers == null || tItemControllers.Count == 0) { return; } var tTempItemCtls = tItemControllers.OrderBy(x => x.recycleTablInfo.dataIndex).ToList(); T tTempItemCtrl = null; var tDataIndex = 0; switch (pDirection) { case Direction.Right: case Direction.Bottom: tTempItemCtrl = tTempItemCtls[tTempItemCtls.Count - 1]; tDataIndex = tTempItemCtrl.recycleTablInfo.dataIndex + 1; if (tDataIndex >= itemCount) { return; } break; case Direction.Left: case Direction.Top: tTempItemCtrl = tTempItemCtls[0]; tDataIndex = tTempItemCtrl.recycleTablInfo.dataIndex - 1; if (tDataIndex < 0) { return; } break; } if (tTempItemCtrl == null) { return; } var tItemCtrl = GetItemControllerByCache(tDataIndex); onUpdateItem(tItemCtrl, tDataIndex); var tTempItemBounds = NGUIMath.CalculateRelativeWidgetBounds(tTempItemCtrl.itemTransform); tTempItemBounds.center += tTempItemCtrl.itemTransform.localPosition; var tItemBounds = NGUIMath.CalculateRelativeWidgetBounds(tItemCtrl.itemTransform); var tInfo = tItemCtrl.recycleTablInfo; tInfo.bounds = tItemBounds; tItemCtrl.recycleTablInfo = tInfo; var tItemOffset = 0F; switch (pDirection) { case Direction.Left: case Direction.Bottom: switch (movement) { case UIScrollView.Movement.Horizontal: tItemOffset = tTempItemBounds.min.x - tItemBounds.max.x - itemIntervalPixel; break; case UIScrollView.Movement.Vertical: tItemOffset = tTempItemBounds.min.y - tItemBounds.max.y - itemIntervalPixel; break; } break; case Direction.Right: case Direction.Top: switch (movement) { case UIScrollView.Movement.Horizontal: tItemOffset = tTempItemBounds.max.x - tItemBounds.min.x + itemIntervalPixel; break; case UIScrollView.Movement.Vertical: tItemOffset = tTempItemBounds.max.y - tItemBounds.min.y + itemIntervalPixel; break; } break; } switch (movement) { case UIScrollView.Movement.Horizontal: tItemCtrl.itemTransform.SetLocalPos(tItemOffset, 0); break; case UIScrollView.Movement.Vertical: tItemCtrl.itemTransform.SetLocalPos(0, tItemOffset); break; } mCalculatedBounds = true; }
public float GetContentHeight() { AABBox aABBox = NGUIMath.CalculateRelativeWidgetBounds(this.addParent.transform, this.addParent.transform); return(aABBox.size.y); }
public void Show() { if (base.enabled && NGUITools.GetActive(base.gameObject) && UIPopupList.mChild == (UnityEngine.Object)null && this.atlas != (UnityEngine.Object)null && this.isValid && this.items.Count > 0) { this.mLabelList.Clear(); base.StopCoroutine("CloseIfUnselected"); UICamera.selectedObject = (UICamera.hoveredObject ?? base.gameObject); this.mSelection = UICamera.selectedObject; this.source = UICamera.selectedObject; if (this.source == (UnityEngine.Object)null) { global::Debug.LogError("Popup list needs a source object..."); return; } this.mOpenFrame = Time.frameCount; if (this.mPanel == (UnityEngine.Object)null) { this.mPanel = UIPanel.Find(base.transform); if (this.mPanel == (UnityEngine.Object)null) { return; } } UIPopupList.mChild = new GameObject("Drop-down List"); UIPopupList.mChild.layer = base.gameObject.layer; UIPopupList.current = this; Transform transform = UIPopupList.mChild.transform; transform.parent = this.mPanel.cachedTransform; Vector3 localPosition; Vector3 vector; Vector3 v; if (this.openOn == UIPopupList.OpenOn.Manual && this.mSelection != base.gameObject) { localPosition = UICamera.lastEventPosition; vector = this.mPanel.cachedTransform.InverseTransformPoint(this.mPanel.anchorCamera.ScreenToWorldPoint(localPosition)); v = vector; transform.localPosition = vector; localPosition = transform.position; } else { Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(this.mPanel.cachedTransform, base.transform, false, false); vector = bounds.min; v = bounds.max; transform.localPosition = vector; localPosition = transform.position; } base.StartCoroutine("CloseIfUnselected"); transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; this.mBackground = NGUITools.AddSprite(UIPopupList.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(UIPopupList.mChild, this.atlas, this.highlightSprite); this.mHighlight.pivot = UIWidget.Pivot.TopLeft; this.mHighlight.color = this.highlightColor; UISpriteData atlasSprite = this.mHighlight.GetAtlasSprite(); if (atlasSprite == null) { return; } Single num = (Single)atlasSprite.borderTop; Single num2 = (Single)this.activeFontSize; Single activeFontScale = this.activeFontScale; Single num3 = num2 * activeFontScale; Single num4 = 0f; Single num5 = -this.padding.y; List <UILabel> list = new List <UILabel>(); if (!this.items.Contains(this.mSelectedItem)) { this.mSelectedItem = (String)null; } Int32 i = 0; Int32 count = this.items.Count; while (i < count) { String text = this.items[i]; UILabel uilabel = NGUITools.AddWidget <UILabel>(UIPopupList.mChild); uilabel.name = i.ToString(); uilabel.pivot = UIWidget.Pivot.TopLeft; uilabel.bitmapFont = this.bitmapFont; uilabel.trueTypeFont = this.trueTypeFont; uilabel.fontSize = this.fontSize; uilabel.fontStyle = this.fontStyle; uilabel.text = ((!this.isLocalized) ? text : Localization.Get(text)); uilabel.color = this.textColor; uilabel.cachedTransform.localPosition = new Vector3(border.x + this.padding.x - uilabel.pivotOffset.x, num5, -1f); uilabel.overflowMethod = UILabel.Overflow.ResizeFreely; uilabel.alignment = this.alignment; list.Add(uilabel); num5 -= num3; num5 -= this.padding.y; num4 = Mathf.Max(num4, uilabel.printedSize.x); UIEventListener uieventListener = UIEventListener.Get(uilabel.gameObject); uieventListener.onHover = new UIEventListener.BoolDelegate(this.OnItemHover); uieventListener.onPress = new UIEventListener.BoolDelegate(this.OnItemPress); uieventListener.parameter = text; if (this.mSelectedItem == text || (i == 0 && String.IsNullOrEmpty(this.mSelectedItem))) { this.Highlight(uilabel, true); } this.mLabelList.Add(uilabel); i++; } num4 = Mathf.Max(num4, v.x - vector.x - (border.x + this.padding.x) * 2f); Single num6 = num4; Vector3 vector2 = new Vector3(num6 * 0.5f, -num3 * 0.5f, 0f); Vector3 vector3 = new Vector3(num6, num3 + this.padding.y, 1f); Int32 j = 0; Int32 count2 = list.Count; while (j < count2) { UILabel uilabel2 = list[j]; NGUITools.AddWidgetCollider(uilabel2.gameObject); uilabel2.autoResizeBoxCollider = false; BoxCollider component = uilabel2.GetComponent <BoxCollider>(); if (component != (UnityEngine.Object)null) { vector2.z = component.center.z; component.center = vector2; component.size = vector3; } else { BoxCollider2D component2 = uilabel2.GetComponent <BoxCollider2D>(); component2.offset = vector2; component2.size = vector3; } j++; } Int32 width = Mathf.RoundToInt(num4); num4 += (border.x + this.padding.x) * 2f; num5 -= border.y; this.mBackground.width = Mathf.RoundToInt(num4); this.mBackground.height = Mathf.RoundToInt(-num5 + border.y); Int32 k = 0; Int32 count3 = list.Count; while (k < count3) { UILabel uilabel3 = list[k]; uilabel3.overflowMethod = UILabel.Overflow.ShrinkContent; uilabel3.width = width; k++; } Single num7 = 2f * this.atlas.pixelSize; Single f = num4 - (border.x + this.padding.x) * 2f + (Single)atlasSprite.borderLeft * num7; Single f2 = num3 + num * num7; this.mHighlight.width = Mathf.RoundToInt(f); this.mHighlight.height = Mathf.RoundToInt(f2); Boolean flag = this.position == UIPopupList.Position.Above; if (this.position == UIPopupList.Position.Auto) { UICamera uicamera = UICamera.FindCameraForLayer(this.mSelection.layer); if (uicamera != (UnityEngine.Object)null) { flag = (uicamera.cachedCamera.WorldToViewportPoint(localPosition).y < 0.5f); } } if (this.isAnimated) { this.AnimateColor(this.mBackground); if (Time.timeScale == 0f || Time.timeScale >= 0.1f) { Single bottom = num5 + num3; this.Animate(this.mHighlight, flag, bottom); Int32 l = 0; Int32 count4 = list.Count; while (l < count4) { this.Animate(list[l], flag, bottom); l++; } this.AnimateScale(this.mBackground, flag, bottom); } } if (flag) { vector.y = v.y - border.y; v.y = vector.y + (Single)this.mBackground.height; v.x = vector.x + (Single)this.mBackground.width; transform.localPosition = new Vector3(vector.x, v.y - border.y, vector.z); } else { v.y = vector.y + border.y; vector.y = v.y - (Single)this.mBackground.height; v.x = vector.x + (Single)this.mBackground.width; } Transform parent = this.mPanel.cachedTransform.parent; if (parent != (UnityEngine.Object)null) { vector = this.mPanel.cachedTransform.TransformPoint(vector); v = this.mPanel.cachedTransform.TransformPoint(v); vector = parent.InverseTransformPoint(vector); v = parent.InverseTransformPoint(v); } Vector3 b = this.mPanel.CalculateConstrainOffset(vector, v); localPosition = transform.localPosition + b; localPosition.x = Mathf.Round(localPosition.x); localPosition.y = Mathf.Round(localPosition.y); transform.localPosition = localPosition; } else { this.OnSelect(false); } }
/// <summary> /// Apply the dragging momentum. /// </summary> void LateUpdate() { float delta = UpdateRealTimeDelta(); if (target == null) { return; } if (mPressed) { // Disable the spring movement SpringPosition sp = target.GetComponent <SpringPosition>(); if (sp != null) { sp.enabled = false; } mScroll = 0f; } else { mMomentum += scale * (-mScroll * 0.05f); mScroll = NGUIMath.SpringLerp(mScroll, 0f, 20f, delta); if (mMomentum.magnitude > 0.0001f) { // Apply the momentum if (mPanel == null) { FindPanel(); } if (mPanel != null) { target.position += NGUIMath.SpringDampen(ref mMomentum, 9f, delta); if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None) { mBounds = NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, target); if (!mPanel.ConstrainTargetToBounds(target, ref mBounds, dragEffect == DragEffect.None)) { SpringPosition sp = target.GetComponent <SpringPosition>(); if (sp != null) { sp.enabled = false; } } } return; } } else { mScroll = 0f; } } // Dampen the momentum NGUIMath.SpringDampen(ref mMomentum, 9f, delta); }
public unsafe static long $Invoke8(long instance, long *args) { return(GCHandledObjects.ObjectToGCHandle(NGUIMath.CalculateRelativeWidgetBounds((Transform)GCHandledObjects.GCHandleToObject(*args), (Transform)GCHandledObjects.GCHandleToObject(args[1]), *(sbyte *)(args + 2) != 0, *(sbyte *)(args + 3) != 0))); }
public bool ConstrainTargetToBounds(Transform target, bool immediate) { var targetBounds = NGUIMath.CalculateRelativeWidgetBounds(cachedTransform, target); return(ConstrainTargetToBounds(target, ref targetBounds, immediate)); }
public static Bounds CalculateRelativeWidgetBounds(Transform trans) { return(NGUIMath.CalculateRelativeWidgetBounds(trans, trans, false, true)); }
/// <summary> /// Positions the grid items, taking their own size into consideration. /// </summary> protected virtual void RepositionVariableSize(List <Transform> children) { float xOffset = 0; float yOffset = 0; int cols = columns > 0 ? children.Count / columns + 1 : 1; int rows = columns > 0 ? columns : children.Count; Bounds[,] bounds = new Bounds[cols, rows]; Bounds[] boundsRows = new Bounds[rows]; Bounds[] boundsCols = new Bounds[cols]; int x = 0; int y = 0; for (int i = 0, imax = children.Count; i < imax; ++i) { Transform t = children[i]; Bounds b = NGUIMath.CalculateRelativeWidgetBounds(t, !hideInactive); Vector3 scale = t.localScale; b.min = Vector3.Scale(b.min, scale); b.max = Vector3.Scale(b.max, scale); bounds[y, x] = b; boundsRows[x].Encapsulate(b); boundsCols[y].Encapsulate(b); if (++x >= columns && columns > 0) { x = 0; ++y; } } x = 0; y = 0; Vector2 po = NGUIMath.GetPivotOffset(cellAlignment); for (int i = 0, imax = children.Count; i < imax; ++i) { Transform t = children[i]; Bounds b = bounds[y, x]; Bounds br = boundsRows[x]; Bounds bc = boundsCols[y]; Vector3 pos = t.localPosition; pos.x = xOffset + b.extents.x - b.center.x; pos.x -= Mathf.Lerp(0f, b.max.x - b.min.x - br.max.x + br.min.x, po.x) - padding.x; if (direction == Direction.Down) { pos.y = -yOffset - b.extents.y - b.center.y; pos.y += Mathf.Lerp(b.max.y - b.min.y - bc.max.y + bc.min.y, 0f, po.y) - padding.y; } else { pos.y = yOffset + b.extents.y - b.center.y; pos.y -= Mathf.Lerp(0f, b.max.y - b.min.y - bc.max.y + bc.min.y, po.y) - padding.y; } xOffset += br.size.x + padding.x * 2f; t.localPosition = pos; if (++x >= columns && columns > 0) { x = 0; ++y; xOffset = 0f; yOffset += bc.size.y + padding.y * 2f; } } // Apply the origin offset if (pivot != UIWidget.Pivot.TopLeft) { po = NGUIMath.GetPivotOffset(pivot); float fx, fy; Bounds b = NGUIMath.CalculateRelativeWidgetBounds(transform); fx = Mathf.Lerp(0f, b.size.x, po.x); fy = Mathf.Lerp(-b.size.y, 0f, po.y); Transform myTrans = transform; for (int i = 0; i < myTrans.childCount; ++i) { Transform t = myTrans.GetChild(i); SpringPosition sp = t.GetComponent <SpringPosition>(); if (sp != null) { sp.target.x -= fx; sp.target.y -= fy; } else { Vector3 pos = t.localPosition; pos.x -= fx; pos.y -= fy; t.localPosition = pos; } } } }
public static Bounds CalculateRelativeWidgetBounds(Transform trans, bool considerInactive) { return(NGUIMath.CalculateRelativeWidgetBounds(trans, trans, considerInactive, true)); }
/// <summary> /// Positions the grid items, taking their own size into consideration. /// </summary> void RepositionVariableSize(List <Transform> children) { float xOffset = 0; float yOffset = 0; int cols = columns > 0 ? children.Count / columns + 1 : 1; int rows = columns > 0 ? columns : children.Count; Bounds[,] bounds = new Bounds[cols, rows]; Bounds[] boundsRows = new Bounds[rows]; Bounds[] boundsCols = new Bounds[cols]; int x = 0; int y = 0; for (int i = 0, imax = children.Count; i < imax; ++i) { Transform t = children[i]; Bounds b = NGUIMath.CalculateRelativeWidgetBounds(t); Vector3 scale = t.localScale; b.min = Vector3.Scale(b.min, scale); b.max = Vector3.Scale(b.max, scale); bounds[y, x] = b; boundsRows[x].Encapsulate(b); boundsCols[y].Encapsulate(b); if (++x >= columns && columns > 0) { x = 0; ++y; } } x = 0; y = 0; for (int i = 0, imax = children.Count; i < imax; ++i) { Transform t = children[i]; Bounds b = bounds[y, x]; Bounds br = boundsRows[x]; Bounds bc = boundsCols[y]; Vector3 pos = t.localPosition; pos.x = xOffset + b.extents.x - b.center.x; pos.y = -(yOffset + b.extents.y + b.center.y); pos.x += b.min.x - br.min.x + padding.x; pos.y += (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y; xOffset += br.max.x - br.min.x + padding.x * 2f; t.localPosition = pos; if (++x >= columns && columns > 0) { x = 0; ++y; xOffset = 0f; yOffset += bc.size.y + padding.y * 2f; } } }
public static Bounds CalculateRelativeWidgetBounds(Transform relativeTo, Transform content) { return(NGUIMath.CalculateRelativeWidgetBounds(relativeTo, content, false, true)); }
/// <summary> /// Show the popup list dialog. /// </summary> public virtual void Show() { if (enabled && NGUITools.GetActive(gameObject) && mChild == null && isValid && items.Count > 0) { mLabelList.Clear(); StopCoroutine("CloseIfUnselected"); // Ensure the popup's source has the selection UICamera.selectedObject = (UICamera.hoveredObject ?? gameObject); mSelection = UICamera.selectedObject; source = mSelection; if (source == null) { Debug.LogError("Popup list needs a source object..."); return; } mOpenFrame = Time.frameCount; // Automatically locate the panel responsible for this object if (mPanel == null) { mPanel = UIPanel.Find(transform); if (mPanel == null) { return; } } // Calculate the dimensions of the object triggering the popup list so we can position it below it Vector3 min; Vector3 max; // Create the root object for the list mChild = new GameObject("Drop-down List"); mChild.layer = gameObject.layer; if (separatePanel) { if (GetComponent <Collider>() != null) { Rigidbody rb = mChild.AddComponent <Rigidbody>(); rb.isKinematic = true; } else if (GetComponent <Collider2D>() != null) { Rigidbody2D rb = mChild.AddComponent <Rigidbody2D>(); rb.isKinematic = true; } var panel = mChild.AddComponent <UIPanel>(); panel.depth = 1000000; panel.sortingOrder = mPanel.sortingOrder; } current = this; var pTrans = mPanel.cachedTransform; Transform t = mChild.transform; t.parent = pTrans; Transform rootTrans = pTrans; if (separatePanel) { var root = mPanel.GetComponentInParent <UIRoot>(); if (root == null && UIRoot.list.Count != 0) { root = UIRoot.list[0]; } if (root != null) { rootTrans = root.transform; } } // Manually triggered popup list on some other game object if (openOn == OpenOn.Manual && mSelection != gameObject) { startingPosition = UICamera.lastEventPosition; min = pTrans.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(startingPosition)); max = min; t.localPosition = min; startingPosition = t.position; } else { Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(pTrans, transform, false, false); min = bounds.min; max = bounds.max; t.localPosition = min; startingPosition = t.position; } StartCoroutine("CloseIfUnselected"); var f = fitScale; t.localRotation = Quaternion.identity; t.localScale = new Vector3(f, f, f); int depth = separatePanel ? 0 : NGUITools.CalculateNextDepth(mPanel.gameObject); // Add a sprite for the background if (background2DSprite != null) { UI2DSprite sp2 = mChild.AddWidget <UI2DSprite>(depth); sp2.sprite2D = background2DSprite; mBackground = sp2; } else if (atlas != null) { mBackground = NGUITools.AddSprite(mChild, atlas as INGUIAtlas, backgroundSprite, depth); } else { return; } bool placeAbove = (position == Position.Above); if (position == Position.Auto) { UICamera cam = UICamera.FindCameraForLayer(mSelection.layer); if (cam != null) { Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(startingPosition); placeAbove = (viewPos.y < 0.5f); } } mBackground.pivot = UIWidget.Pivot.TopLeft; mBackground.color = backgroundColor; // We need to know the size of the background sprite for padding purposes Vector4 bgPadding = mBackground.border; mBgBorder = bgPadding.y; mBackground.cachedTransform.localPosition = new Vector3(0f, placeAbove ? bgPadding.y * 2f - overlap : overlap, 0f); // Add a sprite used for the selection if (highlight2DSprite != null) { UI2DSprite sp2 = mChild.AddWidget <UI2DSprite>(++depth); sp2.sprite2D = highlight2DSprite; mHighlight = sp2; } else if (atlas != null) { mHighlight = NGUITools.AddSprite(mChild, atlas as INGUIAtlas, highlightSprite, ++depth); } else { return; } float hlspHeight = 0f, hlspLeft = 0f; if (mHighlight.hasBorder) { hlspHeight = mHighlight.border.w; hlspLeft = mHighlight.border.x; } mHighlight.pivot = UIWidget.Pivot.TopLeft; mHighlight.color = highlightColor; float labelHeight = activeFontSize * activeFontScale; float lineHeight = labelHeight + padding.y; float x = 0f, y = placeAbove ? bgPadding.y - padding.y - overlap : -padding.y - bgPadding.y + overlap; float contentHeight = bgPadding.y * 2f + padding.y; List <UILabel> labels = new List <UILabel>(); // Clear the selection if it's no longer present if (!items.Contains(mSelectedItem)) { mSelectedItem = null; } // Run through all items and create labels for each one for (int i = 0, imax = items.Count; i < imax; ++i) { string s = items[i]; UILabel lbl = NGUITools.AddWidget <UILabel>(mChild, mBackground.depth + 2); lbl.name = i.ToString(); lbl.pivot = UIWidget.Pivot.TopLeft; lbl.bitmapFont = bitmapFont as INGUIFont; lbl.trueTypeFont = trueTypeFont; lbl.fontSize = fontSize; lbl.fontStyle = fontStyle; lbl.text = isLocalized ? Localization.Get(s) : s; lbl.modifier = textModifier; lbl.color = textColor; lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x - lbl.pivotOffset.x, y, -1f); lbl.overflowMethod = UILabel.Overflow.ResizeFreely; lbl.alignment = alignment; lbl.symbolStyle = NGUIText.SymbolStyle.Colored; lbl.keepCrispWhenShrunk = UILabel.Crispness.Never; //I still don't get why this option exists if it always looks like butts if it's turned on ~digi labels.Add(lbl); contentHeight += lineHeight; y -= lineHeight; x = Mathf.Max(x, lbl.printedSize.x); // Add an event listener UIEventListener listener = UIEventListener.Get(lbl.gameObject); listener.onHover = OnItemHover; listener.onPress = OnItemPress; listener.onClick = OnItemClick; listener.parameter = s; // Move the selection here if this is the right label if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem))) { Highlight(lbl, true); } // Add this label to the list mLabelList.Add(lbl); } // The triggering widget's width should be the minimum allowed width x = Mathf.Max(x, (max.x - min.x) - (bgPadding.x + padding.x) * 2f); float cx = x; Vector3 bcCenter = new Vector3(cx * 0.5f, -labelHeight * 0.5f, 0f); Vector3 bcSize = new Vector3(cx, (labelHeight + padding.y), 1f); // Run through all labels and add colliders for (int i = 0, imax = labels.Count; i < imax; ++i) { UILabel lbl = labels[i]; NGUITools.AddWidgetCollider(lbl.gameObject); lbl.autoResizeBoxCollider = false; BoxCollider bc = lbl.GetComponent <BoxCollider>(); if (bc != null) { bcCenter.z = bc.center.z; bc.center = bcCenter; bc.size = bcSize; } else { BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>(); #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 b2d.center = bcCenter; #else b2d.offset = bcCenter; #endif b2d.size = bcSize; } } int lblWidth = Mathf.RoundToInt(x); x += (bgPadding.x + padding.x) * 2f; y -= bgPadding.y; // Scale the background sprite to envelop the entire set of items mBackground.width = Mathf.RoundToInt(x); mBackground.height = Mathf.RoundToInt(contentHeight); // Set the label width to make alignment work for (int i = 0, imax = labels.Count; i < imax; ++i) { UILabel lbl = labels[i]; lbl.overflowMethod = UILabel.Overflow.ShrinkContent; lbl.width = lblWidth; } // Scale the highlight sprite to envelop a single item float scaleFactor = 2f; var atl = atlas as INGUIAtlas; if (atl != null) { scaleFactor *= atl.pixelSize; } float w = x - (bgPadding.x + padding.x) * 2f + hlspLeft * scaleFactor; float h = labelHeight + hlspHeight * scaleFactor; mHighlight.width = Mathf.RoundToInt(w); mHighlight.height = Mathf.RoundToInt(h); // If the list should be animated, let's animate it by expanding it if (isAnimated) { AnimateColor(mBackground); if (Time.timeScale == 0f || Time.timeScale >= 0.1f) { float bottom = y + labelHeight; Animate(mHighlight, placeAbove, bottom); for (int i = 0, imax = labels.Count; i < imax; ++i) { Animate(labels[i], placeAbove, bottom); } AnimateScale(mBackground, placeAbove, bottom); } } // If we need to place the popup list above the item, we need to reposition everything by the size of the list if (placeAbove) { var bgY = bgPadding.y * f; min.y = max.y - bgPadding.y * f; max.y = min.y + (mBackground.height - bgPadding.y * 2f) * f; max.x = min.x + mBackground.width * f; t.localPosition = new Vector3(min.x, max.y - bgY, min.z); } else { max.y = min.y + bgPadding.y * f; min.y = max.y - mBackground.height * f; max.x = min.x + mBackground.width * f; } var absoluteParent = mPanel; // UIRoot.list[0].GetComponent<UIPanel>(); for (;;) { var p = absoluteParent.parent; if (p == null) { break; } var pp = p.GetComponentInParent <UIPanel>(); if (pp == null) { break; } absoluteParent = pp; } if (pTrans != null) { min = pTrans.TransformPoint(min); max = pTrans.TransformPoint(max); min = absoluteParent.cachedTransform.InverseTransformPoint(min); max = absoluteParent.cachedTransform.InverseTransformPoint(max); var adj = UIRoot.GetPixelSizeAdjustment(gameObject); min /= adj; max /= adj; } // Ensure that everything fits into the panel's visible range var offset = absoluteParent.CalculateConstrainOffset(min, max); var pos = t.localPosition + offset; pos.x = Mathf.Round(pos.x); pos.y = Mathf.Round(pos.y); t.localPosition = pos; t.parent = rootTrans; } else { OnSelect(false); } }
private static void CalculateRelativeWidgetBounds(Transform content, bool considerInactive, bool isRoot, ref Matrix4x4 toLocal, ref Vector3 vMin, ref Vector3 vMax, ref bool isSet, bool considerChildren) { if (content == null) { return; } if (!considerInactive && !NGUITools.GetActive(content.gameObject)) { return; } UIPanel uIPanel = isRoot ? null : content.GetComponent <UIPanel>(); if (uIPanel != null && !uIPanel.enabled) { return; } if (uIPanel != null && uIPanel.clipping != UIDrawCall.Clipping.None) { Vector3[] worldCorners = uIPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 vector = toLocal.MultiplyPoint3x4(worldCorners[i]); if (vector.x > vMax.x) { vMax.x = vector.x; } if (vector.y > vMax.y) { vMax.y = vector.y; } if (vector.z > vMax.z) { vMax.z = vector.z; } if (vector.x < vMin.x) { vMin.x = vector.x; } if (vector.y < vMin.y) { vMin.y = vector.y; } if (vector.z < vMin.z) { vMin.z = vector.z; } isSet = true; } return; } UIWidget component = content.GetComponent <UIWidget>(); if (component != null && component.enabled && !component.skipBoundsCalculations) { Vector3[] worldCorners2 = component.worldCorners; for (int j = 0; j < 4; j++) { Vector3 vector2 = toLocal.MultiplyPoint3x4(worldCorners2[j]); if (vector2.x > vMax.x) { vMax.x = vector2.x; } if (vector2.y > vMax.y) { vMax.y = vector2.y; } if (vector2.z > vMax.z) { vMax.z = vector2.z; } if (vector2.x < vMin.x) { vMin.x = vector2.x; } if (vector2.y < vMin.y) { vMin.y = vector2.y; } if (vector2.z < vMin.z) { vMin.z = vector2.z; } isSet = true; } if (!considerChildren) { return; } } int k = 0; int childCount = content.childCount; while (k < childCount) { NGUIMath.CalculateRelativeWidgetBounds(content.GetChild(k), considerInactive, false, ref toLocal, ref vMin, ref vMax, ref isSet, true); k++; } }
/// <summary> /// Positions the grid items, taking their own size into consideration. /// </summary> void RepositionVariableSize(List <Transform> children) { float xOffset = 0; float yOffset = 0; int cols = columns > 0 ? children.Count / columns + 1 : 1; int rows = columns > 0 ? columns : children.Count; Bounds[,] bounds = new Bounds[cols, rows]; Bounds[] boundsRows = new Bounds[rows]; Bounds[] boundsCols = new Bounds[cols]; int x = 0; int y = 0; for (int i = 0, imax = children.Count; i < imax; ++i) { Transform t = children[i]; Bounds b = NGUIMath.CalculateRelativeWidgetBounds(t); Vector3 scale = t.localScale; b.min = Vector3.Scale(b.min, scale); b.max = Vector3.Scale(b.max, scale); bounds[y, x] = b; boundsRows[x].Encapsulate(b); boundsCols[y].Encapsulate(b); if (++x >= columns && columns > 0) { x = 0; ++y; } } x = 0; y = 0; for (int i = 0, imax = children.Count; i < imax; ++i) { Transform t = children[i]; Bounds b = bounds[y, x]; Bounds br = boundsRows[x]; Bounds bc = boundsCols[y]; Vector3 pos = t.localPosition; pos.x = xOffset + b.extents.x - b.center.x; pos.x += b.min.x - br.min.x + padding.x; // if((columns!=0&&i%columns!=0)||(columns==0&&i!=0))pos.x += gap.x; if (columns != 0) { pos.x += gap.x * (i % columns); } else { pos.x += gap.x * i; } if (direction == Direction.Down) { pos.y = -yOffset - b.extents.y - b.center.y; pos.y += (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y; // if(Mathf.Ceil(i/columns)>0) pos.y-= gap.y; if (columns != 0) { pos.y -= gap.y * Mathf.Floor(i / columns); } } else { pos.y = yOffset + b.extents.y - b.center.y; pos.y += (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y; // if(Mathf.Ceil(i/columns)>0) pos.y+= gap.y; if (columns != 0) { pos.y += gap.y * Mathf.Floor(i / columns); } } xOffset += br.max.x - br.min.x; //+ padding.x * 2f; // xOffset += br.max.x - br.min.x + padding.x * 2f; t.localPosition = pos; if (++x >= columns && columns > 0) { x = 0; ++y; xOffset = 0f; yOffset += bc.size.y; // + padding.y * 2f; } } }
// Token: 0x06003198 RID: 12696 RVA: 0x000F5024 File Offset: 0x000F3424 protected void RepositionVariableSize(List <Transform> children) { float num = 0f; float num2 = 0f; int num3 = (this.columns <= 0) ? 1 : (children.Count / this.columns + 1); int num4 = (this.columns <= 0) ? children.Count : this.columns; Bounds[,] array = new Bounds[num3, num4]; Bounds[] array2 = new Bounds[num4]; Bounds[] array3 = new Bounds[num3]; int num5 = 0; int num6 = 0; int i = 0; int count = children.Count; while (i < count) { Transform transform = children[i]; Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(transform, !this.hideInactive); Vector3 localScale = transform.localScale; bounds.min = Vector3.Scale(bounds.min, localScale); bounds.max = Vector3.Scale(bounds.max, localScale); array[num6, num5] = bounds; array2[num5].Encapsulate(bounds); array3[num6].Encapsulate(bounds); if (++num5 >= this.columns && this.columns > 0) { num5 = 0; num6++; } i++; } num5 = 0; num6 = 0; Vector2 pivotOffset = NGUIMath.GetPivotOffset(this.cellAlignment); int j = 0; int count2 = children.Count; while (j < count2) { Transform transform2 = children[j]; Bounds bounds2 = array[num6, num5]; Bounds bounds3 = array2[num5]; Bounds bounds4 = array3[num6]; Vector3 localPosition = transform2.localPosition; localPosition.x = num + bounds2.extents.x - bounds2.center.x; localPosition.x -= Mathf.Lerp(0f, bounds2.max.x - bounds2.min.x - bounds3.max.x + bounds3.min.x, pivotOffset.x) - this.padding.x; if (this.direction == UITable.Direction.Down) { localPosition.y = -num2 - bounds2.extents.y - bounds2.center.y; localPosition.y += Mathf.Lerp(bounds2.max.y - bounds2.min.y - bounds4.max.y + bounds4.min.y, 0f, pivotOffset.y) - this.padding.y; } else { localPosition.y = num2 + bounds2.extents.y - bounds2.center.y; localPosition.y -= Mathf.Lerp(0f, bounds2.max.y - bounds2.min.y - bounds4.max.y + bounds4.min.y, pivotOffset.y) - this.padding.y; } num += bounds3.size.x + this.padding.x * 2f; transform2.localPosition = localPosition; if (++num5 >= this.columns && this.columns > 0) { num5 = 0; num6++; num = 0f; num2 += bounds4.size.y + this.padding.y * 2f; } j++; } if (this.pivot != UIWidget.Pivot.TopLeft) { pivotOffset = NGUIMath.GetPivotOffset(this.pivot); Bounds bounds5 = NGUIMath.CalculateRelativeWidgetBounds(base.transform); float num7 = Mathf.Lerp(0f, bounds5.size.x, pivotOffset.x); float num8 = Mathf.Lerp(-bounds5.size.y, 0f, pivotOffset.y); Transform transform3 = base.transform; for (int k = 0; k < transform3.childCount; k++) { Transform child = transform3.GetChild(k); SpringPosition component = child.GetComponent <SpringPosition>(); if (component != null) { SpringPosition springPosition = component; springPosition.target.x = springPosition.target.x - num7; SpringPosition springPosition2 = component; springPosition2.target.y = springPosition2.target.y - num8; } else { Vector3 localPosition2 = child.localPosition; localPosition2.x -= num7; localPosition2.y -= num8; child.localPosition = localPosition2; } } } }
void Update() { if (mAnim != null && mAnim.isPlaying) { return; } if (style != Style.None) { UIWidget wc = (container == null) ? null : container.GetComponent <UIWidget>(); UIPanel pc = (container == null && wc == null) ? null : container.GetComponent <UIPanel>(); float adjustment = 1f; if (wc != null) { Bounds b = wc.CalculateBounds(transform.parent); mRect.x = b.min.x; mRect.y = b.min.y; mRect.width = b.size.x; mRect.height = b.size.y; } else if (pc != null) { if (pc.clipping == UIDrawCall.Clipping.None) { // Panel has no clipping -- just use the screen's dimensions float ratio = (mRoot != null) ? (float)mRoot.activeHeight / Screen.height * 0.5f : 0.5f; mRect.xMin = -Screen.width * ratio; mRect.yMin = -Screen.height * ratio; mRect.xMax = -mRect.xMin; mRect.yMax = -mRect.yMin; } else { // Panel has clipping -- use it as the mRect Vector4 cr = pc.finalClipRegion; mRect.x = cr.x - (cr.z * 0.5f); mRect.y = cr.y - (cr.w * 0.5f); mRect.width = cr.z; mRect.height = cr.w; } } else if (container != null) { Transform root = transform.parent; Bounds b = (root != null) ? NGUIMath.CalculateRelativeWidgetBounds(root, container.transform) : NGUIMath.CalculateRelativeWidgetBounds(container.transform); mRect.x = b.min.x; mRect.y = b.min.y; mRect.width = b.size.x; mRect.height = b.size.y; } else if (uiCamera != null) { mRect = uiCamera.pixelRect; if (mRoot != null) { adjustment = mRoot.pixelSizeAdjustment; } } else { return; } float rectWidth = mRect.width; float rectHeight = mRect.height; if (adjustment != 1f && rectHeight > 1f) { float scale = mRoot.activeHeight / rectHeight; rectWidth *= scale; rectHeight *= scale; } Vector3 size = (mWidget != null) ? new Vector3(mWidget.width, mWidget.height) : mTrans.localScale; if (style == Style.BasedOnHeight) { size.x = relativeSize.x * rectHeight; size.y = relativeSize.y * rectHeight; } else if (style == Style.FillKeepingRatio) { // Contributed by Dylan Ryan float screenRatio = rectWidth / rectHeight; float imageRatio = initialSize.x / initialSize.y; if (imageRatio < screenRatio) { // Fit horizontally float scale = rectWidth / initialSize.x; size.x = rectWidth; size.y = initialSize.y * scale; } else { // Fit vertically float scale = rectHeight / initialSize.y; size.x = initialSize.x * scale; size.y = rectHeight; } } else if (style == Style.FitInternalKeepingRatio) { // Contributed by Dylan Ryan float screenRatio = rectWidth / rectHeight; float imageRatio = initialSize.x / initialSize.y; if (imageRatio > screenRatio) { // Fit horizontally float scale = rectWidth / initialSize.x; size.x = rectWidth; size.y = initialSize.y * scale; } else { // Fit vertically float scale = rectHeight / initialSize.y; size.x = initialSize.x * scale; size.y = rectHeight; } } else { if (style != Style.Vertical) { size.x = relativeSize.x * rectWidth; } if (style != Style.Horizontal) { size.y = relativeSize.y * rectHeight; } } if (mSprite != null) { float multiplier = (mSprite.atlas != null) ? mSprite.atlas.pixelSize : 1f; size.x -= borderPadding.x * multiplier; size.y -= borderPadding.y * multiplier; if (style != Style.Vertical) { mSprite.width = Mathf.RoundToInt(size.x); } if (style != Style.Horizontal) { mSprite.height = Mathf.RoundToInt(size.y); } size = Vector3.one; } else if (mWidget != null) { if (style != Style.Vertical) { mWidget.width = Mathf.RoundToInt(size.x - borderPadding.x); } if (style != Style.Horizontal) { mWidget.height = Mathf.RoundToInt(size.y - borderPadding.y); } size = Vector3.one; } else if (mPanel != null) { Vector4 cr = mPanel.baseClipRegion; if (style != Style.Vertical) { cr.z = size.x - borderPadding.x; } if (style != Style.Horizontal) { cr.w = size.y - borderPadding.y; } mPanel.baseClipRegion = cr; size = Vector3.one; } else { if (style != Style.Vertical) { size.x -= borderPadding.x; } if (style != Style.Horizontal) { size.y -= borderPadding.y; } } if (mTrans.localScale != size) { mTrans.localScale = size; } if (runOnlyOnce && Application.isPlaying) { enabled = false; } } }
private void RepositionVariableSize(List <Transform> children) { float num = 0f; float num2 = 0f; int num3 = (this.columns <= 0) ? 1 : ((children.Count / this.columns) + 1); int num4 = (this.columns <= 0) ? children.Count : this.columns; AABBox[,] boxArray = new AABBox[num3, num4]; AABBox[] boxArray2 = new AABBox[num4]; AABBox[] boxArray3 = new AABBox[num3]; int index = 0; int num6 = 0; int num7 = 0; int count = children.Count; while (num7 < count) { Transform trans = children[num7]; AABBox v = NGUIMath.CalculateRelativeWidgetBounds(trans); Vector3 localScale = trans.localScale; Vector3 min = Vector3.Scale(v.min, localScale); v.SetMinMax(min, Vector3.Scale(v.max, localScale)); boxArray[num6, index] = v; boxArray2[index].Encapsulate(v); boxArray3[num6].Encapsulate(v); if ((++index >= this.columns) && (this.columns > 0)) { index = 0; num6++; } num7++; } index = 0; num6 = 0; int num9 = 0; int num10 = children.Count; while (num9 < num10) { Transform transform2 = children[num9]; AABBox box2 = boxArray[num6, index]; AABBox box3 = boxArray2[index]; AABBox box4 = boxArray3[num6]; Vector3 localPosition = transform2.localPosition; Vector3 vector3 = box2.min; Vector3 max = box2.max; Vector3 vector5 = (Vector3)(box2.size * 0.5f); Vector3 center = box2.center; Vector3 vector7 = box4.min; Vector3 vector8 = box4.max; Vector3 vector9 = box3.min; localPosition.x = (num + vector5.x) - center.x; localPosition.x += (vector3.x - vector9.x) + this.padding.x; if (this.direction == Direction.Down) { localPosition.y = (-num2 - vector5.y) - center.y; localPosition.y += ((((max.y - vector3.y) - vector8.y) + vector7.y) * 0.5f) - this.padding.y; } else { localPosition.y = (num2 + vector5.y) - center.y; localPosition.y += ((((max.y - vector3.y) - vector8.y) + vector7.y) * 0.5f) - this.padding.y; } num += (vector9.x - vector9.x) + (this.padding.x * 2f); transform2.localPosition = localPosition; if ((++index >= this.columns) && (this.columns > 0)) { index = 0; num6++; num = 0f; num2 += (vector5.y * 2f) + (this.padding.y * 2f); } num9++; } }
/// <summary> /// Anchor the object to the appropriate point. /// </summary> public void Update() { if (mAnim != null && mAnim.enabled && mAnim.isPlaying) { return; } bool useCamera = false; UIWidget wc = (container == null) ? null : container.GetComponent <UIWidget>(); UIPanel pc = (container == null && wc == null) ? null : container.GetComponent <UIPanel>(); if (wc != null) { Bounds b = wc.CalculateBounds(container.transform.parent); mRect.x = b.min.x; mRect.y = b.min.y; mRect.width = b.size.x; mRect.height = b.size.y; } else if (pc != null) { if (pc.clipping == UIDrawCall.Clipping.None) { // Panel has no clipping -- just use the screen's dimensions Vector2 size = NGUITools.screenSize; float ratio = (mRoot != null) ? (float)mRoot.activeHeight / size.y * 0.5f : 0.5f; mRect.xMin = -size.x * ratio; mRect.yMin = -size.y * ratio; mRect.xMax = -mRect.xMin; mRect.yMax = -mRect.yMin; } else { // Panel has clipping -- use it as the mRect Vector4 pos = pc.finalClipRegion; mRect.x = pos.x - (pos.z * 0.5f); mRect.y = pos.y - (pos.w * 0.5f); mRect.width = pos.z; mRect.height = pos.w; } } else if (container != null) { Transform root = container.transform.parent; Bounds b = (root != null) ? NGUIMath.CalculateRelativeWidgetBounds(root, container.transform) : NGUIMath.CalculateRelativeWidgetBounds(container.transform); mRect.x = b.min.x; mRect.y = b.min.y; mRect.width = b.size.x; mRect.height = b.size.y; } else if (uiCamera != null) { useCamera = true; Vector2 size = NGUITools.screenSize; mRect = uiCamera.rect; mRect.xMin *= size.x; mRect.yMin *= size.y; mRect.xMax *= size.x; mRect.yMax *= size.y; } else { return; } float cx = (mRect.xMin + mRect.xMax) * 0.5f; float cy = (mRect.yMin + mRect.yMax) * 0.5f; Vector3 v = new Vector3(cx, cy, 0f); if (side != Side.Center) { if (side == Side.Right || side == Side.TopRight || side == Side.BottomRight) { v.x = mRect.xMax; } else if (side == Side.Top || side == Side.Center || side == Side.Bottom) { v.x = cx; } else { v.x = mRect.xMin; } if (side == Side.Top || side == Side.TopRight || side == Side.TopLeft) { v.y = mRect.yMax; } else if (side == Side.Left || side == Side.Center || side == Side.Right) { v.y = cy; } else { v.y = mRect.yMin; } } float width = mRect.width; float height = mRect.height; v.x += pixelOffset.x + relativeOffset.x * width; v.y += pixelOffset.y + relativeOffset.y * height; if (useCamera) { if (uiCamera.orthographic) { v.x = Mathf.Round(v.x); v.y = Mathf.Round(v.y); } v.z = uiCamera.WorldToScreenPoint(mTrans.position).z; v = uiCamera.ScreenToWorldPoint(v); } else { v.x = Mathf.Round(v.x); v.y = Mathf.Round(v.y); if (pc != null) { v = pc.cachedTransform.TransformPoint(v); } else if (container != null) { Transform t = container.transform.parent; if (t != null) { v = t.TransformPoint(v); } } v.z = mTrans.position.z; } // Wrapped in an 'if' so the scene doesn't get marked as 'edited' every frame if (mTrans.position != v) { mTrans.position = v; } if (runOnlyOnce && Application.isPlaying) { enabled = false; } }
private void SetChatMsgUI_Left(ChatInfo text) { Vector3 origin = m_trans_redPacket.localPosition; m_trans_redPacket.localPosition = new Vector3(146, origin.y, 0); if (m_headIcon != null) { if (text.Channel == GameCmd.CHATTYPE.CHAT_GM) { UIManager.GetTextureAsyn("n031", ref iuiIconAtlas, () => { if (null != m_headIcon) { m_headIcon.mainTexture = null; } }, m_headIcon); } else { table.SelectRoleDataBase sdb = table.SelectRoleDataBase.Where((GameCmd.enumProfession)text.job, (GameCmd.enmCharSex) 1); if (sdb != null) { UIManager.GetTextureAsyn(sdb.strprofessionIcon, ref iuiIcon, () => { if (m_headIcon != null) { m_headIcon.mainTexture = null; } }, m_headIcon, false); } } m_headIcon.transform.localPosition = new Vector3(-m_panelWidth * 0.5f + BorderX, 0, 0); } if (GameCmd.CHATTYPE.CHAT_GMTOOL == text.Channel) { text.Channel = GameCmd.CHATTYPE.CHAT_GMTOOL; } if (text.Channel == GameCmd.CHATTYPE.CHAT_SILENT) { if (DataManager.Manager <RelationManager>().IsMyFriend(text.Id)) { m_lableChannel.text = "好友"; } else { m_lableChannel.text = "陌生人"; } } else { m_lableChannel.text = DataManager.Manager <ChatDataManager>().GetChannelStr(text.Channel); } m_lableChannel.transform.localPosition = m_headIcon.transform.localPosition + new Vector3(m_headIcon.width + 25, 0, 0); m_lableName.text = text.Name; m_lableName.transform.localPosition = m_lableChannel.transform.localPosition + new Vector3(m_lableChannel.width + 5, 0, 0); if (m_spriteNameBg != null) { m_spriteNameBg.transform.localPosition = m_lableChannel.transform.localPosition + new Vector3(-5, 5, 0); m_spriteNameBg.width = m_lableChannel.width + 10; m_spriteNameBg.height = m_lableChannel.fontSize + 10; m_spriteNameBg.enabled = true; m_spriteNameBg.ChangeSprite(GetChannelIndex(text.Channel)); } UISprite sp = m_bgSprite as UISprite; sp.spriteName = "biankuang_duihuazuo"; m_bgSprite.width = GetMaxWidth() - 10;//左边小箭头 if (!string.IsNullOrEmpty(text.voiceFileid)) { m_goVoice.gameObject.SetActive(true); m_goVoiceTip.SetActive(!m_chatdata.played); m_labelVoice.text = string.Format("{0}'", text.voiceLegth.ToString()); //从左边25开始 m_normalRichTextContext.offset = new Vector2(25, 0); //没有执行AddNewLine()先指定m_layout m_normalRichTextContext.m_layout = new Vector2(25, -60f); } else { m_goVoice.gameObject.SetActive(false); //从左边25开始 m_normalRichTextContext.offset = new Vector2(25, 0); //没有执行AddNewLine()先指定m_layout m_normalRichTextContext.m_layout = new Vector2(25, -10f); } m_normalRichTextContext.AddXml(text.Content); m_bgSprite.height = Mathf.CeilToInt(-m_normalRichTextContext.m_layout.y) + 10; if (m_normalRichTextContext.overline) { m_bgSprite.width = GetMaxWidth(); } else { m_bgSprite.width = Mathf.CeilToInt(m_normalRichTextContext.m_layout.x) + 15;//多添加15 } if (!string.IsNullOrEmpty(text.voiceFileid)) { if (m_bgSprite.width < VOICEBGWIDTH) { m_bgSprite.width = VOICEBGWIDTH; } m_bgSprite.transform.localPosition = new Vector3(m_headIcon.transform.localPosition.x + m_headIcon.width + BorderX + headRightOffset, m_bgSprite.transform.localPosition.y, 0); float posx = m_bgSprite.transform.localPosition.x + m_spriteVoiceBg.width * 0.5f + 40; m_goVoice.transform.localPosition = new UnityEngine.Vector3(posx, -m_headIcon.height * 0.5f - 28, 0); m_goVoice.transform.localRotation = Quaternion.Euler(Vector3.zero); m_labelVoice.transform.localRotation = Quaternion.Euler(Vector3.zero); m_labelVoice.transform.localPosition = new UnityEngine.Vector3(-m_labelVoice.transform.localPosition.x, 0, 0); } else { m_bgSprite.transform.localPosition = new Vector3(m_headIcon.transform.localPosition.x + m_headIcon.width + BorderX + headRightOffset, m_bgSprite.transform.localPosition.y, 0); } bound = NGUIMath.CalculateRelativeWidgetBounds(transform, false); }