public void NGUI_ModifyVertices(List <Vector3> vertices, List <Vector2> uvs, List <Color> colors, List <Vector3> normals, List <Vector4> tangents, List <Vector4> uvs2) { //--[ Cache ]------------ mWidgetColor = mNGUI_Widget.color; if (mWidgetColor.a < 1 / 255f && GetPlayingAnimation() == null) { return; } Bounds bounds = mNGUI_Widget.CalculateBounds(); mRect = Rect.MinMaxRect(bounds.min.x, bounds.min.y, bounds.max.x, bounds.max.y); mRectPivot.x = Mathf.InverseLerp(mRect.min.x, mRect.max.x, mRect.center.x); mRectPivot.y = Mathf.InverseLerp(mRect.min.y, mRect.max.y, mRect.center.y); UILabel label = mNGUI_Widget as UILabel; if (label != null) { mCharacterSize = label.printedSize.y; // fontSize; mLineHeight = label.height; } else { mCharacterSize = mLineHeight = 1; } ImportVerticesFromNGUI(vertices, uvs, colors, normals, tangents, uvs2); ModifyVertices(); ExportVerticesToNGUI(vertices, uvs, colors, normals, tangents, uvs2); }
static int CalculateBounds(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 1) { UIWidget obj = (UIWidget)ToLua.CheckObject<UIWidget>(L, 1); UnityEngine.Bounds o = obj.CalculateBounds(); ToLua.Push(L, o); return 1; } else if (count == 2) { UIWidget obj = (UIWidget)ToLua.CheckObject<UIWidget>(L, 1); UnityEngine.Transform arg0 = (UnityEngine.Transform)ToLua.CheckObject<UnityEngine.Transform>(L, 2); UnityEngine.Bounds o = obj.CalculateBounds(arg0); ToLua.Push(L, o); return 1; } else { return LuaDLL.luaL_throw(L, "invalid arguments to method: UIWidget.CalculateBounds"); } } catch (Exception e) { return LuaDLL.toluaL_exception(L, e); } }
static public int CalculateBounds(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 1) { UIWidget self = (UIWidget)checkSelf(l); var ret = self.CalculateBounds(); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 2) { UIWidget self = (UIWidget)checkSelf(l); UnityEngine.Transform a1; checkType(l, 2, out a1); var ret = self.CalculateBounds(a1); pushValue(l, true); pushValue(l, ret); return(2); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
private void Update() { if ((!(mAnim != null) || !mAnim.isPlaying) && style != 0) { UIWidget uIWidget = (!(container == null)) ? container.GetComponent <UIWidget>() : null; UIPanel uIPanel = (!(container == null) || !(uIWidget == null)) ? container.GetComponent <UIPanel>() : null; float num = 1f; if (uIWidget != null) { Bounds bounds = uIWidget.CalculateBounds(base.transform.parent); ref Rect reference = ref mRect; Vector3 min = bounds.min; reference.x = min.x; ref Rect reference2 = ref mRect; Vector3 min2 = bounds.min; reference2.y = min2.y; ref Rect reference3 = ref mRect;
private void Update() { if (!(mAnim != null) || !mAnim.enabled || !mAnim.isPlaying) { bool flag = false; UIWidget uIWidget = (!(container == null)) ? container.GetComponent <UIWidget>() : null; UIPanel uIPanel = (!(container == null) || !(uIWidget == null)) ? container.GetComponent <UIPanel>() : null; if (uIWidget != null) { Bounds bounds = uIWidget.CalculateBounds(container.transform.parent); ref Rect reference = ref mRect; Vector3 min = bounds.min; reference.x = min.x; ref Rect reference2 = ref mRect; Vector3 min2 = bounds.min; reference2.y = min2.y; ref Rect reference3 = ref mRect;
void Replace() { UIWidget widget = GetComponentInChildren <UIWidget>(); if (widget == null) { Debug.LogError("Widget placeholder can not be used without widget."); } GameObject obj = GameObject.Instantiate(prefab) as GameObject; UIWidget new_widget = obj.GetComponentInChildren <UIWidget>(); if (new_widget == null) { Debug.LogError("The prefab isn't a widget."); } obj.name = gameObject.name; obj.transform.parent = transform.parent; obj.transform.localPosition = transform.localPosition; obj.transform.localRotation = transform.localRotation; obj.transform.localScale = transform.localScale; new_widget.alpha = widget.alpha; Bounds bounds = widget.CalculateBounds(transform.parent); new_widget.SetRect(bounds.min.x, bounds.min.y, bounds.size.x, bounds.size.y); new_widget.width = widget.width; new_widget.height = widget.height; new_widget.aspectRatio = widget.aspectRatio; new_widget.keepAspectRatio = widget.keepAspectRatio; new_widget.leftAnchor = widget.leftAnchor; new_widget.rightAnchor = widget.rightAnchor; new_widget.topAnchor = widget.topAnchor; new_widget.bottomAnchor = widget.bottomAnchor; new_widget.ResetAnchors(); new_widget.UpdateAnchors(); NGUITools.AdjustDepth(new_widget.gameObject, widget.depth - new_widget.depth); UIPanel panel = GetComponent <UIPanel>(); if (panel != null) { UIPanel new_panel = obj.GetComponent <UIPanel>(); NGUITools.AdjustDepth(new_panel.gameObject, panel.depth - new_panel.depth); } NGUITools.Destroy(gameObject); gameObject.SetActive(false); //TODO: Sometimes, it will not be destroyed. spawnedObj = obj; }
private void Update() { if (((UnityEngine.Object)mAnim != null && mAnim.isPlaying) || style == Style.None) { return; } UIWidget uIWidget = (!(container == null)) ? container.GetComponent <UIWidget>() : null; UIPanel uIPanel = (!(container == null) || !(uIWidget == null)) ? container.GetComponent <UIPanel>() : null; float num = 1f; if (uIWidget != null) { Bounds bounds = uIWidget.CalculateBounds(base.transform.parent); ref Rect reference = ref mRect; Vector3 min = bounds.min; reference.x = min.x; ref Rect reference2 = ref mRect;
private void Update() { if ((UnityEngine.Object)mAnim != null && ((Behaviour)mAnim).enabled && mAnim.isPlaying) { return; } bool flag = false; UIWidget uIWidget = (!(container == null)) ? container.GetComponent <UIWidget>() : null; UIPanel uIPanel = (!(container == null) || !(uIWidget == null)) ? container.GetComponent <UIPanel>() : null; if (uIWidget != null) { Bounds bounds = uIWidget.CalculateBounds(container.transform.parent); ref Rect reference = ref mRect; Vector3 min = bounds.min; reference.x = min.x; ref Rect reference2 = ref mRect;
void GetPos() { if (m_widget == null) { return; } bounds = m_widget.CalculateBounds(); Vector3 min = bounds.min; Vector3 max = bounds.max; m_lstPos.Clear(); Vector3 pos = new Vector3(min.x, min.y, 0); m_lstPos.Add(pos); pos = new Vector3(min.x, max.y, 0); m_lstPos.Add(pos); pos = new Vector3(max.x, max.y, 0); m_lstPos.Add(pos); pos = new Vector3(max.x, min.y, 0); m_lstPos.Add(pos); }
private void Update() { if (this.mAnim != null && this.mAnim.enabled && this.mAnim.isPlaying) { return; } if (this.mTrans == null) { 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; } }
private void Update() { if (this.mAnim != null && this.mAnim.get_enabled() && this.mAnim.get_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.get_transform().get_parent()); this.mRect.set_x(bounds.get_min().x); this.mRect.set_y(bounds.get_min().y); this.mRect.set_width(bounds.get_size().x); this.mRect.set_height(bounds.get_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.get_height() * 0.5f); this.mRect.set_xMin((float)(-(float)Screen.get_width()) * num); this.mRect.set_yMin((float)(-(float)Screen.get_height()) * num); this.mRect.set_xMax(-this.mRect.get_xMin()); this.mRect.set_yMax(-this.mRect.get_yMin()); } else { Vector4 finalClipRegion = uIPanel.finalClipRegion; this.mRect.set_x(finalClipRegion.x - finalClipRegion.z * 0.5f); this.mRect.set_y(finalClipRegion.y - finalClipRegion.w * 0.5f); this.mRect.set_width(finalClipRegion.z); this.mRect.set_height(finalClipRegion.w); } } else if (this.container != null) { Transform parent = this.container.get_transform().get_parent(); Bounds bounds2 = (!(parent != null)) ? NGUIMath.CalculateRelativeWidgetBounds(this.container.get_transform()) : NGUIMath.CalculateRelativeWidgetBounds(parent, this.container.get_transform()); this.mRect.set_x(bounds2.get_min().x); this.mRect.set_y(bounds2.get_min().y); this.mRect.set_width(bounds2.get_size().x); this.mRect.set_height(bounds2.get_size().y); } else { if (!(this.uiCamera != null)) { return; } flag = true; this.mRect = this.uiCamera.get_pixelRect(); } float num2 = (this.mRect.get_xMin() + this.mRect.get_xMax()) * 0.5f; float num3 = (this.mRect.get_yMin() + this.mRect.get_yMax()) * 0.5f; Vector3 vector = new Vector3(num2, num3, 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.get_xMax(); } else if (this.side == UIAnchor.Side.Top || this.side == UIAnchor.Side.Center || this.side == UIAnchor.Side.Bottom) { vector.x = num2; } else { vector.x = this.mRect.get_xMin(); } if (this.side == UIAnchor.Side.Top || this.side == UIAnchor.Side.TopRight || this.side == UIAnchor.Side.TopLeft) { vector.y = this.mRect.get_yMax(); } else if (this.side == UIAnchor.Side.Left || this.side == UIAnchor.Side.Center || this.side == UIAnchor.Side.Right) { vector.y = num3; } else { vector.y = this.mRect.get_yMin(); } } float width = this.mRect.get_width(); float height = this.mRect.get_height(); vector.x += this.pixelOffset.x + this.relativeOffset.x * width; vector.y += this.pixelOffset.y + this.relativeOffset.y * height; if (flag) { if (this.uiCamera.get_orthographic()) { vector.x = Mathf.Round(vector.x); vector.y = Mathf.Round(vector.y); } vector.z = this.uiCamera.WorldToScreenPoint(this.mTrans.get_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.get_transform().get_parent(); if (parent2 != null) { vector = parent2.TransformPoint(vector); } } vector.z = this.mTrans.get_position().z; } if (this.mTrans.get_position() != vector) { this.mTrans.set_position(vector); } if (this.runOnlyOnce && Application.get_isPlaying()) { base.set_enabled(false); } }
private void Update() { if (mAnim != null && mAnim.enabled && mAnim.isPlaying) { return; } bool flag = false; UIWidget uIWidget = ((container == null) ? null : container.GetComponent <UIWidget>()); UIPanel uIPanel = ((container == null && uIWidget == null) ? null : container.GetComponent <UIPanel>()); if (uIWidget != null) { Bounds bounds = uIWidget.CalculateBounds(container.transform.parent); mRect.x = bounds.min.x; mRect.y = bounds.min.y; mRect.width = bounds.size.x; mRect.height = bounds.size.y; } else if (uIPanel != null) { if (uIPanel.clipping == UIDrawCall.Clipping.None) { float num = ((mRoot != null) ? ((float)mRoot.activeHeight / (float)Screen.height * 0.5f) : 0.5f); mRect.xMin = (float)(-Screen.width) * num; mRect.yMin = (float)(-Screen.height) * num; mRect.xMax = 0f - mRect.xMin; mRect.yMax = 0f - mRect.yMin; } else { Vector4 finalClipRegion = uIPanel.finalClipRegion; mRect.x = finalClipRegion.x - finalClipRegion.z * 0.5f; mRect.y = finalClipRegion.y - finalClipRegion.w * 0.5f; mRect.width = finalClipRegion.z; mRect.height = finalClipRegion.w; } } else if (container != null) { Transform parent = container.transform.parent; Bounds bounds = ((parent != null) ? NGUIMath.CalculateRelativeWidgetBounds(parent, container.transform) : NGUIMath.CalculateRelativeWidgetBounds(container.transform)); mRect.x = bounds.min.x; mRect.y = bounds.min.y; mRect.width = bounds.size.x; mRect.height = bounds.size.y; } else { if (!(uiCamera != null)) { return; } flag = true; mRect = uiCamera.pixelRect; } float x = (mRect.xMin + mRect.xMax) * 0.5f; float y = (mRect.yMin + mRect.yMax) * 0.5f; Vector3 vector = new Vector3(x, y, 0f); if (side != Side.Center) { if (side == Side.Right || side == Side.TopRight || side == Side.BottomRight) { vector.x = mRect.xMax; } else if (side == Side.Top || side == Side.Center || side == Side.Bottom) { vector.x = x; } else { vector.x = mRect.xMin; } if (side == Side.Top || side == Side.TopRight || side == Side.TopLeft) { vector.y = mRect.yMax; } else if (side == Side.Left || side == Side.Center || side == Side.Right) { vector.y = y; } else { vector.y = mRect.yMin; } } float width = mRect.width; float height = mRect.height; vector.x += pixelOffset.x + relativeOffset.x * width; vector.y += pixelOffset.y + relativeOffset.y * height; if (flag) { if (uiCamera.orthographic) { vector.x = Mathf.Round(vector.x); vector.y = Mathf.Round(vector.y); } vector.z = uiCamera.WorldToScreenPoint(mTrans.position).z; vector = 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 (container != null) { Transform parent2 = container.transform.parent; if (parent2 != null) { vector = parent2.TransformPoint(vector); } } vector.z = mTrans.position.z; } if (mTrans.position != vector) { mTrans.position = vector; } if (runOnlyOnce && Application.isPlaying) { base.enabled = false; } }
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 pos = pc.clipRange; 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 = 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; } 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.Both || style == Style.Horizontal) { size.x = relativeSize.x * rectWidth; } if (style == Style.Both || style == Style.Vertical) { size.y = relativeSize.y * rectHeight; } } UIWidget w = mTrans.GetComponent <UIWidget>(); if (w != null) { w.width = Mathf.RoundToInt(size.x); w.height = Mathf.RoundToInt(size.y); size = Vector3.one; } if (mTrans.localScale != size) { mTrans.localScale = size; } if (runOnlyOnce && Application.isPlaying) { Destroy(this); } } }
private void Update() { if (this.mAnim != null && this.mAnim.get_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.get_transform().get_parent()); this.mRect.set_x(bounds.get_min().x); this.mRect.set_y(bounds.get_min().y); this.mRect.set_width(bounds.get_size().x); this.mRect.set_height(bounds.get_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.get_height() * 0.5f); this.mRect.set_xMin((float)(-(float)Screen.get_width()) * num2); this.mRect.set_yMin((float)(-(float)Screen.get_height()) * num2); this.mRect.set_xMax(-this.mRect.get_xMin()); this.mRect.set_yMax(-this.mRect.get_yMin()); } else { Vector4 finalClipRegion = uIPanel.finalClipRegion; this.mRect.set_x(finalClipRegion.x - finalClipRegion.z * 0.5f); this.mRect.set_y(finalClipRegion.y - finalClipRegion.w * 0.5f); this.mRect.set_width(finalClipRegion.z); this.mRect.set_height(finalClipRegion.w); } } else if (this.container != null) { Transform parent = base.get_transform().get_parent(); Bounds bounds2 = (!(parent != null)) ? NGUIMath.CalculateRelativeWidgetBounds(this.container.get_transform()) : NGUIMath.CalculateRelativeWidgetBounds(parent, this.container.get_transform()); this.mRect.set_x(bounds2.get_min().x); this.mRect.set_y(bounds2.get_min().y); this.mRect.set_width(bounds2.get_size().x); this.mRect.set_height(bounds2.get_size().y); } else { if (!(this.uiCamera != null)) { return; } this.mRect = this.uiCamera.get_pixelRect(); if (this.mRoot != null) { num = this.mRoot.pixelSizeAdjustment; } } float num3 = this.mRect.get_width(); float num4 = this.mRect.get_height(); if (num != 1f && num4 > 1f) { float num5 = (float)this.mRoot.activeHeight / num4; num3 *= num5; num4 *= num5; } Vector3 vector = (!(this.mWidget != null)) ? this.mTrans.get_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.get_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.get_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.get_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.get_localScale() != vector) { this.mTrans.set_localScale(vector); } if (this.runOnlyOnce && Application.get_isPlaying()) { base.set_enabled(false); } } }
private void Update() { //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Expected O, but got Unknown //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Expected O, but got Unknown //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Expected O, but got Unknown //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0535: Unknown result type (might be due to invalid IL or missing references) //IL_053a: Unknown result type (might be due to invalid IL or missing references) //IL_053f: Unknown result type (might be due to invalid IL or missing references) //IL_0553: Unknown result type (might be due to invalid IL or missing references) //IL_0555: Unknown result type (might be due to invalid IL or missing references) //IL_055a: Unknown result type (might be due to invalid IL or missing references) //IL_0599: Unknown result type (might be due to invalid IL or missing references) //IL_059b: Unknown result type (might be due to invalid IL or missing references) //IL_05a0: Unknown result type (might be due to invalid IL or missing references) //IL_05be: Unknown result type (might be due to invalid IL or missing references) //IL_05c3: Unknown result type (might be due to invalid IL or missing references) //IL_05c8: Expected O, but got Unknown //IL_05d9: Unknown result type (might be due to invalid IL or missing references) //IL_05db: Unknown result type (might be due to invalid IL or missing references) //IL_05e0: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_05ef: Unknown result type (might be due to invalid IL or missing references) //IL_0619: Unknown result type (might be due to invalid IL or missing references) //IL_062f: Unknown result type (might be due to invalid IL or missing references) //IL_0634: Unknown result type (might be due to invalid IL or missing references) //IL_0636: Unknown result type (might be due to invalid IL or missing references) //IL_063b: Unknown result type (might be due to invalid IL or missing references) //IL_066b: Unknown result type (might be due to invalid IL or missing references) //IL_0670: Unknown result type (might be due to invalid IL or missing references) //IL_0682: Unknown result type (might be due to invalid IL or missing references) //IL_0694: Unknown result type (might be due to invalid IL or missing references) //IL_0699: Unknown result type (might be due to invalid IL or missing references) //IL_06ab: Unknown result type (might be due to invalid IL or missing references) if (!(mAnim != null) || !mAnim.get_enabled() || !mAnim.get_isPlaying()) { bool flag = false; UIWidget uIWidget = (!(container == null)) ? container.GetComponent <UIWidget>() : null; UIPanel uIPanel = (!(container == null) || !(uIWidget == null)) ? container.GetComponent <UIPanel>() : null; if (uIWidget != null) { Bounds val = uIWidget.CalculateBounds(container.get_transform().get_parent()); ref Rect reference = ref mRect; Vector3 min = val.get_min(); reference.set_x(min.x); ref Rect reference2 = ref mRect; Vector3 min2 = val.get_min(); reference2.set_y(min2.y); ref Rect reference3 = ref mRect;
/// <summary> /// Added by liangxiao, calculate widget value(-1 -- 2) relative to ScrollView, widget must be scroll view's child. /// </summary> /// <param name="widget">widget must be scroll view's child</param> /// <returns>value of x, value of y</returns> public Vector2 GetWidgetValueRelativeToScrollView(UIWidget widget) { if (mPanel == null) return new Vector2(-100, -100); Bounds bound = widget.CalculateBounds(); //Get bound relative to scroll view. Transform current = widget.transform; while (current != transform) { bound.center += current.localPosition; current = current.parent; } return new Vector2(GetBoundValueRelativeToScrollView(true, bound), GetBoundValueRelativeToScrollView(false, bound)); }
/// <summary> /// Added by liangxiao, set scroll view value(0 - 1) by specific widget, not whole bounds. /// </summary> /// <param name="widget">specific widget</param> /// <param name="value"></param> public void SetWidgetValueRelativeToScrollView(UIWidget widget, float value) { if (movement != Movement.Horizontal && movement != Movement.Vertical) { Debug.LogError("Cannot set widget value relative to scroll view cause scroll view not be single clip, contact to Liangxiao if you don't know what to do."); return; } Bounds bound = widget.CalculateBounds(); //Get bound relative to scroll view. Transform current = widget.transform; while (current != transform) { bound.center += current.localPosition; current = current.parent; } if (!mIgnoreCallbacks) { mIgnoreCallbacks = true; mCalculatedBounds = false; Vector2 pv = NGUIMath.GetPivotOffset(contentPivot); float x = (movement == Movement.Horizontal) ? value : pv.x; float y = (movement == Movement.Vertical) ? value : 1f - pv.y; SetDragManualAmount(x, y, bound, false); UpdateScrollbars(true); mIgnoreCallbacks = false; } }
private void Update() { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Expected O, but got Unknown //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Expected O, but got Unknown //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Expected O, but got Unknown //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03c7: Unknown result type (might be due to invalid IL or missing references) //IL_063d: Unknown result type (might be due to invalid IL or missing references) //IL_0642: Unknown result type (might be due to invalid IL or missing references) //IL_06b8: Unknown result type (might be due to invalid IL or missing references) //IL_06bd: Unknown result type (might be due to invalid IL or missing references) //IL_06db: Unknown result type (might be due to invalid IL or missing references) //IL_06e0: Unknown result type (might be due to invalid IL or missing references) //IL_0734: Unknown result type (might be due to invalid IL or missing references) //IL_073b: Unknown result type (might be due to invalid IL or missing references) //IL_0740: Unknown result type (might be due to invalid IL or missing references) //IL_0797: Unknown result type (might be due to invalid IL or missing references) //IL_079c: Unknown result type (might be due to invalid IL or missing references) //IL_07ae: Unknown result type (might be due to invalid IL or missing references) if ((!(mAnim != null) || !mAnim.get_isPlaying()) && style != 0) { UIWidget uIWidget = (!(container == null)) ? container.GetComponent <UIWidget>() : null; UIPanel uIPanel = (!(container == null) || !(uIWidget == null)) ? container.GetComponent <UIPanel>() : null; float num = 1f; if (uIWidget != null) { Bounds val = uIWidget.CalculateBounds(this.get_transform().get_parent()); ref Rect reference = ref mRect; Vector3 min = val.get_min(); reference.set_x(min.x); ref Rect reference2 = ref mRect; Vector3 min2 = val.get_min(); reference2.set_y(min2.y); ref Rect reference3 = ref mRect;
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)ResolutionConstrain.Instance.height * 0.5f); this.mRect.xMin = (float)(-(float)ResolutionConstrain.Instance.width) * num2; this.mRect.yMin = (float)(-(float)ResolutionConstrain.Instance.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 zero = Vector3.zero; zero.x = (float)this.mWidget.width; zero.y = (float)this.mWidget.height; Vector3 vector = (!(this.mWidget != null)) ? this.mTrans.localScale : zero; 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; } } }
/// <summary> /// Anchor the object to the appropriate point. /// </summary> 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) { Rect RectX = new Rect(0, 0, 1, 1); #if UNITY_EDITOR if (Application.isPlaying == false) { RectX = new Rect(0, 0, 1, 1); } #endif // Panel has no clipping -- just use the screen's dimensions float ratio = (mRoot != null) ? (float)mRoot.activeHeight / Screen.height * 0.5f : 0.5f; #if UNITY_EDITOR if (SideType == UIRect.EnumSideType.DontAdapt) #else if (SideType == UIRect.EnumSideType.DontAdapt || (SideType == UIRect.EnumSideType.AdaptCutoutAtLeft && Screen.orientation == ScreenOrientation.LandscapeRight) || (SideType == UIRect.EnumSideType.AdaptCutoutAtRight && Screen.orientation == ScreenOrientation.LandscapeLeft)) #endif { ratio *= 0.5f; mRect.xMin = -Screen.width * ratio; mRect.yMin = -Screen.height * ratio; mRect.xMax = -mRect.xMin; mRect.yMax = -mRect.yMin; } else if (SideType == UIRect.EnumSideType.AdaptTwoSide) { mRect.xMin = -Screen.width * ratio * (0.5f - RectX.x);; mRect.yMin = -Screen.height * ratio * (0.5f - RectX.y); mRect.xMax = Screen.width * ratio * (RectX.x + RectX.width - 0.5f); mRect.yMax = Screen.height * ratio * (RectX.y + RectX.height - 0.5f); } #if UNITY_EDITOR else if (SideType == UIRect.EnumSideType.AdaptCutoutAtLeft) #else else if (SideType == UIRect.EnumSideType.AdaptCutoutAtLeft && Screen.orientation == ScreenOrientation.LandscapeLeft) #endif { mRect.xMin = -Screen.width * ratio * (0.5f - RectX.x); mRect.yMin = -Screen.height * ratio * (0.5f - RectX.y); mRect.xMax = Screen.width * ratio * 0.5f; mRect.yMax = Screen.height * ratio * (RectX.y + RectX.height - 0.5f); } #if UNITY_EDITOR else if (SideType == UIRect.EnumSideType.AdaptCutoutAtRight) #else else if (SideType == UIRect.EnumSideType.AdaptCutoutAtRight && Screen.orientation == ScreenOrientation.LandscapeRight) #endif { mRect.xMin = -Screen.width * ratio * 0.5f; mRect.yMin = -Screen.height * ratio * (0.5f - RectX.y); mRect.xMax = Screen.width * ratio * (RectX.x + RectX.width - 0.5f); mRect.yMax = Screen.height * ratio * (RectX.y + RectX.height - 0.5f); } } 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; mRect = uiCamera.pixelRect; Rect RectX = new Rect(0, 0, 1, 1); #if UNITY_EDITOR if (Application.isPlaying == false) { RectX = new Rect(0, 0, 1, 1); } #endif if (SideType == UIRect.EnumSideType.AdaptTwoSide) { mRect.x = uiCamera.pixelRect.width * RectX.x; mRect.y = uiCamera.pixelRect.height * RectX.y; mRect.width = uiCamera.pixelRect.width * RectX.width; mRect.height = uiCamera.pixelRect.height * RectX.height; } #if UNITY_EDITOR else if (SideType == UIRect.EnumSideType.AdaptCutoutAtLeft) #else else if (SideType == UIRect.EnumSideType.AdaptCutoutAtLeft && Screen.orientation == ScreenOrientation.LandscapeLeft) #endif { mRect.x = uiCamera.pixelRect.width * RectX.x; mRect.y = uiCamera.pixelRect.height * RectX.y; mRect.width = uiCamera.pixelRect.width * (1.0f - RectX.x); mRect.height = uiCamera.pixelRect.height * RectX.height; } #if UNITY_EDITOR else if (SideType == UIRect.EnumSideType.AdaptCutoutAtRight) #else else if (SideType == UIRect.EnumSideType.AdaptCutoutAtRight && Screen.orientation == ScreenOrientation.LandscapeRight) #endif { mRect.y = uiCamera.pixelRect.height * RectX.y; mRect.width = uiCamera.pixelRect.width * (RectX.x + RectX.width); mRect.height = uiCamera.pixelRect.height * RectX.height; } } 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 UNITY_4_3 || UNITY_4_5 || UNITY_4_6 if (useCamera && uiCamera.isOrthoGraphic && mTrans.parent != null) #else if (useCamera && uiCamera.orthographic && mTrans.parent != null) #endif { v = mTrans.parent.InverseTransformPoint(v); v.x = Mathf.RoundToInt(v.x); v.y = Mathf.RoundToInt(v.y); if (mTrans.localPosition != v) { mTrans.localPosition = v; } } else if (mTrans.position != v) { mTrans.position = v; } if (runOnlyOnce && Application.isPlaying) { enabled = false; } }
/// <summary> /// Anchor the object to the appropriate point. /// </summary> 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 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 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; mRect = uiCamera.pixelRect; } 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; } }
public static bool IsDragClick(Vector3 from, Vector3 to, UIWidget ui) { from -= instance.halfExtens; to -= instance.halfExtens; Bounds bd = ui.CalculateBounds(UIRoot.list[0].transform); //如果有一个点在矩形内就算划到 if (bd.Contains(from) || bd.Contains(to)) { return(true); } float x0 = bd.center.x - bd.extents.x; float x1 = bd.center.x + bd.extents.x; float y0 = bd.center.y - bd.extents.y; float y1 = bd.center.y + bd.extents.y; //如果两点都在矩形的同一个边的外面,则必定没有划到 if ((from.x < x0 && to.x < x0) || (from.x > x1 && to.x > x1) || (from.y < y0 && to.y < y0) || (from.y > y1 && to.y > y1)) { return(false); } //如果两点不在同一边外面,则判断两点所在直线与矩形的四边所在直线的交点是否落在矩形边上 //y = ax + b 或者 x = c float a, b, c; if (from.x == to.x) { c = from.x; return(c >= x0 && c <= x1); } a = (from.y - to.y) / (from.x - to.x); b = from.y - a * from.x; if (a == 0) { return(b >= y0 && b <= y1); } float x0_y = a * x0 + b; if (x0_y >= y0 && x0_y <= y1) { return(true); } float x1_y = a * x1 + b; if (x1_y >= y0 && x1_y <= y1) { return(true); } float y0_x = (y0 - b) / a; if (y0_x >= x0 && y0_x <= x1) { return(true); } float y1_x = (y1 - b) / a; if (y1_x >= x0 && y1_x <= x1) { return(true); } return(false); }
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; } NGUITools.UpdateWidgetCollider(gameObject); if (runOnlyOnce && Application.isPlaying) { enabled = false; } } }
private void Update() { if ((mAnim != null && mAnim.isPlaying) || style == Style.None) { return; } UIWidget uIWidget = ((container == null) ? null : container.GetComponent <UIWidget>()); UIPanel uIPanel = ((container == null && uIWidget == null) ? null : container.GetComponent <UIPanel>()); float num = 1f; Vector4 baseClipRegion; if (uIWidget != null) { Bounds bounds = uIWidget.CalculateBounds(base.transform.parent); mRect.x = bounds.min.x; mRect.y = bounds.min.y; mRect.width = bounds.size.x; mRect.height = bounds.size.y; } else if (uIPanel != null) { if (uIPanel.clipping == UIDrawCall.Clipping.None) { float num2 = ((mRoot != null) ? ((float)mRoot.activeHeight / (float)Screen.height * 0.5f) : 0.5f); mRect.xMin = (float)(-Screen.width) * num2; mRect.yMin = (float)(-Screen.height) * num2; mRect.xMax = 0f - mRect.xMin; mRect.yMax = 0f - mRect.yMin; } else { baseClipRegion = uIPanel.finalClipRegion; mRect.x = baseClipRegion.x - baseClipRegion.z * 0.5f; mRect.y = baseClipRegion.y - baseClipRegion.w * 0.5f; mRect.width = baseClipRegion.z; mRect.height = baseClipRegion.w; } } else if (container != null) { Transform parent = base.transform.parent; Bounds bounds = ((parent != null) ? NGUIMath.CalculateRelativeWidgetBounds(parent, container.transform) : NGUIMath.CalculateRelativeWidgetBounds(container.transform)); mRect.x = bounds.min.x; mRect.y = bounds.min.y; mRect.width = bounds.size.x; mRect.height = bounds.size.y; } else { if (!(uiCamera != null)) { return; } mRect = uiCamera.pixelRect; if (mRoot != null) { num = mRoot.pixelSizeAdjustment; } } float num3 = mRect.width; float num4 = mRect.height; if (num != 1f && num4 > 1f) { float num5 = (float)mRoot.activeHeight / num4; num3 *= num5; num4 *= num5; } Vector3 vector = ((mWidget != null) ? new Vector3(mWidget.width, mWidget.height) : mTrans.localScale); if (style == Style.BasedOnHeight) { vector.x = relativeSize.x * num4; vector.y = relativeSize.y * num4; } else if (style == Style.FillKeepingRatio) { float num6 = num3 / num4; float num7 = initialSize.x / initialSize.y; if (num7 < num6) { float num5 = num3 / initialSize.x; vector.x = num3; vector.y = initialSize.y * num5; } else { float num5 = num4 / initialSize.y; vector.x = initialSize.x * num5; vector.y = num4; } } else if (style == Style.FitInternalKeepingRatio) { float num6 = num3 / num4; float num7 = initialSize.x / initialSize.y; if (num7 > num6) { float num5 = num3 / initialSize.x; vector.x = num3; vector.y = initialSize.y * num5; } else { float num5 = num4 / initialSize.y; vector.x = initialSize.x * num5; vector.y = num4; } } else { if (style != Style.Vertical) { vector.x = relativeSize.x * num3; } if (style != Style.Horizontal) { vector.y = relativeSize.y * num4; } } if (mSprite != null) { float num8 = ((mSprite.atlas != null) ? mSprite.atlas.pixelSize : 1f); vector.x -= borderPadding.x * num8; vector.y -= borderPadding.y * num8; if (style != Style.Vertical) { mSprite.width = Mathf.RoundToInt(vector.x); } if (style != Style.Horizontal) { mSprite.height = Mathf.RoundToInt(vector.y); } vector = Vector3.one; } else if (mWidget != null) { if (style != Style.Vertical) { mWidget.width = Mathf.RoundToInt(vector.x - borderPadding.x); } if (style != Style.Horizontal) { mWidget.height = Mathf.RoundToInt(vector.y - borderPadding.y); } vector = Vector3.one; } else if (mPanel != null) { baseClipRegion = mPanel.baseClipRegion; if (style != Style.Vertical) { baseClipRegion.z = vector.x - borderPadding.x; } if (style != Style.Horizontal) { baseClipRegion.w = vector.y - borderPadding.y; } mPanel.baseClipRegion = baseClipRegion; vector = Vector3.one; } else { if (style != Style.Vertical) { vector.x -= borderPadding.x; } if (style != Style.Horizontal) { vector.y -= borderPadding.y; } } if (mTrans.localScale != vector) { mTrans.localScale = vector; } if (runOnlyOnce && Application.isPlaying) { base.enabled = false; } }