Ejemplo n.º 1
0
 public void UpdateSpline(Spline spline)
 {
     Generate();
     ApplyOffset();
     spline.type   = GetSplineType();
     spline.points = points;
     if (closed)
     {
         spline.Close();
     }
     else if (spline.isClosed)
     {
         spline.Break();
     }
 }
Ejemplo n.º 2
0
        private void UpdateVisualizer()
        {
            if (visualizer == null)
            {
                visualizer = new Spline(splineType);
            }
            visualizer.type       = splineType;
            visualizer.sampleRate = sampleRate;
            if (placementMode == PlacementMode.Insert)
            {
                visualizer.points = points;
                if (isClosed)
                {
                    visualizer.Close();
                }
                else if (visualizer.isClosed)
                {
                    visualizer.Break();
                }
                return;
            }

            if (visualizer.points.Length != points.Length + 1)
            {
                visualizer.points = new SplinePoint[points.Length + 1];
            }
            SplinePoint newPoint = new SplinePoint(createPoint, createPoint, createNormal, 1f, Color.white);

            if (appendMode == AppendMode.End)
            {
                if (isClosed)
                {
                    for (int i = 0; i < points.Length; i++)
                    {
                        visualizer.points[i] = points[i];
                    }
                    visualizer.points[visualizer.points.Length - 2] = newPoint;
                    visualizer.points[visualizer.points.Length - 1] = points[points.Length - 1];
                }
                else
                {
                    for (int i = 0; i < points.Length; i++)
                    {
                        visualizer.points[i] = points[i];
                    }
                    visualizer.points[visualizer.points.Length - 1] = newPoint;
                }
            }
            else
            {
                if (isClosed)
                {
                    for (int i = 1; i < points.Length; i++)
                    {
                        visualizer.points[i] = points[i - 1];
                    }
                    visualizer.points[1] = newPoint;
                    visualizer.points[0] = points[0];
                }
                else
                {
                    for (int i = 1; i < visualizer.points.Length; i++)
                    {
                        visualizer.points[i] = points[i - 1];
                    }
                    visualizer.points[0] = newPoint;
                }
            }
            if (isClosed && !visualizer.isClosed)
            {
                visualizer.Close();
            }
            else if (visualizer.isClosed)
            {
                visualizer.Break();
            }
            if (visualizer.isClosed)
            {
                visualizer.points[0].SetPosition(createPoint);
            }
        }
        public override void DrawScene(SceneView current)
        {
            CustomPathGenerator generator = (CustomPathGenerator)target;

            if (visualization == null)
            {
                visualization = new Spline(generator.customPathType, generator.customPathSampleRate);
            }
            visualization.sampleRate = generator.customPathSampleRate;
            visualization.type       = generator.customPathType;
            visualization.points     = generator.points;
            if (generator.loop && generator.points.Length > 3)
            {
                visualization.Close();
            }
            else if (visualization.isClosed)
            {
                visualization.Break();
            }
            DrawSpline(visualization);
            Vector3 cameraPos = SceneView.currentDrawingSceneView.camera.transform.position;

            for (int i = 0; i < generator.points.Length; i++)
            {
                if (visualization.isClosed && i == generator.points.Length - 1)
                {
                    continue;
                }
                Color col = generator.points[i].color;
                col.a         = 0.7f;
                Handles.color = col;
                if (i == selectedPoint)
                {
                    generator.points[i].SetPosition(Handles.PositionHandle(generator.points[i].position, Quaternion.identity));
                    if (visualization.type == Spline.Type.Bezier)
                    {
                        generator.points[i].SetTangent2Position(Handles.PositionHandle(generator.points[i].tangent2, Quaternion.identity));
                        generator.points[i].SetTangentPosition(Handles.PositionHandle(generator.points[i].tangent, Quaternion.identity));
                        Handles.DrawLine(generator.points[i].position, generator.points[i].tangent);
                        Handles.DrawLine(generator.points[i].position, generator.points[i].tangent2);
                    }
                }
                else
                {
                    Vector3 pos        = generator.points[i].position;
                    float   handleSize = HandleUtility.GetHandleSize(generator.points[i].position);
                    float   pointSize  = handleSize * 0.1f * Mathf.Max(generator.points[i].size, 0.2f);
                    Handles.DrawSolidDisc(pos, cameraPos - pos, pointSize);
                    Handles.DrawLine(pos, pos + generator.points[i].normal * 5f * handleSize * 0.2f);
                    if (generator.customPathType == Spline.Type.Bezier)
                    {
                        Handles.DrawDottedLine(generator.points[i].position, generator.points[i].tangent, 10f);
                        Handles.DrawDottedLine(generator.points[i].position, generator.points[i].tangent2, 10f);
                        Handles.DrawWireDisc(generator.points[i].tangent, cameraPos - generator.points[i].tangent, handleSize * 0.075f);
                        Handles.DrawWireDisc(generator.points[i].tangent2, cameraPos - generator.points[i].tangent2, handleSize * 0.075f);
                    }
                    Handles.color = Color.clear;
                    if (Handles.Button(pos, Quaternion.LookRotation(cameraPos - pos), pointSize, pointSize, Handles.CircleHandleCap))
                    {
                        selectedPoint = i;
                        pointsPanel   = true;
                        Repaint();
                    }
                }
            }
            if (generator.loop)
            {
                generator.points[generator.points.Length - 1] = generator.points[0];
            }
            Handles.color = Color.white;
        }