コード例 #1
0
        public void DrawPath(Vector2[] points, StrokeStyle strokeStyle, bool closePath)
        {
            if (points.Length < 2)
            {
                Debug.LogError("DrawPath() needs at least two points to draw");
                return;
            }
            else if (points.Length == 2)
            {
                DrawLine(points[0], points[1], strokeStyle);
                if (closePath)
                {
                    Debug.LogWarning("DrawPath() can't close a path with only two points. 'closePath' parameter ignored.");
                }
                return;
            }

            float relativeThickness = strokeStyle.scaleMode == StrokeScaleMode.Absolute ?
                                      strokeStyle.thickness / rectTransform.rect.width :
                                      strokeStyle.thickness;

//			Debug.Log(String.Join(", ", PUIUtils.GetPathPoints(points, closePath, relativeThickness, aspectRatio).Select(x => x.ToString("f5")).ToArray()));
            elements.Add(new PUIStrokeElement(points,
                                              PUIUtils.GetPathPoints(points, closePath, relativeThickness, aspectRatio),
                                              strokeStyle,
                                              closePath));

            if (setDirtyOnDraw)
            {
                SetVerticesDirty();
            }
        }
コード例 #2
0
        protected override void OnRectTransformDimensionsChange()
        {
            base.OnRectTransformDimensionsChange();

            PUIStrokeElement current;

            foreach (PUIElement el in elements)
            {
                if (el.GetType() == typeof(PUIStrokeElement))
                {
                    current = (PUIStrokeElement)el;

                    if (current.strokeStyle.scaleMode == StrokeScaleMode.Absolute)
                    {
                        float relativeThickness = current.strokeStyle.thickness / rectTransform.rect.width;

                        if (current.rawPoints.Length == 2)
                        {
                            current.UpdatePoints(PUIUtils.GetLinePoints(current.rawPoints[0], current.rawPoints[1],
                                                                        relativeThickness,
                                                                        aspectRatio));
                        }
                        else
                        {
                            current.UpdatePoints(PUIUtils.GetPathPoints(current.rawPoints,
                                                                        current.isClosedPath,
                                                                        relativeThickness,
                                                                        aspectRatio));
                        }
                    }
                }
            }
        }