Exemple #1
0
        //Loop:
        void Update()
        {
            //initialize:
            if (!_initialized)
            {
                //refs:
                _lineRenderer = GetComponent <LineRenderer> ();
                _spline       = GetComponent <Objects.Spline> ();

                //initial setup:
                ConfigureLineRenderer();
                UpdateLineRenderer();

                _initialized = true;
            }

            //configure line renderer:
            if (segmentsPerCurve != _previousSegmentsPerCurve || _previousAnchorsLength != _spline.Anchors.Length)
            {
                ConfigureLineRenderer();
                UpdateLineRenderer();
            }

            if (_spline.Anchors.Length <= 1)
            {
                _lineRenderer.positionCount = 0;
                return;
            }

            //if any part of the spline is changed update line renderer:
            foreach (var item in _spline.Anchors)
            {
                if (item.RenderingChange)
                {
                    item.RenderingChange = false;
                    UpdateLineRenderer();
                }
            }

            //if the range has changed, update:
            if (startPercentage != _previousStart || endPercentage != _previousEnd)
            {
                UpdateLineRenderer();

                //reset:
                _previousStart = startPercentage;
                _previousEnd   = endPercentage;
            }
        }
Exemple #2
0
 void OnEnable()
 {
     _target = target as Objects.Spline;
 }
Exemple #3
0
        static void DrawTools(Transform target)
        {
            Objects.Spline spline = target.GetComponent <Objects.Spline> ();

            if (spline == null)
            {
                return;
            }
            if (target.transform.childCount == 0)
            {
                return;
            }

            Handles.color = spline.SecondaryColor;

            for (int i = 0; i < spline.Anchors.Length; i++)
            {
                Quaternion   lookRotation  = Quaternion.identity;
                SplineAnchor currentAnchor = spline.Anchors[i];

                currentAnchor.InTangent.localScale  = Vector3.one * (spline.toolScale * 1.3f);
                currentAnchor.OutTangent.localScale = Vector3.one * (spline.toolScale * 1.3f);
                currentAnchor.Anchor.localScale     = Vector3.one * (spline.toolScale * 2.1f);

                if (spline.toolScale > 0)
                {
                    if (currentAnchor.OutTangent.gameObject.activeSelf)
                    {
                        Handles.DrawDottedLine(currentAnchor.Anchor.position, currentAnchor.OutTangent.position, 3);

                        if (SceneView.currentDrawingSceneView != null)
                        {
                            lookRotation = Quaternion.LookRotation((SceneView.currentDrawingSceneView.camera.transform.position - currentAnchor.OutTangent.position).normalized);
                            Handles.CircleHandleCap(0, currentAnchor.OutTangent.position, lookRotation, spline.toolScale * .65f, EventType.Repaint);
                            Handles.CircleHandleCap(0, currentAnchor.OutTangent.position, lookRotation, spline.toolScale * .25f, EventType.Repaint);
                        }
                    }

                    if (currentAnchor.InTangent.gameObject.activeSelf)
                    {
                        Handles.DrawDottedLine(currentAnchor.Anchor.position, currentAnchor.InTangent.position, 3);

                        if (SceneView.currentDrawingSceneView != null)
                        {
                            lookRotation = Quaternion.LookRotation((SceneView.currentDrawingSceneView.camera.transform.position - currentAnchor.InTangent.position).normalized);
                            Handles.CircleHandleCap(0, currentAnchor.InTangent.position, lookRotation, spline.toolScale * .65f, EventType.Repaint);
                            Handles.CircleHandleCap(0, currentAnchor.InTangent.position, lookRotation, spline.toolScale * .25f, EventType.Repaint);
                        }
                    }

                    if (SceneView.currentDrawingSceneView != null)
                    {
                        lookRotation = Quaternion.LookRotation((SceneView.currentDrawingSceneView.camera.transform.position - currentAnchor.Anchor.position).normalized);
                        Handles.CircleHandleCap(0, currentAnchor.Anchor.position, lookRotation, spline.toolScale, EventType.Repaint);
                    }

                    if (spline.direction == SplineDirection.Forward && i == 0 || spline.direction == SplineDirection.Backwards && i == spline.Anchors.Length - 1)
                    {
                        Handles.CircleHandleCap(0, currentAnchor.Anchor.position, lookRotation, spline.toolScale * .8f, EventType.Repaint);
                        Handles.CircleHandleCap(0, currentAnchor.Anchor.position, lookRotation, spline.toolScale * .75f, EventType.Repaint);
                        Handles.CircleHandleCap(0, currentAnchor.Anchor.position, lookRotation, spline.toolScale * .5f, EventType.Repaint);
                        Handles.CircleHandleCap(0, currentAnchor.Anchor.position, lookRotation, spline.toolScale * .45f, EventType.Repaint);
                        Handles.CircleHandleCap(0, currentAnchor.Anchor.position, lookRotation, spline.toolScale * .25f, EventType.Repaint);
                    }
                }
            }

            for (int i = 0; i < spline.Anchors.Length - 1; i++)
            {
                SplineAnchor startAnchor = spline.Anchors[i];
                SplineAnchor endAnchor   = spline.Anchors[i + 1];
                Handles.DrawBezier(startAnchor.Anchor.position, endAnchor.Anchor.position, startAnchor.OutTangent.position, endAnchor.InTangent.position, spline.color, null, 2);
            }
        }
 //Init:
 void Awake()
 {
     _spline = GetComponent <Objects.Spline> ();
 }