示例#1
0
 private void PointTypeShortcuts()
 {
     if (LastSelectedPoint != null)
     {
         if (Event.current.shift)
         {
             if (Event.current.type == EventType.keyDown)
             {
                 if (Event.current.keyCode == KeyCode.Alpha2)
                 {
                     Undo.RecordObject(Line, "Change node type");
                     LastSelectedPoint.PointType = PointType.RoundedCorner;
                     LastSelectedPoint.RecalculateCornerValues();
                     SceneView.RepaintAll();
                 }
                 if (Event.current.keyCode == KeyCode.Alpha1)
                 {
                     Undo.RecordObject(Line, "Change node type");
                     LastSelectedPoint.PointType = PointType.None;
                     LastSelectedPoint.RecalculateCornerValues();
                     LastSelectedPoint.ResetValues();
                     SceneView.RepaintAll();
                 }
             }
         }
     }
 }
示例#2
0
    public void RemovePoint(int index)
    {
        if (AnchorPoints.Count == 0)
        {
            return;
        }

        if (AnchorPoints.Count == 1)
        {
            AnchorPoints.Clear();
            return;
        }

        AnchorPoint previousPoint = GetPreviousPoint(index);
        AnchorPoint nextPoint     = GetNextPoint(index);

        if (AnchorPoints.Count == 2)
        {
            nextPoint.PreviousPoint = null;
            nextPoint.NextPoint     = null;
            nextPoint.Name          = "point 0";
            AnchorPoints.RemoveAt(index);
            nextPoint.RecalculateCornerValues();
            return;
        }

        if (previousPoint != null)
        {
            previousPoint.NextPoint = nextPoint;
        }

        if (nextPoint != null)
        {
            nextPoint.PreviousPoint = previousPoint;
            nextPoint.Name          = "point " + index;
        }

        AnchorPoints.RemoveAt(index);

        for (int i = index; i < AnchorPoints.Count; i++)
        {
            AnchorPoints[i].Name = "point " + i;
        }

        if (nextPoint != null)
        {
            nextPoint.RecalculateCornerValues();
        }
        if (previousPoint != null)
        {
            previousPoint.RecalculateCornerValues();
        }
    }
示例#3
0
    private void DrawScenePointCornerControl(AnchorPoint point, bool isSelected)
    {
        point.RecalculateCornerValues();

        AnchorPoint pointPrevious = point.PreviousPoint;
        AnchorPoint pointNext     = point.NextPoint;

        Vector2 A  = pointPrevious.Position;
        Vector2 B  = point.Position;
        Vector2 C  = pointNext.Position;
        Vector2 AC = C - A;
        Vector2 BA = A - B;
        Vector2 BC = C - B;

        // draw circle
        Assert.IsNotNull(point);
        Assert.IsNotNull(pointNext);
        Assert.IsNotNull(pointPrevious);

        Vector2 arcCenter = B + point.Vh;

//        if (isSelected)
        if (DrawCornerCircle)
        {
            Handles.color = Color.gray;
            Handles.DrawWireDisc(arcCenter, Vector3.forward, point.Radius);
        }

        {// draw arc
            Vector2 ACnl     = Utils.NormalL(AC);
            bool    isConvex = Vector2.Dot(ACnl, point.Vh) < 0;

//        DrawRay(B, ACnl, Color.red);
//        DrawRay(B, point.Vh, Color.grey);

            Vector2 startAngleVector = isConvex ? Utils.NormalL(BC) : Utils.NormalL(BA);
//        DrawRay(arcCenter, startAngleVector, Color.magenta);

            Handles.color = Color.white;
            Handles.DrawWireArc(arcCenter, Vector3.forward, startAngleVector, point.ArcAngle, point.Radius);
        }

        {// draw sides
//        Handles.color = Color.red;
            if (pointNext != null && pointNext.PointType == PointType.RoundedCorner)
            {
                Vector2 start = B + point.RightTangent;
                Vector2 end   = pointNext.Position + pointNext.LeftTangent;
                Handles.DrawLine(start, (start + end) * 0.5f);
            }
            else
            {
                Handles.DrawLine(B + point.RightTangent, C);
            }

//        Handles.color = Color.blue;
            if (pointPrevious != null && pointPrevious.PointType == PointType.RoundedCorner)
            {
                Vector2 start = B + point.LeftTangent;
                Vector2 end   = pointPrevious.Position + pointPrevious.RightTangent;
                Handles.DrawLine(start, (start + end) * 0.5f);
            }
            else
            {
                Handles.DrawLine(A, B + point.LeftTangent);
            }
        }

//        Handles.color = Color.grey;
//        Handles.DrawLine(B + point.LeftTangent, B + point.Vh);
//        Handles.DrawLine(B + point.RightTangent, B + point.Vh);

//        if (isSelected)
        if (DrawCornerCircle)
        {
            float   size        = 0.2f;
            Vector2 leftNormal  = Utils.NormalL(BA) * size * 0.5f;
            Vector2 rightNormal = Utils.NormalR(BC) * size * 0.5f;
            DrawRay(B + point.LeftTangent - leftNormal, leftNormal * 2, Color.gray);
            DrawRay(B + point.RightTangent - rightNormal, rightNormal * 2, Color.gray);
//            DrawRay(B + point.Vh, point.StartVector, Color.yellow);
        }


//        if (isSelected) {
        DrawRay(B + point.Vh - point.VhN * point.Radius, point.VhN * point.Radius, Color.grey);

        EditorGUI.BeginChangeCheck();
        {
            Vector2 smoothVector = B + point.Vh;

            float handleSize = HandleUtility.GetHandleSize(point.Position) * HandleSize;

            Vector2 sliderPosition = Handles.Slider(smoothVector, point.VhN, handleSize, (controlID, position, rotation, size) => {
                if (!SelectedAnchorPoints.ContainsKey(controlID))
                {
                    SelectedAnchorPoints.Add(controlID, point);
                }
                Handles.SphereCap(controlID, position, Quaternion.Euler(0, 0, 0), handleSize);
            }, 1f);

            Vector2 newSmoothVector = sliderPosition - B;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(Line, "Change Corner Smooth Strength");
                point.SmoothStrength = Mathf.Max(0, newSmoothVector.magnitude);
            }
        }
//        }
    }