public void DoAlignToCanvas() { if (!GetCamera()) { return; } if (_mainCamera.orthographic && Mathfx.Approximately(_mainCamera.orthographicSize, 0)) { return; } var screenSize = GetGameViewSize(); var bottomLeft = _mainCamera.ScreenToWorldPoint(new Vector3(0, 0, _mainCamera.nearClipPlane)); var topRight = _mainCamera.ScreenToWorldPoint(new Vector3(screenSize.x, screenSize.y, _mainCamera.farClipPlane)); if (Boundaries == null) { return; } switch (HorizontalAlign) { case HorizontalAlignType.Left: _offsetX = bottomLeft.x + transform.lossyScale.x * (-Boundaries.center.x + Boundaries.size.x / 2); break; case HorizontalAlignType.Right: _offsetX = topRight.x + transform.lossyScale.x * (-Boundaries.center.x - Boundaries.size.x / 2); break; case HorizontalAlignType.Center: _offsetX = (topRight.x + bottomLeft.x) / 2 + transform.lossyScale.x * -Boundaries.center.x; break; } switch (VerticalAlign) { case VerticalAlignType.Bottom: _offsetY = bottomLeft.y + transform.lossyScale.x * (-Boundaries.center.y + (Boundaries.size.y / 2)); break; case VerticalAlignType.Top: _offsetY = topRight.y + transform.lossyScale.x * (-Boundaries.center.y - (Boundaries.size.y / 2)); break; case VerticalAlignType.Center: _offsetY = (topRight.y + bottomLeft.y) / 2 + transform.lossyScale.x * -Boundaries.center.y; break; } transform.position = new Vector3(_offsetX, _offsetY, transform.position.z); }
private void ParseGradient(XmlNode svgEntry, RageSvgObject pathData, RageSvgGradient.GradientType gradientType, bool subPath, int level) { // Initializes a new Gradient pathData.Gradient = RageSvgGradient.NewInstance(); pathData.Gradient.Type = gradientType; float radius = 0f; var gradientTransformString = ""; XmlAttributeCollection attributes = svgEntry.Attributes; if (attributes != null) { foreach (XmlAttribute svgAttribute in attributes) { string svgCommand = svgAttribute.Name; string svgValue = svgAttribute.Value; // Parse valid Svg style commands, if any found, iterate // if (ParseSvgStyle(svgCommand, svgValue)) continue; switch (svgCommand) { //<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="170.0791" y1="85.0396" x2="170.0791" y2="28.3472"> case ("id"): pathData.Gradient.Id = svgValue; break; case ("xlink:href"): ParseGradientLink(ref pathData.Gradient, svgValue.Substring(1)); break; case ("x1"): pathData.Gradient.X1 = svgValue.SvgToFloat(); break; case ("y1"): pathData.Gradient.Y1 = svgValue.SvgToFloat(); break; case ("x2"): pathData.Gradient.X2 = svgValue.SvgToFloat(); break; case ("y2"): pathData.Gradient.Y2 = svgValue.SvgToFloat(); break; case ("cx"): pathData.Gradient.X2 = svgValue.SvgToFloat(); break; case ("cy"): pathData.Gradient.Y2 = svgValue.SvgToFloat(); break; case ("fx"): pathData.Gradient.X1 = svgValue.SvgToFloat(); break; case ("fy"): pathData.Gradient.Y1 = svgValue.SvgToFloat(); break; case ("r"): radius = svgValue.SvgToFloat(); break; case ("gradientTransform"): gradientTransformString = svgValue; break; } } } if (!(Mathfx.Approximately(radius, 0f))) { pathData.Gradient.X2 = pathData.Gradient.X1 + radius; pathData.Gradient.Y2 = pathData.Gradient.Y2 + radius; } if (DebugStyleCreation) { Debug.Log("######### Gradient children Count: " + svgEntry.ChildNodes.Count); } if (svgEntry.ChildNodes.Count != 0) { level++; foreach (XmlNode childNode in svgEntry.ChildNodes) { ParseSvg(childNode, pathData, subPath, level); } } ApplyGradientTransform(gradientTransformString, pathData); if (_gradients.ContainsKey(pathData.Gradient.Id)) { return; } if (DebugStyleCreation) { Debug.Log("Gradient entry added: " + pathData.Gradient.Id); } // After all "stop" child nodes are parsed, actually add the new dictionary item _gradients.Add(pathData.Gradient.Id, pathData.Gradient); }