コード例 #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
ファイル: Line.cs プロジェクト: stadoblech/Rounded-Corners
    public void ReasignNeighbourPoints()
    {
        int pointsCount = AnchorPoints.Count;

        for (int i = 0; i < pointsCount; i++)
        {
            AnchorPoints[i].Name = "point " + i;

            AnchorPoints[i].PreviousPoint = null;
            AnchorPoints[i].NextPoint     = null;

            int         indexNext     = (i + 1) % pointsCount;
            int         indexPrevious = (i - 1 < 0) ? pointsCount - 1 : i - 1;
            AnchorPoint point         = AnchorPoints[i];
            AnchorPoint pointNext     = AnchorPoints[indexNext];
            AnchorPoint pointPrevious = AnchorPoints[indexPrevious];

            if (!ClosedLine)
            {
                if (i == 0)
                {
                    point.ResetValues();
                    point.PreviousPoint = null;
                }
                if (i == pointsCount - 1)
                {
                    point.ResetValues();
                    point.NextPoint = null;
                }
            }
//            AnchorPoints[i] = point;
            if (i == 0 && ClosedLine || i != 0)
            {
                point.PreviousPoint = pointPrevious;
            }
            if (i == pointsCount - 1 && ClosedLine || i != pointsCount - 1)
            {
                point.NextPoint = pointNext;
            }
        }
    }
コード例 #3
0
    private void DrawInspectorPointControls()
    {
        GUILayout.Label("Points", Bold);

        if (GUILayout.Button("+", GUILayout.Width(18)))
        {
            Undo.RecordObject(Line, "Point added");
            Vector3 newPosition = Vector3.zero;
            if (Line != null && Line.AnchorPoints.Count > 0)
            {
                newPosition = Line.AnchorPoints[Line.AnchorPoints.Count - 1].Position + Vector2.right;
            }
            Line.AddPointAtTheEnd(newPosition);
            SceneView.RepaintAll();
        }

        for (int i = 0; i < Line.AnchorPoints.Count; i++)
        {
            AnchorPoint point = Line.AnchorPoints[i];

            string[] pointTypes = System.Enum.GetNames(typeof(PointType));

            GUILayout.BeginHorizontal();
            GUILayout.Label(point.Name);

            {
                EditorGUI.BeginChangeCheck();
                PointType pointType = (PointType)EditorGUILayout.Popup((int)point.PointType, pointTypes);

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(Line, "Change Point Type");

                    point.PointType = pointType;

                    if (point.PointType == PointType.None)
                    {
                        point.ResetValues();
                    }

                    SceneView.RepaintAll();
                }
            }

            if (GUILayout.Button("X", GUILayout.Width(15), GUILayout.Height(15)))
            {
//                RemovePoint(point);
                Line.RemovePoint(i);
                SelectedAnchorPoints.Clear();
                SceneView.RepaintAll();
            }
            GUILayout.EndHorizontal();

            EditorGUI.BeginChangeCheck();
            Vector3 position = EditorGUILayout.Vector3Field("    Position: ", point.Position);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(Line, "Move Point");
                point.Position = position;
                SceneView.RepaintAll();
            }

            if (point.PointType == PointType.RoundedCorner)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.BeginHorizontal();
//                GUILayout.Label("    Smooth Strength:", GUILayout.Width(170));
                float defaultLabelWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 147;
                float smoothStrength = EditorGUILayout.FloatField("    Smooth Strength:", point.SmoothStrength, GUILayout.Width(212));
                EditorGUIUtility.labelWidth = defaultLabelWidth;
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(Line, "SmoothStrength");
                    point.SmoothStrength = smoothStrength;
                    SceneView.RepaintAll();
                }
                EditorGUILayout.EndHorizontal();
            }
        }
    }