// Token: 0x0600021F RID: 543 RVA: 0x00017F74 File Offset: 0x00016174 protected virtual void ResetPosition(List <Transform> list) { this.mReposition = false; int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int i = 0; int count = list.Count; while (i < count) { Transform transform = list[i]; Vector3 vector = transform.localPosition; float z = vector.z; if (this.arrangement == UIGrid.Arrangement.CellSnap) { if (this.cellWidth > 0f) { vector.x = Mathf.Round(vector.x / this.cellWidth) * this.cellWidth; } if (this.cellHeight > 0f) { vector.y = Mathf.Round(vector.y / this.cellHeight) * this.cellHeight; } } else { vector = ((this.arrangement == UIGrid.Arrangement.Horizontal) ? new Vector3(this.cellWidth * (float)num, -this.cellHeight * (float)num2, z) : new Vector3(this.cellWidth * (float)num2, -this.cellHeight * (float)num, z)); } if (this.animateSmoothly && Application.isPlaying && (this.pivot != UIWidget.Pivot.TopLeft || Vector3.SqrMagnitude(transform.localPosition - vector) >= 0.0001f)) { SpringPosition springPosition = SpringPosition.Begin(transform.gameObject, vector, 15f); springPosition.updateScrollView = true; springPosition.ignoreTimeScale = true; } else { transform.localPosition = vector; } num3 = Mathf.Max(num3, num); num4 = Mathf.Max(num4, num2); if (++num >= this.maxPerLine && this.maxPerLine > 0) { num = 0; num2++; } i++; } if (this.pivot != UIWidget.Pivot.TopLeft) { Vector2 pivotOffset = NGUIMath.GetPivotOffset(this.pivot); float num5; float num6; if (this.arrangement == UIGrid.Arrangement.Horizontal) { num5 = Mathf.Lerp(0f, (float)num3 * this.cellWidth, pivotOffset.x); num6 = Mathf.Lerp((float)(-(float)num4) * this.cellHeight, 0f, pivotOffset.y); } else { num5 = Mathf.Lerp(0f, (float)num4 * this.cellWidth, pivotOffset.x); num6 = Mathf.Lerp((float)(-(float)num3) * this.cellHeight, 0f, pivotOffset.y); } foreach (Transform transform2 in list) { SpringPosition component = transform2.GetComponent <SpringPosition>(); if (component != null) { component.enabled = false; SpringPosition springPosition2 = component; springPosition2.target.x = springPosition2.target.x - num5; SpringPosition springPosition3 = component; springPosition3.target.y = springPosition3.target.y - num6; component.enabled = true; } else { Vector3 localPosition = transform2.localPosition; localPosition.x -= num5; localPosition.y -= num6; transform2.localPosition = localPosition; } } } }
/// <summary> /// The reverse of ParseColor -- encodes a color in RrGgBb format. /// </summary> static public string EncodeColor(Color c) { int i = 0xFFFFFF & (NGUIMath.ColorToInt(c) >> 8); return(NGUIMath.DecimalToHex(i)); }
public override void OnFill(MeshBuffer m) { Vertex vertex = new Vertex(); Vertex vertex1 = new Vertex(); Vertex vertex2 = new Vertex(); Vertex vertex3 = new Vertex(); Texture texture = base.material.mainTexture; if (texture == null) { return; } Rect pixels = this.mInner; if (base.atlas.coordinates == UIAtlas.Coordinates.TexCoords) { pixels = NGUIMath.ConvertToPixels(pixels, texture.width, texture.height, true); } Vector2 vector2 = base.cachedTransform.localScale; float single = base.atlas.pixelSize; float single1 = Mathf.Abs(pixels.width / vector2.x) * single; float single2 = Mathf.Abs(pixels.height / vector2.y) * single; if (single1 < 0.01f || single2 < 0.01f) { Debug.LogWarning(string.Concat("The tiled sprite (", NGUITools.GetHierarchy(base.gameObject), ") is too small.\nConsider using a bigger one.")); single1 = 0.01f; single2 = 0.01f; } Vector2 vector21 = new Vector2(pixels.xMin / (float)texture.width, pixels.yMin / (float)texture.height); Vector2 vector22 = new Vector2(pixels.xMax / (float)texture.width, pixels.yMax / (float)texture.height); Vector2 vector23 = vector22; float single3 = 0f; Color color = base.color; float single4 = color.r; float single5 = single4; vertex3.r = single4; float single6 = single5; single5 = single6; vertex2.r = single6; float single7 = single5; single5 = single7; vertex1.r = single7; vertex.r = single5; float single8 = color.g; single5 = single8; vertex3.g = single8; float single9 = single5; single5 = single9; vertex2.g = single9; float single10 = single5; single5 = single10; vertex1.g = single10; vertex.g = single5; float single11 = color.b; single5 = single11; vertex3.b = single11; float single12 = single5; single5 = single12; vertex2.b = single12; float single13 = single5; single5 = single13; vertex1.b = single13; vertex.b = single5; float single14 = color.a; single5 = single14; vertex3.a = single14; float single15 = single5; single5 = single15; vertex2.a = single15; float single16 = single5; single5 = single16; vertex1.a = single16; vertex.a = single5; float single17 = 0f; single5 = single17; vertex3.z = single17; float single18 = single5; single5 = single18; vertex2.z = single18; float single19 = single5; single5 = single19; vertex1.z = single19; vertex.z = single5; while (single3 < 1f) { float single20 = 0f; vector23.x = vector22.x; float single21 = single3 + single2; if (single21 > 1f) { vector23.y = vector21.y + (vector22.y - vector21.y) * (1f - single3) / (single21 - single3); single21 = 1f; } while (single20 < 1f) { float single22 = single20 + single1; if (single22 > 1f) { vector23.x = vector21.x + (vector22.x - vector21.x) * (1f - single20) / (single22 - single20); single22 = 1f; } vertex.x = single22; vertex.y = -single3; vertex1.x = single22; vertex1.y = -single21; vertex2.x = single20; vertex2.y = -single21; vertex3.x = single20; vertex3.y = -single3; vertex.u = vector23.x; vertex.v = 1f - vector21.y; vertex1.u = vector23.x; vertex1.v = 1f - vector23.y; vertex2.u = vector21.x; vertex2.v = 1f - vector23.y; vertex3.u = vector21.x; vertex3.v = 1f - vector21.y; m.Quad(vertex, vertex1, vertex2, vertex3); single20 = single20 + single1; } single3 = single3 + single2; } }
/// <summary> /// Filled sprite fill function. /// </summary> void FilledFill(List <Vector3> verts, List <Vector2> uvs, List <Color> cols) { if (mFillAmount < 0.001f) { return; } Vector4 v = drawingDimensions; Vector4 u = drawingUVs; Color c = drawingColor; // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical) { if (mFillDirection == FillDirection.Horizontal) { float fill = (u.z - u.x) * mFillAmount; if (mInvert) { v.x = v.z - (v.z - v.x) * mFillAmount; u.x = u.z - fill; } else { v.z = v.x + (v.z - v.x) * mFillAmount; u.z = u.x + fill; } } else if (mFillDirection == FillDirection.Vertical) { float fill = (u.w - u.y) * mFillAmount; if (mInvert) { v.y = v.w - (v.w - v.y) * mFillAmount; u.y = u.w - fill; } else { v.w = v.y + (v.w - v.y) * mFillAmount; u.w = u.y + fill; } } } mTempPos[0] = new Vector2(v.x, v.y); mTempPos[1] = new Vector2(v.x, v.w); mTempPos[2] = new Vector2(v.z, v.w); mTempPos[3] = new Vector2(v.z, v.y); mTempUVs[0] = new Vector2(u.x, u.y); mTempUVs[1] = new Vector2(u.x, u.w); mTempUVs[2] = new Vector2(u.z, u.w); mTempUVs[3] = new Vector2(u.z, u.y); if (mFillAmount < 1f) { if (mFillDirection == FillDirection.Radial90) { if (RadialCut(mTempPos, mTempUVs, mFillAmount, mInvert, 0)) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } return; } if (mFillDirection == FillDirection.Radial180) { for (int side = 0; side < 2; ++side) { float fx0, fx1, fy0, fy1; fy0 = 0f; fy1 = 1f; if (side == 0) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } mTempPos[0].x = Mathf.Lerp(v.x, v.z, fx0); mTempPos[1].x = mTempPos[0].x; mTempPos[2].x = Mathf.Lerp(v.x, v.z, fx1); mTempPos[3].x = mTempPos[2].x; mTempPos[0].y = Mathf.Lerp(v.y, v.w, fy0); mTempPos[1].y = Mathf.Lerp(v.y, v.w, fy1); mTempPos[2].y = mTempPos[1].y; mTempPos[3].y = mTempPos[0].y; mTempUVs[0].x = Mathf.Lerp(u.x, u.z, fx0); mTempUVs[1].x = mTempUVs[0].x; mTempUVs[2].x = Mathf.Lerp(u.x, u.z, fx1); mTempUVs[3].x = mTempUVs[2].x; mTempUVs[0].y = Mathf.Lerp(u.y, u.w, fy0); mTempUVs[1].y = Mathf.Lerp(u.y, u.w, fy1); mTempUVs[2].y = mTempUVs[1].y; mTempUVs[3].y = mTempUVs[0].y; float val = !mInvert ? fillAmount * 2f - side : mFillAmount * 2f - (1 - side); if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(val), !mInvert, NGUIMath.RepeatIndex(side + 3, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } } return; } if (mFillDirection == FillDirection.Radial360) { for (int corner = 0; corner < 4; ++corner) { float fx0, fx1, fy0, fy1; if (corner < 2) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } if (corner == 0 || corner == 3) { fy0 = 0f; fy1 = 0.5f; } else { fy0 = 0.5f; fy1 = 1f; } mTempPos[0].x = Mathf.Lerp(v.x, v.z, fx0); mTempPos[1].x = mTempPos[0].x; mTempPos[2].x = Mathf.Lerp(v.x, v.z, fx1); mTempPos[3].x = mTempPos[2].x; mTempPos[0].y = Mathf.Lerp(v.y, v.w, fy0); mTempPos[1].y = Mathf.Lerp(v.y, v.w, fy1); mTempPos[2].y = mTempPos[1].y; mTempPos[3].y = mTempPos[0].y; mTempUVs[0].x = Mathf.Lerp(u.x, u.z, fx0); mTempUVs[1].x = mTempUVs[0].x; mTempUVs[2].x = Mathf.Lerp(u.x, u.z, fx1); mTempUVs[3].x = mTempUVs[2].x; mTempUVs[0].y = Mathf.Lerp(u.y, u.w, fy0); mTempUVs[1].y = Mathf.Lerp(u.y, u.w, fy1); mTempUVs[2].y = mTempUVs[1].y; mTempUVs[3].y = mTempUVs[0].y; float val = mInvert ? mFillAmount * 4f - NGUIMath.RepeatIndex(corner + 2, 4) : mFillAmount * 4f - (3 - NGUIMath.RepeatIndex(corner + 2, 4)); if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(val), mInvert, NGUIMath.RepeatIndex(corner + 2, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } } return; } } // Fill the buffer with the quad for the sprite for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } }
void OnWillRenderObject() { UpdateMaterials(); if (mBlock != null) { mRenderer.SetPropertyBlock(mBlock); } if (onRender != null) { onRender(mDynamicMat ?? mMaterial); } if (mDynamicMat == null || mClipCount == 0) { return; } if (mTextureClip) { Vector4 cr = panel.drawCallClipRange; Vector2 soft = panel.clipSoftness; Vector2 sharpness = new Vector2(1000.0f, 1000.0f); if (soft.x > 0f) { sharpness.x = cr.z / soft.x; } if (soft.y > 0f) { sharpness.y = cr.w / soft.y; } mDynamicMat.SetVector(ClipRange[0], new Vector4(-cr.x / cr.z, -cr.y / cr.w, 1f / cr.z, 1f / cr.w)); mDynamicMat.SetTexture("_ClipTex", clipTexture); } else if (!mLegacyShader) { UIPanel currentPanel = panel; for (int i = 0; currentPanel != null;) { if (currentPanel.hasClipping) { float angle = 0f; Vector4 cr = currentPanel.drawCallClipRange; // Clipping regions past the first one need additional math if (currentPanel != panel) { Vector3 pos = currentPanel.cachedTransform.InverseTransformPoint(panel.cachedTransform.position); cr.x -= pos.x; cr.y -= pos.y; Vector3 v0 = panel.cachedTransform.rotation.eulerAngles; Vector3 v1 = currentPanel.cachedTransform.rotation.eulerAngles; Vector3 diff = v1 - v0; diff.x = NGUIMath.WrapAngle(diff.x); diff.y = NGUIMath.WrapAngle(diff.y); diff.z = NGUIMath.WrapAngle(diff.z); if (Mathf.Abs(diff.x) > 0.001f || Mathf.Abs(diff.y) > 0.001f) { Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", panel); } angle = diff.z; } // Pass the clipping parameters to the shader SetClipping(i++, cr, currentPanel.clipSoftness, currentPanel.clipCorner, currentPanel.cornerSoft, currentPanel.cornerBorder, angle); } currentPanel = currentPanel.parentPanel; } } else // Legacy functionality { Vector2 soft = panel.clipSoftness; Vector4 cr = panel.drawCallClipRange; Vector2 v0 = new Vector2(-cr.x / cr.z, -cr.y / cr.w); Vector2 v1 = new Vector2(1f / cr.z, 1f / cr.w); Vector2 sharpness = new Vector2(1000.0f, 1000.0f); if (soft.x > 0f) { sharpness.x = cr.z / soft.x; } if (soft.y > 0f) { sharpness.y = cr.w / soft.y; } mDynamicMat.mainTextureOffset = v0; mDynamicMat.mainTextureScale = v1; mDynamicMat.SetVector("_ClipSharpness", sharpness); } }
/// <summary> /// Anchor the object to the appropriate point. /// </summary> void Update() { if (mAnim != null && mAnim.enabled && mAnim.isPlaying) { return; } if (mTrans == null) { 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 UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 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; } }
public void Recenter() { if (mScrollView == null) { mScrollView = NGUITools.FindInParents <UIScrollView>(gameObject); if (mScrollView == null) { Debug.LogWarning(GetType() + " requires " + typeof(UIScrollView) + " on a parent object in order to work", this); enabled = false; return; } else { if (mScrollView.horizontalScrollBar != null) { mScrollView.horizontalScrollBar.onDragFinished = OnDragFinished; } if (mScrollView.verticalScrollBar != null) { mScrollView.verticalScrollBar.onDragFinished = OnDragFinished; } } } if (mScrollView.panel == null) { return; } Transform trans = transform; if (trans.childCount == 0) { return; } // Calculate the panel's center in world coordinates Vector3[] corners = mScrollView.panel.worldCorners; Vector3 panelCenter = (corners[2] + corners[0]) * 0.5f; // Offset this value by the momentum Vector3 momentum = mScrollView.currentMomentum * mScrollView.momentumAmount; Vector3 moveDelta = NGUIMath.SpringDampen(ref momentum, 9f, 2f); Vector3 pickingPoint = panelCenter - moveDelta * 0.01f; // Magic number based on what "feels right" float min = float.MaxValue; Transform closest = null; int index = 0; // Determine the closest child for (int i = 0, imax = trans.childCount; i < imax; ++i) { Transform t = trans.GetChild(i); if (!t.gameObject.activeInHierarchy) { continue; } float sqrDist = Vector3.SqrMagnitude(t.position - pickingPoint); if (sqrDist < min) { min = sqrDist; closest = t; index = i; } } // If we have a touch in progress and the next page threshold set if (nextPageThreshold > 0f && UICamera.currentTouch != null) { // If we're still on the same object if (mCenteredObject != null && mCenteredObject.transform == trans.GetChild(index)) { Vector2 totalDelta = UICamera.currentTouch.totalDelta; float delta = 0f; switch (mScrollView.movement) { case UIScrollView.Movement.Horizontal: { delta = totalDelta.x; break; } case UIScrollView.Movement.Vertical: { delta = totalDelta.y; break; } default: { delta = totalDelta.magnitude; break; } } if (delta > nextPageThreshold) { // Next page if (index > 0) { closest = trans.GetChild(index - 1); } } else if (delta < -nextPageThreshold) { // Previous page if (index < trans.childCount - 1) { closest = trans.GetChild(index + 1); } } } } CenterOn(closest, panelCenter); }
/// <summary> /// Set the tooltip's text to the specified string. /// </summary> void SetText(string tooltipText) { if (text != null && !string.IsNullOrEmpty(tooltipText)) { mTarget = 1f; if (text != null) { text.text = tooltipText; } // Orthographic camera positioning is trivial mPos = Input.mousePosition; if (background != null) { Transform backgroundTrans = background.transform; Transform textTrans = text.transform; Vector3 offset = textTrans.localPosition; Vector3 textScale = textTrans.localScale; // Calculate the dimensions of the printed text mSize = text.relativeSize; // Scale by the transform and adjust by the padding offset mSize.x *= textScale.x; mSize.y *= textScale.y; mSize.x += background.border.x + background.border.z + (offset.x - background.border.x) * 2f; mSize.y += background.border.y + background.border.w + (-offset.y - background.border.y) * 2f; mSize.z = 1f; backgroundTrans.localScale = mSize; } if (uiCamera != null) { // Since the screen can be of different than expected size, we want to convert // mouse coordinates to view space, then convert that to world position. mPos.x = Mathf.Clamp01(mPos.x / Screen.width); mPos.y = Mathf.Clamp01(mPos.y / Screen.height); // Calculate the ratio of the camera's target orthographic size to current screen size float activeSize = uiCamera.orthographicSize / mTrans.parent.lossyScale.y; float ratio = (Screen.height * 0.5f) / activeSize; // Calculate the maximum on-screen size of the tooltip window Vector2 max = new Vector2(ratio * mSize.x / Screen.width, ratio * mSize.y / Screen.height); // Limit the tooltip to always be visible mPos.x = Mathf.Min(mPos.x, 1f - max.x); mPos.y = Mathf.Max(mPos.y, max.y); // Update the absolute position and save the local one mTrans.position = uiCamera.ViewportToWorldPoint(mPos); mPos = mTrans.localPosition; } else { // Don't let the tooltip leave the screen area if (mPos.x + mSize.x > Screen.width) { mPos.x = Screen.width - mSize.x; } if (mPos.y - mSize.y < 0f) { mPos.y = mSize.y; } // Simple calculation that assumes that the camera is of fixed size mPos.x -= Screen.width * 0.5f; mPos.y -= Screen.height * 0.5f; } // Set the final position mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mPos); } else { mTarget = 0f; } }
private void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (!(mFillAmount < 0.001f)) { Vector4 drawingDimensions = this.drawingDimensions; Vector4 drawingUVs = this.drawingUVs; Color32 drawingColor = this.drawingColor; if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical) { if (mFillDirection == FillDirection.Horizontal) { float num = (drawingUVs.z - drawingUVs.x) * mFillAmount; if (mInvert) { drawingDimensions.x = drawingDimensions.z - (drawingDimensions.z - drawingDimensions.x) * mFillAmount; drawingUVs.x = drawingUVs.z - num; } else { drawingDimensions.z = drawingDimensions.x + (drawingDimensions.z - drawingDimensions.x) * mFillAmount; drawingUVs.z = drawingUVs.x + num; } } else if (mFillDirection == FillDirection.Vertical) { float num2 = (drawingUVs.w - drawingUVs.y) * mFillAmount; if (mInvert) { drawingDimensions.y = drawingDimensions.w - (drawingDimensions.w - drawingDimensions.y) * mFillAmount; drawingUVs.y = drawingUVs.w - num2; } else { drawingDimensions.w = drawingDimensions.y + (drawingDimensions.w - drawingDimensions.y) * mFillAmount; drawingUVs.w = drawingUVs.y + num2; } } } mTempPos[0] = new Vector2(drawingDimensions.x, drawingDimensions.y); mTempPos[1] = new Vector2(drawingDimensions.x, drawingDimensions.w); mTempPos[2] = new Vector2(drawingDimensions.z, drawingDimensions.w); mTempPos[3] = new Vector2(drawingDimensions.z, drawingDimensions.y); mTempUVs[0] = new Vector2(drawingUVs.x, drawingUVs.y); mTempUVs[1] = new Vector2(drawingUVs.x, drawingUVs.w); mTempUVs[2] = new Vector2(drawingUVs.z, drawingUVs.w); mTempUVs[3] = new Vector2(drawingUVs.z, drawingUVs.y); if (mFillAmount < 1f) { if (mFillDirection == FillDirection.Radial90) { if (RadialCut(mTempPos, mTempUVs, mFillAmount, mInvert, 0)) { for (int i = 0; i < 4; i++) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(drawingColor); } } return; } if (mFillDirection == FillDirection.Radial180) { for (int j = 0; j < 2; j++) { float t = 0f; float t2 = 1f; float t3; float t4; if (j == 0) { t3 = 0f; t4 = 0.5f; } else { t3 = 0.5f; t4 = 1f; } mTempPos[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t3); mTempPos[1].x = mTempPos[0].x; mTempPos[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t4); mTempPos[3].x = mTempPos[2].x; mTempPos[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t); mTempPos[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t2); mTempPos[2].y = mTempPos[1].y; mTempPos[3].y = mTempPos[0].y; mTempUVs[0].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t3); mTempUVs[1].x = mTempUVs[0].x; mTempUVs[2].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t4); mTempUVs[3].x = mTempUVs[2].x; mTempUVs[0].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t); mTempUVs[1].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t2); mTempUVs[2].y = mTempUVs[1].y; mTempUVs[3].y = mTempUVs[0].y; float value = mInvert ? (mFillAmount * 2f - (float)(1 - j)) : (fillAmount * 2f - (float)j); if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(value), !mInvert, NGUIMath.RepeatIndex(j + 3, 4))) { for (int k = 0; k < 4; k++) { verts.Add(mTempPos[k]); uvs.Add(mTempUVs[k]); cols.Add(drawingColor); } } } return; } if (mFillDirection == FillDirection.Radial360) { for (int l = 0; l < 4; l++) { float t5; float t6; if (l < 2) { t5 = 0f; t6 = 0.5f; } else { t5 = 0.5f; t6 = 1f; } float t7; float t8; if (l == 0 || l == 3) { t7 = 0f; t8 = 0.5f; } else { t7 = 0.5f; t8 = 1f; } mTempPos[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t5); mTempPos[1].x = mTempPos[0].x; mTempPos[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t6); mTempPos[3].x = mTempPos[2].x; mTempPos[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t7); mTempPos[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t8); mTempPos[2].y = mTempPos[1].y; mTempPos[3].y = mTempPos[0].y; mTempUVs[0].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t5); mTempUVs[1].x = mTempUVs[0].x; mTempUVs[2].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t6); mTempUVs[3].x = mTempUVs[2].x; mTempUVs[0].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t7); mTempUVs[1].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t8); mTempUVs[2].y = mTempUVs[1].y; mTempUVs[3].y = mTempUVs[0].y; float value2 = (!mInvert) ? (mFillAmount * 4f - (float)(3 - NGUIMath.RepeatIndex(l + 2, 4))) : (mFillAmount * 4f - (float)NGUIMath.RepeatIndex(l + 2, 4)); if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(value2), mInvert, NGUIMath.RepeatIndex(l + 2, 4))) { for (int m = 0; m < 4; m++) { verts.Add(mTempPos[m]); uvs.Add(mTempUVs[m]); cols.Add(drawingColor); } } } return; } } for (int n = 0; n < 4; n++) { verts.Add(mTempPos[n]); uvs.Add(mTempUVs[n]); cols.Add(drawingColor); } } }
public void Show() { if (base.enabled && NGUITools.GetActive(base.gameObject) && mChild == null && atlas != null && isValid && items.Count > 0) { mLabelList.Clear(); if (mPanel == null) { mPanel = UIPanel.Find(base.transform); if (mPanel == null) { return; } } handleEvents = true; Transform transform = base.transform; Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(transform.parent, transform); mChild = new GameObject("Drop-down List"); mChild.layer = base.gameObject.layer; Transform transform2 = mChild.transform; transform2.parent = transform.parent; transform2.localPosition = bounds.min; transform2.localRotation = Quaternion.identity; transform2.localScale = Vector3.one; mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite); mBackground.pivot = UIWidget.Pivot.TopLeft; mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject); mBackground.color = backgroundColor; Vector4 border = mBackground.border; mBgBorder = border.y; mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f); mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite); mHighlight.pivot = UIWidget.Pivot.TopLeft; mHighlight.color = highlightColor; UISpriteData atlasSprite = mHighlight.GetAtlasSprite(); if (atlasSprite != null) { float num = (float)atlasSprite.borderTop; float num2 = (float)activeFontSize; float activeFontScale = this.activeFontScale; float num3 = num2 * activeFontScale; float num4 = 0f; float num5 = 0f - padding.y; List <UILabel> list = new List <UILabel>(); if (!items.Contains(mSelectedItem)) { mSelectedItem = null; } int i = 0; for (int count = items.Count; i < count; i++) { string text = items[i]; UILabel uILabel = NGUITools.AddWidget <UILabel>(mChild); uILabel.name = i.ToString(); uILabel.pivot = UIWidget.Pivot.TopLeft; uILabel.bitmapFont = bitmapFont; uILabel.trueTypeFont = trueTypeFont; uILabel.fontSize = fontSize; uILabel.fontStyle = fontStyle; uILabel.text = ((!isLocalized) ? text : Localization.Get(text)); uILabel.color = textColor; Transform cachedTransform = uILabel.cachedTransform; float num6 = border.x + padding.x; Vector2 pivotOffset = uILabel.pivotOffset; cachedTransform.localPosition = new Vector3(num6 - pivotOffset.x, num5, -1f); uILabel.overflowMethod = UILabel.Overflow.ResizeFreely; uILabel.alignment = alignment; list.Add(uILabel); num5 -= num3; num5 -= padding.y; float a = num4; Vector2 printedSize = uILabel.printedSize; num4 = Mathf.Max(a, printedSize.x); UIEventListener uIEventListener = UIEventListener.Get(uILabel.gameObject); uIEventListener.onHover = OnItemHover; uIEventListener.onPress = OnItemPress; uIEventListener.onClick = OnItemClick; uIEventListener.parameter = text; if (mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(mSelectedItem))) { Highlight(uILabel, instant: true); } mLabelList.Add(uILabel); } float a2 = num4; Vector3 size = bounds.size; num4 = Mathf.Max(a2, size.x * activeFontScale - (border.x + padding.x) * 2f); float num7 = num4; Vector3 vector = new Vector3(num7 * 0.5f, (0f - num2) * 0.5f, 0f); Vector3 vector2 = new Vector3(num7, num3 + padding.y, 1f); int j = 0; for (int count2 = list.Count; j < count2; j++) { UILabel uILabel2 = list[j]; NGUITools.AddWidgetCollider(uILabel2.gameObject); uILabel2.autoResizeBoxCollider = false; BoxCollider component = uILabel2.GetComponent <BoxCollider>(); if (component != null) { Vector3 center = component.center; vector.z = center.z; component.center = vector; component.size = vector2; } else { BoxCollider2D component2 = uILabel2.GetComponent <BoxCollider2D>(); component2.offset = vector; component2.size = vector2; } } int width = Mathf.RoundToInt(num4); num4 += (border.x + padding.x) * 2f; num5 -= border.y; mBackground.width = Mathf.RoundToInt(num4); mBackground.height = Mathf.RoundToInt(0f - num5 + border.y); int k = 0; for (int count3 = list.Count; k < count3; k++) { UILabel uILabel3 = list[k]; uILabel3.overflowMethod = UILabel.Overflow.ShrinkContent; uILabel3.width = width; } float num8 = 2f * atlas.pixelSize; float f = num4 - (border.x + padding.x) * 2f + (float)atlasSprite.borderLeft * num8; float f2 = num3 + num * num8; mHighlight.width = Mathf.RoundToInt(f); mHighlight.height = Mathf.RoundToInt(f2); bool flag = position == Position.Above; if (position == Position.Auto) { UICamera uICamera = UICamera.FindCameraForLayer(base.gameObject.layer); if (uICamera != null) { Vector3 vector3 = uICamera.cachedCamera.WorldToViewportPoint(transform.position); flag = (vector3.y < 0.5f); } } if (isAnimated) { float bottom = num5 + num3; Animate(mHighlight, flag, bottom); int l = 0; for (int count4 = list.Count; l < count4; l++) { Animate(list[l], flag, bottom); } AnimateColor(mBackground); AnimateScale(mBackground, flag, bottom); } if (flag) { Transform transform3 = transform2; Vector3 min = bounds.min; float x = min.x; Vector3 max = bounds.max; float y = max.y - num5 - border.y; Vector3 min2 = bounds.min; transform3.localPosition = new Vector3(x, y, min2.z); } } } else { OnSelect(isSelected: false); } }
void Update2() { 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) { count++; if (count == GameConfig.UpdateNGUIStretch) { enabled = false; } } } }
/// <summary> /// Draw the on-screen selection, knobs, and handle all interaction logic. /// </summary> public void OnSceneGUI() { if (Selection.objects.Length > 1) { return; } NGUIEditorTools.HideMoveTool(true); if (!UIWidget.showHandles) { return; } mWidget = target as UIWidget; Transform t = mWidget.cachedTransform; Event e = Event.current; int id = GUIUtility.GetControlID(s_Hash, FocusType.Passive); EventType type = e.GetTypeForControl(id); Action actionUnderMouse = mAction; Vector3[] handles = GetHandles(mWidget.worldCorners); NGUIHandles.DrawShadowedLine(handles, handles[0], handles[1], handlesColor); NGUIHandles.DrawShadowedLine(handles, handles[1], handles[2], handlesColor); NGUIHandles.DrawShadowedLine(handles, handles[2], handles[3], handlesColor); NGUIHandles.DrawShadowedLine(handles, handles[0], handles[3], handlesColor); // If the widget is anchored, draw the anchors if (mWidget.isAnchored) { DrawAnchorHandle(mWidget.leftAnchor, mWidget.cachedTransform, handles, 0, id); DrawAnchorHandle(mWidget.topAnchor, mWidget.cachedTransform, handles, 1, id); DrawAnchorHandle(mWidget.rightAnchor, mWidget.cachedTransform, handles, 2, id); DrawAnchorHandle(mWidget.bottomAnchor, mWidget.cachedTransform, handles, 3, id); } if (type == EventType.Repaint) { bool showDetails = (mAction == UIWidgetInspector.Action.Scale) || NGUISettings.drawGuides; if (mAction == UIWidgetInspector.Action.None && e.modifiers == EventModifiers.Control) { showDetails = true; } if (NGUITools.GetActive(mWidget) && mWidget.parent == null) { showDetails = true; } if (showDetails) { NGUIHandles.DrawSize(handles, mWidget.width, mWidget.height); } } // Presence of the legacy stretch component prevents resizing bool canResize = (mWidget.GetComponent <UIStretch>() == null); bool[] resizable = new bool[8]; resizable[4] = canResize; // left resizable[5] = canResize; // top resizable[6] = canResize; // right resizable[7] = canResize; // bottom UILabel lbl = mWidget as UILabel; if (lbl != null) { if (lbl.overflowMethod == UILabel.Overflow.ResizeFreely) { resizable[4] = false; // left resizable[5] = false; // top resizable[6] = false; // right resizable[7] = false; // bottom } else if (lbl.overflowMethod == UILabel.Overflow.ResizeHeight) { resizable[5] = false; // top resizable[7] = false; // bottom } } if (mWidget.keepAspectRatio == UIWidget.AspectRatioSource.BasedOnHeight) { resizable[4] = false; resizable[6] = false; } else if (mWidget.keepAspectRatio == UIWidget.AspectRatioSource.BasedOnWidth) { resizable[5] = false; resizable[7] = false; } resizable[0] = resizable[7] && resizable[4]; // bottom-left resizable[1] = resizable[5] && resizable[4]; // top-left resizable[2] = resizable[5] && resizable[6]; // top-right resizable[3] = resizable[7] && resizable[6]; // bottom-right UIWidget.Pivot pivotUnderMouse = GetPivotUnderMouse(handles, e, resizable, true, ref actionUnderMouse); switch (type) { case EventType.Repaint: { Vector3 v0 = HandleUtility.WorldToGUIPoint(handles[0]); Vector3 v2 = HandleUtility.WorldToGUIPoint(handles[2]); if ((v2 - v0).magnitude > 60f) { Vector3 v1 = HandleUtility.WorldToGUIPoint(handles[1]); Vector3 v3 = HandleUtility.WorldToGUIPoint(handles[3]); Handles.BeginGUI(); { for (int i = 0; i < 4; ++i) { DrawKnob(handles[i], mWidget.pivot == pivotPoints[i], resizable[i], id); } if ((v1 - v0).magnitude > 80f) { if (mWidget.leftAnchor.target == null || mWidget.leftAnchor.absolute != 0) { DrawKnob(handles[4], mWidget.pivot == pivotPoints[4], resizable[4], id); } if (mWidget.rightAnchor.target == null || mWidget.rightAnchor.absolute != 0) { DrawKnob(handles[6], mWidget.pivot == pivotPoints[6], resizable[6], id); } } if ((v3 - v0).magnitude > 80f) { if (mWidget.topAnchor.target == null || mWidget.topAnchor.absolute != 0) { DrawKnob(handles[5], mWidget.pivot == pivotPoints[5], resizable[5], id); } if (mWidget.bottomAnchor.target == null || mWidget.bottomAnchor.absolute != 0) { DrawKnob(handles[7], mWidget.pivot == pivotPoints[7], resizable[7], id); } } } Handles.EndGUI(); } } break; case EventType.MouseDown: { if (actionUnderMouse != Action.None) { mStartMouse = e.mousePosition; mAllowSelection = true; if (e.button == 1) { if (e.modifiers == 0) { GUIUtility.hotControl = GUIUtility.keyboardControl = id; e.Use(); } } else if (e.button == 0 && actionUnderMouse != Action.None && Raycast(handles, out mStartDrag)) { mWorldPos = t.position; mLocalPos = t.localPosition; mStartRot = t.localRotation.eulerAngles; mStartDir = mStartDrag - t.position; mStartWidth = mWidget.width; mStartHeight = mWidget.height; mStartLeft.x = mWidget.leftAnchor.relative; mStartLeft.y = mWidget.leftAnchor.absolute; mStartRight.x = mWidget.rightAnchor.relative; mStartRight.y = mWidget.rightAnchor.absolute; mStartBottom.x = mWidget.bottomAnchor.relative; mStartBottom.y = mWidget.bottomAnchor.absolute; mStartTop.x = mWidget.topAnchor.relative; mStartTop.y = mWidget.topAnchor.absolute; mDragPivot = pivotUnderMouse; mActionUnderMouse = actionUnderMouse; GUIUtility.hotControl = GUIUtility.keyboardControl = id; e.Use(); } } } break; case EventType.MouseDrag: { // Prevent selection once the drag operation begins bool dragStarted = (e.mousePosition - mStartMouse).magnitude > 3f; if (dragStarted) { mAllowSelection = false; } if (GUIUtility.hotControl == id) { e.Use(); if (mAction != Action.None || mActionUnderMouse != Action.None) { Vector3 pos; if (Raycast(handles, out pos)) { if (mAction == Action.None && mActionUnderMouse != Action.None) { // Wait until the mouse moves by more than a few pixels if (dragStarted) { if (mActionUnderMouse == Action.Move) { NGUISnap.Recalculate(mWidget); } else if (mActionUnderMouse == Action.Rotate) { mStartRot = t.localRotation.eulerAngles; mStartDir = mStartDrag - t.position; } else if (mActionUnderMouse == Action.Scale) { mStartWidth = mWidget.width; mStartHeight = mWidget.height; mDragPivot = pivotUnderMouse; } mAction = actionUnderMouse; } } if (mAction != Action.None) { NGUIEditorTools.RegisterUndo("Change Rect", t); NGUIEditorTools.RegisterUndo("Change Rect", mWidget); // Reset the widget before adjusting anything t.position = mWorldPos; mWidget.width = mStartWidth; mWidget.height = mStartHeight; mWidget.leftAnchor.Set(mStartLeft.x, mStartLeft.y); mWidget.rightAnchor.Set(mStartRight.x, mStartRight.y); mWidget.bottomAnchor.Set(mStartBottom.x, mStartBottom.y); mWidget.topAnchor.Set(mStartTop.x, mStartTop.y); if (mAction == Action.Move) { // Move the widget t.position = mWorldPos + (pos - mStartDrag); Vector3 after = t.localPosition; bool snapped = false; Transform parent = t.parent; if (parent != null) { UIGrid grid = parent.GetComponent <UIGrid>(); if (grid != null && grid.arrangement == UIGrid.Arrangement.CellSnap) { snapped = true; if (grid.cellWidth > 0) { after.x = Mathf.Round(after.x / grid.cellWidth) * grid.cellWidth; } if (grid.cellHeight > 0) { after.y = Mathf.Round(after.y / grid.cellHeight) * grid.cellHeight; } } } if (!snapped) { // Snap the widget after = NGUISnap.Snap(after, mWidget.localCorners, e.modifiers != EventModifiers.Control); } // Calculate the final delta Vector3 localDelta = (after - mLocalPos); // Restore the position t.position = mWorldPos; // Adjust the widget by the delta NGUIMath.MoveRect(mWidget, localDelta.x, localDelta.y); } else if (mAction == Action.Rotate) { Vector3 dir = pos - t.position; float angle = Vector3.Angle(mStartDir, dir); if (angle > 0f) { float dot = Vector3.Dot(Vector3.Cross(mStartDir, dir), t.forward); if (dot < 0f) { angle = -angle; } angle = mStartRot.z + angle; angle = (NGUISnap.allow && e.modifiers != EventModifiers.Control) ? Mathf.Round(angle / 15f) * 15f : Mathf.Round(angle); t.localRotation = Quaternion.Euler(mStartRot.x, mStartRot.y, angle); } } else if (mAction == Action.Scale) { // Move the widget t.position = mWorldPos + (pos - mStartDrag); // Calculate the final delta Vector3 localDelta = (t.localPosition - mLocalPos); // Restore the position t.position = mWorldPos; // Adjust the widget's position and scale based on the delta, restricted by the pivot NGUIMath.ResizeWidget(mWidget, mDragPivot, localDelta.x, localDelta.y, 2, 2); ReEvaluateAnchorType(); } } } } } } break; case EventType.MouseUp: { if (e.button == 2) { break; } if (GUIUtility.hotControl == id) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; if (e.button < 2) { bool handled = false; if (e.button == 1) { // Right-click: Open a context menu listing all widgets underneath NGUIEditorTools.ShowSpriteSelectionMenu(e.mousePosition); handled = true; } else if (mAction == Action.None) { if (mAllowSelection) { // Left-click: Select the topmost widget NGUIEditorTools.SelectWidget(e.mousePosition); handled = true; } } else { // Finished dragging something Vector3 pos = t.localPosition; pos.x = Mathf.Round(pos.x); pos.y = Mathf.Round(pos.y); pos.z = Mathf.Round(pos.z); t.localPosition = pos; handled = true; } if (handled) { e.Use(); } } // Clear the actions mActionUnderMouse = Action.None; mAction = Action.None; } else if (mAllowSelection) { List <UIWidget> widgets = NGUIEditorTools.SceneViewRaycast(e.mousePosition); if (widgets.Count > 0) { Selection.activeGameObject = widgets[0].gameObject; } } mAllowSelection = true; } break; case EventType.KeyDown: { if (e.keyCode == KeyCode.UpArrow) { NGUIEditorTools.RegisterUndo("Nudge Rect", t); NGUIEditorTools.RegisterUndo("Nudge Rect", mWidget); NGUIMath.MoveRect(mWidget, 0f, 1f); e.Use(); } else if (e.keyCode == KeyCode.DownArrow) { NGUIEditorTools.RegisterUndo("Nudge Rect", t); NGUIEditorTools.RegisterUndo("Nudge Rect", mWidget); NGUIMath.MoveRect(mWidget, 0f, -1f); e.Use(); } else if (e.keyCode == KeyCode.LeftArrow) { NGUIEditorTools.RegisterUndo("Nudge Rect", t); NGUIEditorTools.RegisterUndo("Nudge Rect", mWidget); NGUIMath.MoveRect(mWidget, -1f, 0f); e.Use(); } else if (e.keyCode == KeyCode.RightArrow) { NGUIEditorTools.RegisterUndo("Nudge Rect", t); NGUIEditorTools.RegisterUndo("Nudge Rect", mWidget); NGUIMath.MoveRect(mWidget, 1f, 0f); e.Use(); } else if (e.keyCode == KeyCode.Escape) { if (GUIUtility.hotControl == id) { if (mAction != Action.None) { Undo.PerformUndo(); } GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; mActionUnderMouse = Action.None; mAction = Action.None; e.Use(); } else { Selection.activeGameObject = null; } } } break; } }
/// <summary> /// Filled sprite fill function. /// </summary> void FilledFill(List <Vector3> verts, List <Vector2> uvs, List <Color> cols) { if (mFillAmount < 0.001f) { return; } Vector4 v = drawingDimensions; Vector4 u = drawingUVs; Color c = drawingColor; // zhy drawingUVs已经是考虑过flip的 // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical) { if (mFillDirection == FillDirection.Horizontal) { // zhy fill并不是纹理坐标,只是一个差额 float fill = (u.z - u.x) * mFillAmount; if (mInvert) { // zhy 矩形的右边界文职和纹理坐标不动,左边界的重新计算 v.x = v.z - (v.z - v.x) * mFillAmount; u.x = u.z - fill; } else { // zhy 矩形的左边界位置和纹理坐标都不动,右边界的重新计算 v.z = v.x + (v.z - v.x) * mFillAmount; u.z = u.x + fill; } } else if (mFillDirection == FillDirection.Vertical) { float fill = (u.w - u.y) * mFillAmount; if (mInvert) { v.y = v.w - (v.w - v.y) * mFillAmount; u.y = u.w - fill; } else { v.w = v.y + (v.w - v.y) * mFillAmount; u.w = u.y + fill; } } } // zhy 如果只是水平或垂直方向的flip,顶点和纹理坐标都计算完,mTempPos和mTempUVs就是最终值 // 如果是其他方式(辐射)的flip,则mTempPos和mTempUVs只是最原始的矩形四边界位置和纹理坐标,用于接下来的旋转计算 mTempPos[0] = new Vector2(v.x, v.y); mTempPos[1] = new Vector2(v.x, v.w); mTempPos[2] = new Vector2(v.z, v.w); mTempPos[3] = new Vector2(v.z, v.y); mTempUVs[0] = new Vector2(u.x, u.y); mTempUVs[1] = new Vector2(u.x, u.w); mTempUVs[2] = new Vector2(u.z, u.w); mTempUVs[3] = new Vector2(u.z, u.y); if (mFillAmount < 1f) { if (mFillDirection == FillDirection.Radial90) { if (RadialCut(mTempPos, mTempUVs, mFillAmount, mInvert, 0)) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } return; } if (mFillDirection == FillDirection.Radial180) { for (int side = 0; side < 2; ++side) { float fx0, fx1, fy0, fy1; fy0 = 0f; fy1 = 1f; if (side == 0) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } mTempPos[0].x = Mathf.Lerp(v.x, v.z, fx0); mTempPos[1].x = mTempPos[0].x; mTempPos[2].x = Mathf.Lerp(v.x, v.z, fx1); mTempPos[3].x = mTempPos[2].x; mTempPos[0].y = Mathf.Lerp(v.y, v.w, fy0); mTempPos[1].y = Mathf.Lerp(v.y, v.w, fy1); mTempPos[2].y = mTempPos[1].y; mTempPos[3].y = mTempPos[0].y; mTempUVs[0].x = Mathf.Lerp(u.x, u.z, fx0); mTempUVs[1].x = mTempUVs[0].x; mTempUVs[2].x = Mathf.Lerp(u.x, u.z, fx1); mTempUVs[3].x = mTempUVs[2].x; mTempUVs[0].y = Mathf.Lerp(u.y, u.w, fy0); mTempUVs[1].y = Mathf.Lerp(u.y, u.w, fy1); mTempUVs[2].y = mTempUVs[1].y; mTempUVs[3].y = mTempUVs[0].y; float val = !mInvert ? fillAmount * 2f - side : mFillAmount * 2f - (1 - side); string log = string.Format("side = {0}, val = {1}", side.ToString(), val.ToString()); Debug.LogError(log); if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(val), !mInvert, NGUIMath.RepeatIndex(side + 3, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } } return; } if (mFillDirection == FillDirection.Radial360) { for (int corner = 0; corner < 4; ++corner) { float fx0, fx1, fy0, fy1; if (corner < 2) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } if (corner == 0 || corner == 3) { fy0 = 0f; fy1 = 0.5f; } else { fy0 = 0.5f; fy1 = 1f; } mTempPos[0].x = Mathf.Lerp(v.x, v.z, fx0); mTempPos[1].x = mTempPos[0].x; mTempPos[2].x = Mathf.Lerp(v.x, v.z, fx1); mTempPos[3].x = mTempPos[2].x; mTempPos[0].y = Mathf.Lerp(v.y, v.w, fy0); mTempPos[1].y = Mathf.Lerp(v.y, v.w, fy1); mTempPos[2].y = mTempPos[1].y; mTempPos[3].y = mTempPos[0].y; mTempUVs[0].x = Mathf.Lerp(u.x, u.z, fx0); mTempUVs[1].x = mTempUVs[0].x; mTempUVs[2].x = Mathf.Lerp(u.x, u.z, fx1); mTempUVs[3].x = mTempUVs[2].x; mTempUVs[0].y = Mathf.Lerp(u.y, u.w, fy0); mTempUVs[1].y = Mathf.Lerp(u.y, u.w, fy1); mTempUVs[2].y = mTempUVs[1].y; mTempUVs[3].y = mTempUVs[0].y; float val = mInvert ? mFillAmount * 4f - NGUIMath.RepeatIndex(corner + 2, 4) : mFillAmount * 4f - (3 - NGUIMath.RepeatIndex(corner + 2, 4)); if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(val), mInvert, NGUIMath.RepeatIndex(corner + 2, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } } return; } } // zhy 水平或垂直方向的flip才会走到这里 // Fill the buffer with the quad for the sprite for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } }
/// <summary> /// Adjust the specified quad, making it be radially filled instead. /// </summary> static void RadialCut(Vector2[] xy, float cos, float sin, bool invert, int corner) { int i0 = corner; int i1 = NGUIMath.RepeatIndex(corner + 1, 4); int i2 = NGUIMath.RepeatIndex(corner + 2, 4); int i3 = NGUIMath.RepeatIndex(corner + 3, 4); // zhy 顶点顺序 // 1---2 // | | // 0---3 // zhy 判断corner是否是奇数,负数也成立 if ((corner & 1) == 1) { if (sin > cos) { cos /= sin; sin = 1f; if (invert) { xy[i1].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); xy[i2].x = xy[i1].x; } } else if (cos > sin) { sin /= cos; cos = 1f; if (!invert) { xy[i2].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); xy[i3].y = xy[i2].y; } } else { cos = 1f; sin = 1f; } if (!invert) { xy[i3].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); } else { xy[i1].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); } } else { if (cos > sin) { sin /= cos; cos = 1f; Debug.LogError("sin = " + sin.ToString()); if (!invert) { // zhy 当角度小于45°时,1和2顶点重合,四边形退化成一个三角形(2,3,0)和一条线段(0,1,2) xy[i1].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); xy[i2].y = xy[i1].y; } } else if (sin > cos) { cos /= sin; sin = 1f; Debug.LogError("cos = " + cos.ToString()); if (invert) { xy[i2].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); xy[i3].x = xy[i2].x; } } else { Debug.LogError("cos is equal sin"); cos = 1f; sin = 1f; } if (invert) { // zhy 45°时,3点重合到2点 xy[i3].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); } else { // zhy 45°时,1点重合到2点 xy[i1].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); } } }
/// <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(); // 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; 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 fontHeight = activeFontSize; float dynScale = activeFontScale; float labelHeight = fontHeight * dynScale; float x = 0f, y = -padding.y; int labelFontSize = (bitmapFont != null) ? bitmapFont.defaultSize : fontSize; 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.name = i.ToString(); lbl.pivot = UIWidget.Pivot.TopLeft; lbl.bitmapFont = bitmapFont; lbl.trueTypeFont = trueTypeFont; lbl.fontSize = labelFontSize; lbl.fontStyle = fontStyle; lbl.text = isLocalized ? Localization.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, 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 / 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]; NGUITools.AddWidgetCollider(lbl.gameObject); BoxCollider bc = lbl.GetComponent <BoxCollider>(); if (bc != null) { bcCenter.z = bc.center.z; bc.center = bcCenter; bc.size = bcSize; } #if !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2 else { BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>(); #if UNITY_5_0 || UNITY_5_2 || UNITY_5_3 || UNITY_5_5 || UNITY_5_6_OR_NEWER b2d.offset = bcCenter; #else b2d.center = bcCenter; #endif b2d.size = bcSize; } #endif } 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); } }
public void SetColor(uint color) { mLabel.color = NGUIMath.HexToColor(color); }
// Token: 0x0600058A RID: 1418 RVA: 0x00033444 File Offset: 0x00031644 protected override void OnAnchor() { Transform cachedTransform = base.cachedTransform; Transform parent = cachedTransform.parent; Vector3 localPosition = cachedTransform.localPosition; Vector2 pivotOffset = this.pivotOffset; float num; float num2; float num3; float num4; if (this.leftAnchor.target == this.bottomAnchor.target && this.leftAnchor.target == this.rightAnchor.target && this.leftAnchor.target == this.topAnchor.target) { Vector3[] sides = this.leftAnchor.GetSides(parent); if (sides != null) { num = NGUIMath.Lerp(sides[0].x, sides[2].x, this.leftAnchor.relative) + (float)this.leftAnchor.absolute; num2 = NGUIMath.Lerp(sides[0].x, sides[2].x, this.rightAnchor.relative) + (float)this.rightAnchor.absolute; num3 = NGUIMath.Lerp(sides[3].y, sides[1].y, this.bottomAnchor.relative) + (float)this.bottomAnchor.absolute; num4 = NGUIMath.Lerp(sides[3].y, sides[1].y, this.topAnchor.relative) + (float)this.topAnchor.absolute; this.mIsInFront = true; } else { Vector3 localPos = base.GetLocalPos(this.leftAnchor, parent); num = localPos.x + (float)this.leftAnchor.absolute; num3 = localPos.y + (float)this.bottomAnchor.absolute; num2 = localPos.x + (float)this.rightAnchor.absolute; num4 = localPos.y + (float)this.topAnchor.absolute; this.mIsInFront = (!this.hideIfOffScreen || localPos.z >= 0f); } } else { this.mIsInFront = true; if (this.leftAnchor.target) { Vector3[] sides2 = this.leftAnchor.GetSides(parent); if (sides2 != null) { num = NGUIMath.Lerp(sides2[0].x, sides2[2].x, this.leftAnchor.relative) + (float)this.leftAnchor.absolute; } else { num = base.GetLocalPos(this.leftAnchor, parent).x + (float)this.leftAnchor.absolute; } } else { num = localPosition.x - pivotOffset.x * (float)this.mWidth; } if (this.rightAnchor.target) { Vector3[] sides3 = this.rightAnchor.GetSides(parent); if (sides3 != null) { num2 = NGUIMath.Lerp(sides3[0].x, sides3[2].x, this.rightAnchor.relative) + (float)this.rightAnchor.absolute; } else { num2 = base.GetLocalPos(this.rightAnchor, parent).x + (float)this.rightAnchor.absolute; } } else { num2 = localPosition.x - pivotOffset.x * (float)this.mWidth + (float)this.mWidth; } if (this.bottomAnchor.target) { Vector3[] sides4 = this.bottomAnchor.GetSides(parent); if (sides4 != null) { num3 = NGUIMath.Lerp(sides4[3].y, sides4[1].y, this.bottomAnchor.relative) + (float)this.bottomAnchor.absolute; } else { num3 = base.GetLocalPos(this.bottomAnchor, parent).y + (float)this.bottomAnchor.absolute; } } else { num3 = localPosition.y - pivotOffset.y * (float)this.mHeight; } if (this.topAnchor.target) { Vector3[] sides5 = this.topAnchor.GetSides(parent); if (sides5 != null) { num4 = NGUIMath.Lerp(sides5[3].y, sides5[1].y, this.topAnchor.relative) + (float)this.topAnchor.absolute; } else { num4 = base.GetLocalPos(this.topAnchor, parent).y + (float)this.topAnchor.absolute; } } else { num4 = localPosition.y - pivotOffset.y * (float)this.mHeight + (float)this.mHeight; } } Vector3 vector = new Vector3(Mathf.Lerp(num, num2, pivotOffset.x), Mathf.Lerp(num3, num4, pivotOffset.y), localPosition.z); vector.x = Mathf.Round(vector.x); vector.y = Mathf.Round(vector.y); int num5 = Mathf.FloorToInt(num2 - num + 0.5f); int num6 = Mathf.FloorToInt(num4 - num3 + 0.5f); if (this.keepAspectRatio != UIWidget.AspectRatioSource.Free && this.aspectRatio != 0f) { if (this.keepAspectRatio == UIWidget.AspectRatioSource.BasedOnHeight) { num5 = Mathf.RoundToInt((float)num6 * this.aspectRatio); } else { num6 = Mathf.RoundToInt((float)num5 / this.aspectRatio); } } if (num5 < this.minWidth) { num5 = this.minWidth; } if (num6 < this.minHeight) { num6 = this.minHeight; } if (Vector3.SqrMagnitude(localPosition - vector) > 0.001f) { base.cachedTransform.localPosition = vector; if (this.mIsInFront) { this.mChanged = true; } } if (this.mWidth != num5 || this.mHeight != num6) { this.mWidth = num5; this.mHeight = num6; if (this.mIsInFront) { this.mChanged = true; } if (this.autoResizeBoxCollider) { this.ResizeCollider(); } } }
override public void OnInspectorGUI() { mFont = target as UIFont; #pragma warning disable 0618 EditorGUIUtility.LookLikeControls(80f); #pragma warning restore 0618 NGUIEditorTools.DrawSeparator(); if (mFont.replacement != null) { mType = FontType.Reference; mReplacement = mFont.replacement as UIFont; } FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType); if (mType != after) { if (after == FontType.Normal) { OnSelectFont(null); } else { mType = FontType.Reference; } } if (mType == FontType.Reference) { ComponentSelector.Draw <UIFont>(mFont.replacement as UIFont, OnSelectFont); NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can have one font simply point to\n" + "another one. This is useful if you want to be\n" + "able to quickly replace the contents of one\n" + "font with another one, for example for\n" + "swapping an SD font with an HD one, or\n" + "replacing an English font with a Chinese\n" + "one. All the labels referencing this font\n" + "will update their references to the new one."); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mFont); } return; } NGUIEditorTools.DrawSeparator(); ComponentSelector.Draw <UIAtlas>(mFont.atlas as UIAtlas, OnSelectAtlas); if (mFont.atlas != null) { if (mFont.bmFont.LegacyCheck()) { Debug.Log(mFont.name + " uses a legacy font data structure. Upgrading, please save."); EditorUtility.SetDirty(mFont); } if (mFont.bmFont.isValid) { string spriteName = UISlicedSpriteInspector.SpriteField(mFont.atlas as UIAtlas, mFont.spriteName); if (mFont.spriteName != spriteName) { NGUIEditorTools.RegisterUndo("Font Sprite", mFont); mFont.spriteName = spriteName; } } } else { // No atlas specified -- set the material and texture rectangle directly Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } } bool resetWidthHeight = false; if (mFont.atlas != null || mFont.material != null) { TextAsset data = EditorGUILayout.ObjectField("Import Font", null, typeof(TextAsset), false) as TextAsset; if (data != null) { NGUIEditorTools.RegisterUndo("Import Font Data", mFont); BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes); mFont.MarkAsDirty(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } } if (mFont.bmFont.isValid) { Color green = new Color(0.4f, 1f, 0f, 1f); Texture2D tex = mFont.texture; if (tex != null) { if (mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Automatically set the width and height of the rectangle to be the original font texture's dimensions if (resetWidthHeight) { pixels.width = mFont.texWidth; pixels.height = mFont.texHeight; } // Font sprite rectangle GUI.backgroundColor = green; pixels = EditorGUILayout.RectField("Pixel Rect", pixels); GUI.backgroundColor = Color.white; // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { GUILayout.Label("Correction", GUILayout.Width(75f)); Rect corrected = NGUIMath.MakePixelPerfect(pixels); if (corrected == pixels) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { pixels = corrected; GUI.changed = true; } } GUILayout.EndHorizontal(); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont); mFont.uvRect = uvRect; } } // Font spacing GUILayout.BeginHorizontal(); { #pragma warning disable 0618 EditorGUIUtility.LookLikeControls(0f); #pragma warning restore 0618 GUILayout.Label("Spacing", GUILayout.Width(60f)); GUILayout.Label("X", GUILayout.Width(12f)); int x = EditorGUILayout.IntField(mFont.horizontalSpacing); GUILayout.Label("Y", GUILayout.Width(12f)); int y = EditorGUILayout.IntField(mFont.verticalSpacing); #pragma warning disable 0618 EditorGUIUtility.LookLikeControls(80f); #pragma warning restore 0618 if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y) { NGUIEditorTools.RegisterUndo("Font Spacing", mFont); mFont.horizontalSpacing = x; mFont.verticalSpacing = y; } } GUILayout.EndHorizontal(); EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Show", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); if (mUseShader != EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f))) { mUseShader = !mUseShader; if (mUseShader && mView == View.Font) { // TODO: Remove this when Unity fixes the bug with DrawPreviewTexture not being affected by BeginGroup Debug.LogWarning("There is a bug in Unity that prevents the texture from getting clipped properly.\n" + "Until it's fixed by Unity, your texture may spill onto the rest of the Unity's GUI while using this mode."); } } } GUILayout.EndHorizontal(); if (mView != View.Nothing) { // Draw the atlas EditorGUILayout.Separator(); Material m = mUseShader ? mFont.material : null; Rect rect = (mView == View.Atlas) ? NGUIEditorTools.DrawAtlas(tex, m) : NGUIEditorTools.DrawSprite(tex, mFont.uvRect, m); NGUIEditorTools.DrawOutline(rect, mFont.uvRect, green); rect = GUILayoutUtility.GetRect(Screen.width, 18f); EditorGUI.DropShadowLabel(rect, "Font Size: " + mFont.size); } } } }
public override void OnFill(NGUI.Meshing.MeshBuffer m) { Texture mainTexture = base.material.mainTexture; if (mainTexture != null) { Vertex vertex; Vertex vertex2; Vertex vertex3; Vertex vertex4; Rect mInner = base.mInner; if (base.atlas.coordinates == UIAtlas.Coordinates.TexCoords) { mInner = NGUIMath.ConvertToPixels(mInner, mainTexture.width, mainTexture.height, true); } Vector2 localScale = base.cachedTransform.localScale; float pixelSize = base.atlas.pixelSize; float num2 = Mathf.Abs((float)(mInner.width / localScale.x)) * pixelSize; float num3 = Mathf.Abs((float)(mInner.height / localScale.y)) * pixelSize; if ((num2 < 0.01f) || (num3 < 0.01f)) { Debug.LogWarning("The tiled sprite (" + NGUITools.GetHierarchy(base.gameObject) + ") is too small.\nConsider using a bigger one."); num2 = 0.01f; num3 = 0.01f; } Vector2 vector2 = new Vector2(mInner.xMin / ((float)mainTexture.width), mInner.yMin / ((float)mainTexture.height)); Vector2 vector3 = new Vector2(mInner.xMax / ((float)mainTexture.width), mInner.yMax / ((float)mainTexture.height)); Vector2 vector4 = vector3; float num4 = 0f; Color color = base.color; vertex.r = vertex2.r = vertex3.r = vertex4.r = color.r; vertex.g = vertex2.g = vertex3.g = vertex4.g = color.g; vertex.b = vertex2.b = vertex3.b = vertex4.b = color.b; vertex.a = vertex2.a = vertex3.a = vertex4.a = color.a; vertex.z = vertex2.z = vertex3.z = vertex4.z = 0f; while (num4 < 1f) { float num5 = 0f; vector4.x = vector3.x; float num6 = num4 + num3; if (num6 > 1f) { vector4.y = vector2.y + (((vector3.y - vector2.y) * (1f - num4)) / (num6 - num4)); num6 = 1f; } while (num5 < 1f) { float num7 = num5 + num2; if (num7 > 1f) { vector4.x = vector2.x + (((vector3.x - vector2.x) * (1f - num5)) / (num7 - num5)); num7 = 1f; } vertex.x = num7; vertex.y = -num4; vertex2.x = num7; vertex2.y = -num6; vertex3.x = num5; vertex3.y = -num6; vertex4.x = num5; vertex4.y = -num4; vertex.u = vector4.x; vertex.v = 1f - vector2.y; vertex2.u = vector4.x; vertex2.v = 1f - vector4.y; vertex3.u = vector2.x; vertex3.v = 1f - vector4.y; vertex4.u = vector2.x; vertex4.v = 1f - vector2.y; m.Quad(vertex, vertex2, vertex3, vertex4); num5 += num2; } num4 += num3; } } }
public override void OnInspectorGUI() { mFont = target as UIFont; NGUIEditorTools.SetLabelWidth(80f); GUILayout.Space(6f); if (mFont.replacement != null) { mType = FontType.Reference; mReplacement = mFont.replacement; } else if (mFont.dynamicFont != null) { mType = FontType.Dynamic; } GUILayout.BeginHorizontal(); FontType fontType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (mType != fontType) { if (fontType == FontType.Normal) { OnSelectFont(null); } else { mType = fontType; } if (mType != FontType.Dynamic && mFont.dynamicFont != null) { mFont.dynamicFont = null; } } if (mType == FontType.Reference) { ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one font simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "font with another one, for example for " + "swapping an SD font with an HD one, or " + "replacing an English font with a Chinese " + "one. All the labels referencing this font " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mFont); } return; } else if (mType == FontType.Dynamic) { #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font; if (fnt != mFont.dynamicFont) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFont = fnt; } Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } GUILayout.BeginHorizontal(); int size = EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f)); FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (size != mFont.defaultSize) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.defaultSize = size; } if (style != mFont.dynamicFontStyle) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFontStyle = style; } #endif } else { NGUIEditorTools.DrawSeparator(); ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas, true); if (mFont.atlas != null) { if (mFont.bmFont.isValid) { NGUIEditorTools.DrawAdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false); } EditorGUILayout.Space(); } else { // No atlas specified -- set the material and texture rectangle directly Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } } // For updating the font's data when importing from an external source, such as the texture packer bool resetWidthHeight = false; if (mFont.atlas != null || mFont.material != null) { TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset; if (data != null) { NGUIEditorTools.RegisterUndo("Import Font Data", mFont); BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes); mFont.MarkAsDirty(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } } if (mFont.bmFont.isValid) { Color green = new Color(0.4f, 1f, 0f, 1f); Texture2D tex = mFont.texture; if (tex != null) { if (mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Automatically set the width and height of the rectangle to be the original font texture's dimensions if (resetWidthHeight) { pixels.width = mFont.texWidth; pixels.height = mFont.texHeight; } // Font sprite rectangle GUI.backgroundColor = green; pixels = EditorGUILayout.RectField("Pixel Rect", pixels); GUI.backgroundColor = Color.white; // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { Rect corrected = NGUIMath.MakePixelPerfect(pixels); if (corrected == pixels) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { pixels = corrected; GUI.changed = true; } } GUILayout.EndHorizontal(); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont); mFont.uvRect = uvRect; } //NGUIEditorTools.DrawSeparator(); EditorGUILayout.Space(); } } } } // The font must be valid at this point for the rest of the options to show up if (mFont.isDynamic || mFont.bmFont.isValid) { // Font spacing GUILayout.BeginHorizontal(); { NGUIEditorTools.SetLabelWidth(0f); GUILayout.Label("Spacing", GUILayout.Width(60f)); GUILayout.Label("X", GUILayout.Width(12f)); int x = EditorGUILayout.IntField(mFont.horizontalSpacing); GUILayout.Label("Y", GUILayout.Width(12f)); int y = EditorGUILayout.IntField(mFont.verticalSpacing); GUILayout.Space(18f); NGUIEditorTools.SetLabelWidth(80f); if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y) { NGUIEditorTools.RegisterUndo("Font Spacing", mFont); mFont.horizontalSpacing = x; mFont.verticalSpacing = y; } } GUILayout.EndHorizontal(); if (mFont.atlas == null) { mView = View.Font; mUseShader = false; float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f)); if (pixelSize != mFont.pixelSize) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.pixelSize = pixelSize; } } EditorGUILayout.Space(); } // Preview option if (!mFont.isDynamic && mFont.atlas != null) { GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Preview", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)); } GUILayout.EndHorizontal(); } // Dynamic fonts don't support emoticons if (!mFont.isDynamic && mFont.bmFont.isValid) { if (mFont.atlas != null) { if (NGUIEditorTools.DrawHeader("Symbols and Emoticons")) { NGUIEditorTools.BeginContents(); List <BMSymbol> symbols = mFont.symbols; for (int i = 0; i < symbols.Count;) { BMSymbol sym = symbols[i]; GUILayout.BeginHorizontal(); GUILayout.Label(sym.sequence, GUILayout.Width(40f)); if (NGUIEditorTools.DrawSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite)) { mSelectedSymbol = sym; } if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (mFont.atlas != null) { NGUISettings.selectedSprite = sym.spriteName; NGUIEditorTools.Select(mFont.atlas.gameObject); } } GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove symbol", mFont); mSymbolSequence = sym.sequence; mSymbolSprite = sym.spriteName; symbols.Remove(sym); mFont.MarkAsDirty(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); ++i; } if (symbols.Count > 0) { GUILayout.Space(6f); } GUILayout.BeginHorizontal(); mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f)); NGUIEditorTools.DrawSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite); bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add symbol", mFont); mFont.AddSymbol(mSymbolSequence, mSymbolSprite); mFont.MarkAsDirty(); mSymbolSequence = ""; mSymbolSprite = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (symbols.Count == 0) { EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } NGUIEditorTools.EndContents(); } } } }
/// <summary> /// Adjust the specified quad, making it be radially filled instead. /// </summary> static void RadialCut(Vector2[] xy, float cos, float sin, bool invert, int corner) { int i0 = corner; int i1 = NGUIMath.RepeatIndex(corner + 1, 4); int i2 = NGUIMath.RepeatIndex(corner + 2, 4); int i3 = NGUIMath.RepeatIndex(corner + 3, 4); if ((corner & 1) == 1) { if (sin > cos) { cos /= sin; sin = 1f; if (invert) { xy[i1].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); xy[i2].x = xy[i1].x; } } else if (cos > sin) { sin /= cos; cos = 1f; if (!invert) { xy[i2].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); xy[i3].y = xy[i2].y; } } else { cos = 1f; sin = 1f; } if (!invert) { xy[i3].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); } else { xy[i1].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); } } else { if (cos > sin) { sin /= cos; cos = 1f; if (!invert) { xy[i1].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); xy[i2].y = xy[i1].y; } } else if (sin > cos) { cos /= sin; sin = 1f; if (invert) { xy[i2].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); xy[i3].x = xy[i2].x; } } else { cos = 1f; sin = 1f; } if (invert) { xy[i3].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); } else { xy[i1].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); } } }
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; } } }
/// <summary> /// Update the anchored edges and ensure the widget is registered with a panel. /// </summary> protected override void OnAnchor() { float lt, bt, rt, tt; Transform trans = cachedTransform; Transform parent = trans.parent; Vector3 pos = trans.localPosition; Vector2 pvt = pivotOffset; // Attempt to fast-path if all anchors match if (leftAnchor.target == bottomAnchor.target && leftAnchor.target == rightAnchor.target && leftAnchor.target == topAnchor.target) { Vector3[] sides = leftAnchor.GetSides(parent); if (sides != null) { lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute; rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute; bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute; tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute; mIsInFront = true; } else { // Anchored to a single transform Vector3 lp = GetLocalPos(leftAnchor, parent); lt = lp.x + leftAnchor.absolute; bt = lp.y + bottomAnchor.absolute; rt = lp.x + rightAnchor.absolute; tt = lp.y + topAnchor.absolute; mIsInFront = (!hideIfOffScreen || lp.z >= 0f); } } else { mIsInFront = true; // Left anchor point if (leftAnchor.target) { Vector3[] sides = leftAnchor.GetSides(parent); if (sides != null) { lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute; } else { lt = GetLocalPos(leftAnchor, parent).x + leftAnchor.absolute; } } else { lt = pos.x - pvt.x * mWidth; } // Right anchor point if (rightAnchor.target) { Vector3[] sides = rightAnchor.GetSides(parent); if (sides != null) { rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute; } else { rt = GetLocalPos(rightAnchor, parent).x + rightAnchor.absolute; } } else { rt = pos.x - pvt.x * mWidth + mWidth; } // Bottom anchor point if (bottomAnchor.target) { Vector3[] sides = bottomAnchor.GetSides(parent); if (sides != null) { bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute; } else { bt = GetLocalPos(bottomAnchor, parent).y + bottomAnchor.absolute; } } else { bt = pos.y - pvt.y * mHeight; } // Top anchor point if (topAnchor.target) { Vector3[] sides = topAnchor.GetSides(parent); if (sides != null) { tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute; } else { tt = GetLocalPos(topAnchor, parent).y + topAnchor.absolute; } } else { tt = pos.y - pvt.y * mHeight + mHeight; } } // Calculate the new position, width and height Vector3 newPos = new Vector3(Mathf.Lerp(lt, rt, pvt.x), Mathf.Lerp(bt, tt, pvt.y), pos.z); newPos.x = Mathf.Round(newPos.x); newPos.y = Mathf.Round(newPos.y); int w = Mathf.FloorToInt(rt - lt + 0.5f); int h = Mathf.FloorToInt(tt - bt + 0.5f); // Maintain the aspect ratio if requested and possible if (keepAspectRatio != AspectRatioSource.Free && aspectRatio != 0f) { if (keepAspectRatio == AspectRatioSource.BasedOnHeight) { w = Mathf.RoundToInt(h * aspectRatio); } else { h = Mathf.RoundToInt(w / aspectRatio); } } // Don't let the width and height get too small if (w < minWidth) { w = minWidth; } if (h < minHeight) { h = minHeight; } // Update the position if it has changed if (Vector3.SqrMagnitude(pos - newPos) > 0.001f) { cachedTransform.localPosition = newPos; if (mIsInFront) { mChanged = true; } } // Update the width and height if it has changed if (mWidth != w || mHeight != h) { mWidth = w; mHeight = h; if (mIsInFront) { mChanged = true; } if (autoResizeBoxCollider) { ResizeCollider(); } } }
protected override void OnAnchor() { if (mClipping != 0) { Transform cachedTransform = base.cachedTransform; Transform parent = cachedTransform.parent; Vector2 viewSize = GetViewSize(); Vector2 vector = cachedTransform.localPosition; float num; float num2; float num3; float num4; if (leftAnchor.target == bottomAnchor.target && leftAnchor.target == rightAnchor.target && leftAnchor.target == topAnchor.target) { Vector3[] sides = leftAnchor.GetSides(parent); if (sides != null) { num = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + (float)leftAnchor.absolute; num2 = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + (float)rightAnchor.absolute; num3 = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + (float)bottomAnchor.absolute; num4 = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + (float)topAnchor.absolute; } else { Vector2 vector2 = GetLocalPos(leftAnchor, parent); num = vector2.x + (float)leftAnchor.absolute; num3 = vector2.y + (float)bottomAnchor.absolute; num2 = vector2.x + (float)rightAnchor.absolute; num4 = vector2.y + (float)topAnchor.absolute; } } else { if ((bool)leftAnchor.target) { Vector3[] sides2 = leftAnchor.GetSides(parent); if (sides2 != null) { num = NGUIMath.Lerp(sides2[0].x, sides2[2].x, leftAnchor.relative) + (float)leftAnchor.absolute; } else { Vector3 localPos = GetLocalPos(leftAnchor, parent); num = localPos.x + (float)leftAnchor.absolute; } } else { num = mClipRange.x - 0.5f * viewSize.x; } if ((bool)rightAnchor.target) { Vector3[] sides3 = rightAnchor.GetSides(parent); if (sides3 != null) { num2 = NGUIMath.Lerp(sides3[0].x, sides3[2].x, rightAnchor.relative) + (float)rightAnchor.absolute; } else { Vector3 localPos2 = GetLocalPos(rightAnchor, parent); num2 = localPos2.x + (float)rightAnchor.absolute; } } else { num2 = mClipRange.x + 0.5f * viewSize.x; } if ((bool)bottomAnchor.target) { Vector3[] sides4 = bottomAnchor.GetSides(parent); if (sides4 != null) { num3 = NGUIMath.Lerp(sides4[3].y, sides4[1].y, bottomAnchor.relative) + (float)bottomAnchor.absolute; } else { Vector3 localPos3 = GetLocalPos(bottomAnchor, parent); num3 = localPos3.y + (float)bottomAnchor.absolute; } } else { num3 = mClipRange.y - 0.5f * viewSize.y; } if ((bool)topAnchor.target) { Vector3[] sides5 = topAnchor.GetSides(parent); if (sides5 != null) { num4 = NGUIMath.Lerp(sides5[3].y, sides5[1].y, topAnchor.relative) + (float)topAnchor.absolute; } else { Vector3 localPos4 = GetLocalPos(topAnchor, parent); num4 = localPos4.y + (float)topAnchor.absolute; } } else { num4 = mClipRange.y + 0.5f * viewSize.y; } } num -= vector.x + mClipOffset.x; num2 -= vector.x + mClipOffset.x; num3 -= vector.y + mClipOffset.y; num4 -= vector.y + mClipOffset.y; float x = Mathf.Lerp(num, num2, 0.5f); float y = Mathf.Lerp(num3, num4, 0.5f); float num5 = num2 - num; float num6 = num4 - num3; float num7 = Mathf.Max(2f, mClipSoftness.x); float num8 = Mathf.Max(2f, mClipSoftness.y); if (num5 < num7) { num5 = num7; } if (num6 < num8) { num6 = num8; } baseClipRegion = new Vector4(x, y, num5, num6); } }
public static GameObject Str2Obj(GameObject parent, string in_str, UIFont mFont, float width, string[] parms = null, int chatID = 0) { in_str = Str2Str(in_str, parms); GameObject content = new GameObject("content"); content.transform.parent = parent.transform; content.transform.localPosition = new Vector3(0, 0, 0); content.transform.localScale = new Vector3(1, 1, 1); content.layer = LayerMask.NameToLayer("NGUI"); string color = null; string has = in_str; float DrawWidth = 0; float now_y = 0; List <GameObject> thisLine = new List <GameObject>(); while (true) { if (has == null) { break; } if (has.Length == 0) { break; } int index_bef = has.IndexOf("["); int index_aft = has.IndexOf("]"); if (index_bef == -1) { string strs = string.Empty; NGUIText.WrapText(has, out strs); if (strs.Length <= 0) { if (DrawWidth == 0) { Debug.Log("can not set string"); return(null); } now_y = FormatLine(thisLine, now_y); DrawWidth = 0; thisLine = new List <GameObject>(); continue; } UILabel lb = CreateLabel(content, strs, mFont, color); lb.transform.localPosition = new Vector3(DrawWidth, 0, 0); thisLine.Add(lb.gameObject); now_y = FormatLine(thisLine, now_y); DrawWidth = 0; thisLine = new List <GameObject>(); if (has.Length > strs.Length) { has = has.Substring(strs.Length, has.Length - strs.Length); if (has[0] == '\n') { if (has.Length > 2) { has = has.Substring(1, has.Length - 1); } else { has = null; } } } else { has = null; } } else { if (index_aft < index_bef) { Debug.Log("error str = " + in_str); return(null); } if (index_aft == -1) { Debug.Log("error str = " + in_str); return(null); } else { string befor_has = has.Substring(0, index_bef); while (true) { if (befor_has == null) { break; } if (befor_has.Length == 0) { break; } string befor_strs = string.Empty; NGUIText.WrapText(befor_has, out befor_strs); if (befor_strs.Length <= 0) { if (DrawWidth == 0) { Debug.Log("can not set string"); return(null); } now_y = FormatLine(thisLine, now_y); DrawWidth = 0; thisLine = new List <GameObject>(); continue; } UILabel befor_lb = CreateLabel(content, befor_strs, mFont, color); befor_lb.transform.localPosition = new Vector3(DrawWidth, 0, 0); thisLine.Add(befor_lb.gameObject); Bounds b = NGUIMath.CalculateRelativeWidgetBounds(befor_lb.gameObject.transform); DrawWidth += b.size.x * mFont.defaultSize; if (befor_has.Length > befor_strs.Length) { now_y = FormatLine(thisLine, now_y); DrawWidth = 0; thisLine = new List <GameObject>(); befor_has = befor_has.Substring(befor_strs.Length, befor_has.Length - befor_strs.Length); if (befor_has[0] == '\n') { if (befor_has.Length > 2) { befor_has = befor_has.Substring(1, befor_has.Length - 1); } else { befor_has = null; } } } else { befor_has = null; } } if (index_aft - index_bef > 1) { string trun_str = has.Substring(index_bef + 1, index_aft - index_bef - 1); string[] trun_parms = trun_str.Split(','); switch (trun_parms[0]) { case "color": color = trun_parms[1]; break; case "-": color = null; break; default: //GameObject other = CreateOther(content, trun_parms, mFont,chatID); //if (other != null) //{ // Bounds b = NGUIMath.CalculateRelativeWidgetBounds(other.transform); // if ((DrawWidth + b.size.x * other.transform.localScale.x) > width) // { // now_y = FormatLine(thisLine, now_y); // thisLine = new List<GameObject>(); // other.transform.localPosition = new Vector3(0, 0, 0); // DrawWidth = b.size.x * other.transform.localScale.x; // thisLine.Add(other); // } // else // { // other.transform.localPosition = new Vector3(DrawWidth, 0, 0); // DrawWidth += b.size.x * other.transform.localScale.x; // thisLine.Add(other); // } //} break; } } if (has.Length > index_aft + 1) { has = has.Substring(index_aft + 1, has.Length - (index_aft + 1)); } else { has = null; } } } } if (thisLine.Count > 0) { FormatLine(thisLine, now_y); } return(content); }
public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) #endif { Texture tex = material.mainTexture; if (tex == null) { return; } Rect rect = mInner; if (atlas.coordinates == UIAtlas.Coordinates.TexCoords) { rect = NGUIMath.ConvertToPixels(rect, tex.width, tex.height, true); } Vector2 scale = cachedTransform.localScale; float pixelSize = atlas.pixelSize; float width = Mathf.Abs(rect.width / scale.x) * pixelSize; float height = Mathf.Abs(rect.height / scale.y) * pixelSize; // Safety check. Useful so Unity doesn't run out of memory if the sprites are too small. if (width < 0.01f || height < 0.01f) { Debug.LogWarning("The tiled sprite (" + NGUITools.GetHierarchy(gameObject) + ") is too small.\nConsider using a bigger one."); width = 0.01f; height = 0.01f; } Vector2 min = new Vector2(rect.xMin / tex.width, rect.yMin / tex.height); Vector2 max = new Vector2(rect.xMax / tex.width, rect.yMax / tex.height); Vector2 clipped = max; Color colF = color; colF.a *= mPanel.alpha; #if UNITY_3_5_4 Color col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; #else Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; #endif float y = 0f; while (y < 1f) { float x = 0f; clipped.x = max.x; float y2 = y + height; if (y2 > 1f) { clipped.y = min.y + (max.y - min.y) * (1f - y) / (y2 - y); y2 = 1f; } while (x < 1f) { float x2 = x + width; if (x2 > 1f) { clipped.x = min.x + (max.x - min.x) * (1f - x) / (x2 - x); x2 = 1f; } verts.Add(new Vector3(x2, -y, 0f)); verts.Add(new Vector3(x2, -y2, 0f)); verts.Add(new Vector3(x, -y2, 0f)); verts.Add(new Vector3(x, -y, 0f)); uvs.Add(new Vector2(clipped.x, 1f - min.y)); uvs.Add(new Vector2(clipped.x, 1f - clipped.y)); uvs.Add(new Vector2(min.x, 1f - clipped.y)); uvs.Add(new Vector2(min.x, 1f - min.y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); x += width; } y += height; } }
/// <summary> /// Apply the dragging momentum. /// </summary> void LateUpdate() { if (!Application.isPlaying) { return; } float delta = RealTime.deltaTime; // Fade the scroll bars if needed if (showScrollBars != ShowCondition.Always && (verticalScrollBar || horizontalScrollBar)) { bool vertical = false; bool horizontal = false; if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f) { vertical = shouldMoveVertically; horizontal = shouldMoveHorizontally; } if (verticalScrollBar) { float alpha = verticalScrollBar.alpha; alpha += vertical ? delta * 6f : -delta * 3f; alpha = Mathf.Clamp01(alpha); if (verticalScrollBar.alpha != alpha) { verticalScrollBar.alpha = alpha; } } if (horizontalScrollBar) { float alpha = horizontalScrollBar.alpha; alpha += horizontal ? delta * 6f : -delta * 3f; alpha = Mathf.Clamp01(alpha); if (horizontalScrollBar.alpha != alpha) { horizontalScrollBar.alpha = alpha; } } } if (!mShouldMove) { return; } // Apply momentum if (!mPressed) { if (mMomentum.magnitude > 0.0001f || mScroll != 0f) { if (movement == Movement.Horizontal) { mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * 0.05f, 0f, 0f)); } else if (movement == Movement.Vertical) { mMomentum -= mTrans.TransformDirection(new Vector3(0f, mScroll * 0.05f, 0f)); } else if (movement == Movement.Unrestricted) { mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * 0.05f, mScroll * 0.05f, 0f)); } else { mMomentum -= mTrans.TransformDirection(new Vector3( mScroll * customMovement.x * 0.05f, mScroll * customMovement.y * 0.05f, 0f)); } mScroll = NGUIMath.SpringLerp(mScroll, 0f, 20f, delta); // Move the scroll view Vector3 offset = NGUIMath.SpringDampen(ref mMomentum, dampenStrength, delta); MoveAbsolute(offset); // Restrict the contents to be within the scroll view's bounds if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None) { if (NGUITools.GetActive(centerOnChild)) { if (centerOnChild.nextPageThreshold != 0f) { mMomentum = Vector3.zero; mScroll = 0f; } else { centerOnChild.Recenter(); } } else { RestrictWithinBounds(false, canMoveHorizontally, canMoveVertically); } } if (onMomentumMove != null) { onMomentumMove(); } } else { mScroll = 0f; mMomentum = Vector3.zero; SpringPanel sp = GetComponent <SpringPanel>(); if (sp != null && sp.enabled) { return; } mShouldMove = false; if (onStoppedMoving != null) { onStoppedMoving(); } } } else { // Dampen the momentum mScroll = 0f; NGUIMath.SpringDampen(ref mMomentum, 9f, delta); } }
public override void OnInspectorGUI() { mFont = target as UIFont; NGUIEditorTools.SetLabelWidth(80f); GUILayout.Space(6f); if (mFont.replacement != null) { mType = FontType.Reference; mReplacement = mFont.replacement; } else if (mFont.dynamicFont != null) { mType = FontType.Dynamic; } GUI.changed = false; GUILayout.BeginHorizontal(); mType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (GUI.changed) { if (mType == FontType.Bitmap) { OnSelectFont(null); } if (mType != FontType.Dynamic && mFont.dynamicFont != null) { mFont.dynamicFont = null; } } if (mType == FontType.Reference) { ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one font simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "font with another one, for example for " + "swapping an SD font with an HD one, or " + "replacing an English font with a Chinese " + "one. All the labels referencing this font " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.replacement = mReplacement; NGUITools.SetDirty(mFont); } return; } else if (mType == FontType.Dynamic) { #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font; if (fnt != mFont.dynamicFont) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFont = fnt; } Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } GUILayout.BeginHorizontal(); int size = EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f)); FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (size != mFont.defaultSize) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.defaultSize = size; } if (style != mFont.dynamicFontStyle) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFontStyle = style; } #endif } else { ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas, true); if (mFont.atlas != null) { if (mFont.bmFont.isValid) { NGUIEditorTools.DrawAdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false); } EditorGUILayout.Space(); } else { // No atlas specified -- set the material and texture rectangle directly Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } } // For updating the font's data when importing from an external source, such as the texture packer bool resetWidthHeight = false; if (mFont.atlas != null || mFont.material != null) { TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset; if (data != null) { NGUIEditorTools.RegisterUndo("Import Font Data", mFont); BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes); mFont.MarkAsChanged(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } } if (mFont.bmFont.isValid) { Texture2D tex = mFont.texture; if (tex != null && mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Automatically set the width and height of the rectangle to be the original font texture's dimensions if (resetWidthHeight) { pixels.width = mFont.texWidth; pixels.height = mFont.texHeight; } // Font sprite rectangle pixels = EditorGUILayout.RectField("Pixel Rect", pixels); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont); mFont.uvRect = uvRect; } //NGUIEditorTools.DrawSeparator(); EditorGUILayout.Space(); } } } // Dynamic fonts don't support emoticons if (!mFont.isDynamic && mFont.bmFont.isValid) { if (mFont.atlas != null) { if (NGUIEditorTools.DrawHeader("Symbols and Emoticons")) { NGUIEditorTools.BeginContents(); List <BMSymbol> symbols = mFont.symbols; for (int i = 0; i < symbols.Count;) { BMSymbol sym = symbols[i]; GUILayout.BeginHorizontal(); GUILayout.Label(sym.sequence, GUILayout.Width(40f)); if (NGUIEditorTools.DrawSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite, GUILayout.MinWidth(100f))) { mSelectedSymbol = sym; } if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (mFont.atlas != null) { NGUISettings.atlas = mFont.atlas; NGUISettings.selectedSprite = sym.spriteName; NGUIEditorTools.Select(mFont.atlas.gameObject); } } GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove symbol", mFont); mSymbolSequence = sym.sequence; mSymbolSprite = sym.spriteName; symbols.Remove(sym); mFont.MarkAsChanged(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); ++i; } if (symbols.Count > 0) { GUILayout.Space(6f); } GUILayout.BeginHorizontal(); mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f)); NGUIEditorTools.DrawSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite); bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add symbol", mFont); mFont.AddSymbol(mSymbolSequence, mSymbolSprite); mFont.MarkAsChanged(); mSymbolSequence = ""; mSymbolSprite = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (symbols.Count == 0) { EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } NGUIEditorTools.EndContents(); } } } if (mFont.bmFont != null && mFont.bmFont.isValid) { if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); UISpriteData sd = mFont.sprite; bool disable = (sd != null && (sd.paddingLeft != 0 || sd.paddingBottom != 0)); EditorGUI.BeginDisabledGroup(disable || mFont.packedFontShader); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); NGUISettings.foregroundColor = EditorGUILayout.ColorField("Foreground", NGUISettings.foregroundColor); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); GUILayout.EndVertical(); mCurve = EditorGUILayout.CurveField("", mCurve, GUILayout.Width(40f), GUILayout.Height(40f)); GUILayout.EndHorizontal(); if (GUILayout.Button("Add a Shadow")) { ApplyEffect(Effect.Shadow, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Add a Soft Outline")) { ApplyEffect(Effect.Outline, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Rebalance Colors")) { ApplyEffect(Effect.Rebalance, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Apply Curve to Alpha")) { ApplyEffect(Effect.AlphaCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Apply Curve to Foreground")) { ApplyEffect(Effect.ForegroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Apply Curve to Background")) { ApplyEffect(Effect.BackgroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } GUILayout.Space(10f); if (GUILayout.Button("Add Transparent Border (+1)")) { ApplyEffect(Effect.Border, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Remove Border (-1)")) { ApplyEffect(Effect.Crop, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); if (disable) { GUILayout.Space(3f); EditorGUILayout.HelpBox("The sprite used by this font has been trimmed and is not suitable for modification. " + "Try re-adding this sprite with 'Trim Alpha' disabled.", MessageType.Warning); } NGUIEditorTools.EndContents(); } } // The font must be valid at this point for the rest of the options to show up if (mFont.isDynamic || mFont.bmFont.isValid) { if (mFont.atlas == null) { mView = View.Font; mUseShader = false; } } // Preview option if (!mFont.isDynamic && mFont.atlas != null) { GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Preview", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)); } GUILayout.EndHorizontal(); } }
/// <summary> /// Constrain the specified target to be within the panel's bounds. /// </summary> public bool ConstrainTargetToBounds(Transform target, bool immediate) { Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(cachedTransform, target); return(ConstrainTargetToBounds(target, ref bounds, immediate)); }
private void OnWillRenderObject() { this.UpdateMaterials(); if (this.onRender != null) { this.onRender(this.mDynamicMat ?? this.mMaterial); } if (this.mDynamicMat == null || this.mClipCount == 0) { return; } if (this.mTextureClip) { Vector4 drawCallClipRange = this.panel.drawCallClipRange; Vector2 clipSoftness = this.panel.clipSoftness; Vector2 vector = new Vector2(1000f, 1000f); if (clipSoftness.x > 0f) { vector.x = drawCallClipRange.z / clipSoftness.x; } if (clipSoftness.y > 0f) { vector.y = drawCallClipRange.w / clipSoftness.y; } this.mDynamicMat.SetVector(UIDrawCall.ClipRange[0], new Vector4(-drawCallClipRange.x / drawCallClipRange.z, -drawCallClipRange.y / drawCallClipRange.w, 1f / drawCallClipRange.z, 1f / drawCallClipRange.w)); this.mDynamicMat.SetTexture("_ClipTex", this.clipTexture); } else if (!this.mLegacyShader) { UIPanel parentPanel = this.panel; int num = 0; while (parentPanel != null) { if (parentPanel.hasClipping) { float angle = 0f; Vector4 drawCallClipRange2 = parentPanel.drawCallClipRange; if (parentPanel != this.panel) { Vector3 vector2 = parentPanel.cachedTransform.InverseTransformPoint(this.panel.cachedTransform.get_position()); drawCallClipRange2.x -= vector2.x; drawCallClipRange2.y -= vector2.y; Vector3 eulerAngles = this.panel.cachedTransform.get_rotation().get_eulerAngles(); Vector3 eulerAngles2 = parentPanel.cachedTransform.get_rotation().get_eulerAngles(); Vector3 vector3 = eulerAngles2 - eulerAngles; vector3.x = NGUIMath.WrapAngle(vector3.x); vector3.y = NGUIMath.WrapAngle(vector3.y); vector3.z = NGUIMath.WrapAngle(vector3.z); if (Mathf.Abs(vector3.x) > 0.001f || Mathf.Abs(vector3.y) > 0.001f) { Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", this.panel); } angle = vector3.z; } this.SetClipping(num++, drawCallClipRange2, parentPanel.clipSoftness, angle); } parentPanel = parentPanel.parentPanel; } } else { Vector2 clipSoftness2 = this.panel.clipSoftness; Vector4 drawCallClipRange3 = this.panel.drawCallClipRange; Vector2 mainTextureOffset = new Vector2(-drawCallClipRange3.x / drawCallClipRange3.z, -drawCallClipRange3.y / drawCallClipRange3.w); Vector2 mainTextureScale = new Vector2(1f / drawCallClipRange3.z, 1f / drawCallClipRange3.w); Vector2 vector4 = new Vector2(1000f, 1000f); if (clipSoftness2.x > 0f) { vector4.x = drawCallClipRange3.z / clipSoftness2.x; } if (clipSoftness2.y > 0f) { vector4.y = drawCallClipRange3.w / clipSoftness2.y; } this.mDynamicMat.set_mainTextureOffset(mainTextureOffset); this.mDynamicMat.set_mainTextureScale(mainTextureScale); this.mDynamicMat.SetVector("_ClipSharpness", vector4); } }