/// <summary> /// By default, elements defined with an absolute size (in pixels), will be treated as fixed sized. /// This can be changed by setting IsFixedSize to false. /// </summary> public RectTransform(Point absoluteSize, RectTransform parent = null, Anchor anchor = Anchor.TopLeft, Pivot?pivot = null) { Init(parent, anchor, pivot); this.scaleBasis = ScaleBasis.Normal; this.nonScaledSize = absoluteSize; RecalculateScale(); RecalculateRelativeSize(); RecalculateAnchorPoint(); RecalculatePivotOffset(); IsFixedSize = true; parent?.ChildrenChanged?.Invoke(this); }
public RectTransform(Vector2 relativeSize, RectTransform parent, Anchor anchor = Anchor.TopLeft, Pivot?pivot = null, Point?minSize = null, Point?maxSize = null, ScaleBasis scaleBasis = ScaleBasis.Normal) { Init(parent, anchor, pivot); this.scaleBasis = scaleBasis; this.relativeSize = relativeSize; this.minSize = minSize; this.maxSize = maxSize; RecalculateScale(); RecalculateAbsoluteSize(); RecalculateAnchorPoint(); RecalculatePivotOffset(); parent?.ChildrenChanged?.Invoke(this); }
/// <summary> /// By default, elements defined with an absolute size (in pixels) will scale with the parent. /// This can be changed by setting IsFixedSize to true. /// </summary> public RectTransform(Point absoluteSize, RectTransform parent = null, Anchor anchor = Anchor.TopLeft, Pivot?pivot = null, ScaleBasis scaleBasis = ScaleBasis.Normal, bool isFixedSize = false) { Init(parent, anchor, pivot); _scaleBasis = scaleBasis; this.nonScaledSize = absoluteSize; RecalculateScale(); RecalculateRelativeSize(); if (scaleBasis != ScaleBasis.Normal) { RecalculateAbsoluteSize(); } RecalculateAnchorPoint(); RecalculatePivotOffset(); IsFixedSize = isFixedSize; parent?.ChildrenChanged?.Invoke(this); }
public static RectTransform Load(XElement element, RectTransform parent, Anchor defaultAnchor = Anchor.TopLeft) { Enum.TryParse(element.GetAttributeString("anchor", defaultAnchor.ToString()), out Anchor anchor); Enum.TryParse(element.GetAttributeString("pivot", anchor.ToString()), out Pivot pivot); Point? minSize = null, maxSize = null; ScaleBasis scaleBasis = ScaleBasis.Normal; if (element.Attribute("minsize") != null) { minSize = element.GetAttributePoint("minsize", Point.Zero); } if (element.Attribute("maxsize") != null) { maxSize = element.GetAttributePoint("maxsize", new Point(1000, 1000)); } string sb = element.GetAttributeString("scalebasis", null); if (sb != null) { Enum.TryParse(sb, ignoreCase: true, out scaleBasis); } RectTransform rectTransform; if (element.Attribute("absolutesize") != null) { rectTransform = new RectTransform(element.GetAttributePoint("absolutesize", new Point(1000, 1000)), parent, anchor, pivot, scaleBasis) { minSize = minSize, maxSize = maxSize }; } else { rectTransform = new RectTransform(element.GetAttributeVector2("relativesize", Vector2.One), parent, anchor, pivot, minSize, maxSize, scaleBasis); } rectTransform.RelativeOffset = element.GetAttributeVector2("relativeoffset", Vector2.Zero); rectTransform.AbsoluteOffset = element.GetAttributePoint("absoluteoffset", Point.Zero); return(rectTransform); }
private void AdjustCamZoom(ScaleBasis pBasis) { // calc max player distance, x, y and determine the normalizing part of things // set zoom as interpolation between two floats (the top one being he initial and the bottom being something else) // give it a velocity so it eases Vector3 avg = Vector3.zero; for(int i =0; i< trackChars.Count; i++) { avg += trackChars[0].transform.position; } if(trackChars!=null && trackChars.Count!= 0) avg /= (float) trackChars.Count; float highPoint = avg.z; float lowPoint = avg.z; float leftPoint = avg.x; float rightPoint = avg.x; Vector3 curPos; for(int i = 0; i< trackChars.Count; i++) { curPos = trackChars[i].transform.position; if(curPos.x>rightPoint) { rightPoint = curPos.x; } if(curPos.x < leftPoint) { leftPoint = curPos.x; } if(curPos.z>highPoint) { highPoint = curPos.z; } if(curPos.z < lowPoint) { lowPoint = curPos.z; } } if(pBasis == ScaleBasis.WIDTH_OR_HEIGHT) { float width = (rightPoint - leftPoint) + 2; float height = (highPoint - lowPoint)+4; float curRatio = width/height; float desiredOrthographicSize; if(curRatio > W_TO_H_RATIO) { //length is longer if(longestLength == 0) longestLength = 0.01f; desiredOrthographicSize = ((width)/longestLength) * (10 * (16.0f/9.0f) ); //Debug.Log("A"); } else { // width is longer if(highestHeight == 0) highestHeight = 0.01f; desiredOrthographicSize = ((height +8)/highestHeight)* 10; //Debug.Log("B"); } } else if(pBasis == ScaleBasis.HYPOTENUSE) { float width = (rightPoint - leftPoint) + 4; float height = (highPoint - lowPoint) * 1.8f; float desiredOrthographicSize = (Mathf.Sqrt((width * width)+ (height * height)) / initHypotenuse) * initialOrthSize; if(desiredOrthographicSize > maxOrth-2) desiredOrthographicSize = maxOrth; if(desiredOrthographicSize < minOrth) desiredOrthographicSize = minOrth; if(Mathf.Abs(camGO.GetComponent<Camera>().orthographicSize - desiredOrthographicSize) >1.0f) { if(desiredOrthographicSize > camGO.GetComponent<Camera>().orthographicSize ) { camGO.GetComponent<Camera>().orthographicSize += zoomSpeed * Time.deltaTime; } else { camGO.GetComponent<Camera>().orthographicSize -= zoomSpeed * Time.deltaTime; } } } }
public void ProcessMouseWheel(Control sender, MouseEventArgs e) { double num11; double num12; double num13; RectDouble visibleCanvasViewportBounds = this.canvasView.GetVisibleCanvasViewportBounds(); PointInt32 point = base.PointToClient(sender.PointToScreen(e.Location)).ToPointInt32(); PointDouble viewportPt = RectDoubleUtil.Clamp(visibleCanvasViewportBounds, point); PointDouble extentPt = this.canvasView.ConvertViewportToExtent(viewportPt); PointDouble num5 = this.canvasView.ConvertExtentToCanvas(extentPt); double scaleRatio = this.canvasView.ScaleRatio; PointDouble viewportCanvasOffset = this.canvasView.ViewportCanvasOffset; double num8 = ((double)e.Delta) / scaleRatio; double x = viewportCanvasOffset.X; double y = viewportCanvasOffset.Y; ScaleBasis scaleBasis = this.canvasView.ScaleBasis; ScaleBasis ratio = ScaleBasis.Ratio; if (Control.ModifierKeys == Keys.Shift) { num11 = x - num8; num12 = y; ratio = scaleBasis; num13 = scaleRatio; } else if (Control.ModifierKeys == Keys.Control) { double num16; double num14 = ((double)e.Delta) / 120.0; double num15 = Math.Pow(1.12, Math.Abs(num14)); if (e.Delta > 0) { num16 = scaleRatio * num15; } else { num16 = scaleRatio / num15; } double num17 = this.canvasView.ClampScaleRatio(num16); double num18 = Math.Round(num17, MidpointRounding.AwayFromZero); if ((Math.Abs((double)(num18 - num17)) < (num18 * 0.1)) && (Math.Abs((double)(num18 - num17)) < Math.Abs((double)(num18 - scaleRatio)))) { num13 = num18; } else { num13 = num17; } ratio = ScaleBasis.Ratio; num11 = num5.X - (viewportPt.X / num13); num12 = num5.Y - (viewportPt.Y / num13); } else if (Control.ModifierKeys == Keys.None) { num11 = x; num12 = y - num8; ratio = scaleBasis; num13 = scaleRatio; } else { num11 = x; num12 = y; ratio = scaleBasis; num13 = scaleRatio; } this.canvasView.ViewportCanvasOffset = new PointDouble(num11, num12); this.canvasView.ScaleBasis = ratio; this.canvasView.ScaleRatio = num13; }