Exemple #1
0
        public void UpdateCollection()
        {
            if (source == null)
            {
                source = gameObject.GetComponent <LineBase>();
            }

            if (source == null)
            {
                return;
            }

            if (transformHelper == null)
            {
                transformHelper = transform.Find("TransformHelper");
                if (transformHelper == null)
                {
                    transformHelper        = new GameObject("TransformHelper").transform;
                    transformHelper.parent = transform;
                }
            }

            switch (StepMode)
            {
            case LineUtils.StepModeEnum.FromSource:
                break;

            case LineUtils.StepModeEnum.Interpolated:
                for (int i = 0; i < Objects.Count; i++)
                {
                    if (Objects[i] == null)
                    {
                        continue;
                    }

                    float normalizedDistance = Mathf.Repeat(((float)i / Objects.Count) + DistributionOffset, 1f);
                    Objects[i].position = source.GetPoint(normalizedDistance);
                    Objects[i].rotation = source.GetRotation(normalizedDistance, RotationTypeOverride);

                    transformHelper.localScale    = Vector3.one;
                    transformHelper.position      = Objects[i].position;
                    transformHelper.localRotation = Quaternion.identity;
                    Transform tempParent = Objects[i].parent;
                    Objects[i].parent = transformHelper;
                    transformHelper.localEulerAngles = RotationOffset;
                    Objects[i].parent = tempParent;
                    Objects[i].transform.localScale = Vector3.one * ObjectScale.Evaluate(Mathf.Repeat(ScaleOffset + normalizedDistance, 1f)) * ScaleMultiplier;

                    /*if (FlipRotation) {
                     *  Objects[i].forward = -Objects[i].forward;
                     * }*/
                }
                break;
            }
        }
Exemple #2
0
        public static void GizmosDrawLineRenderer(LineBase source, LineRenderer renderer)
        {
            switch (renderer.StepMode)
            {
            case LineUtils.StepModeEnum.FromSource:
                GizmosDrawLineFromSource(source, renderer);
                break;

            case LineUtils.StepModeEnum.Interpolated:
                GizmosDrawLineInterpolated(source, renderer);
                break;
            }
        }
Exemple #3
0
        protected virtual void OnDrawGizmos()
        {
            if (Application.isPlaying)
            {
                return;
            }

            if (source == null)
            {
                source = gameObject.GetComponent <LineBase>();
            }

            if (source == null || !source.enabled)
            {
                return;
            }

            GizmosDrawLineRenderer(source, this);
        }
        public virtual void OnSceneGUI()
        {
            if (Event.current.type == EventType.MouseDown)
            {
                mouseDown = true;
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                mouseDown     = false;
                recordingUndo = false;
            }

            LineBase line = (LineBase)target;

            if (line.ManualUpVectorBlend > 0)
            {
                DrawManualUpVectorHandles(line);
            }
        }
        protected void DrawManualUpVectorHandles(LineBase line)
        {
            if (line.ManualUpVectors == null || line.ManualUpVectors.Length < 2)
            {
                line.ManualUpVectors = new Vector3[2];
            }

            for (int i = 0; i < line.ManualUpVectors.Length; i++)
            {
                float   normalizedLength = (1f / (line.ManualUpVectors.Length - 1)) * i;
                Vector3 currentPoint     = line.GetPoint(normalizedLength);
                Vector3 currentUpVector  = line.ManualUpVectors[i];
                float   maxHandleLength  = (HandleUtility.GetHandleSize(currentPoint) * rotationHandleLength);
                Vector3 upVectorPoint    = currentPoint + (currentUpVector * (maxHandleLength * currentUpVector.magnitude));

                Handles.color = Color.Lerp(Color.black, Color.cyan, currentUpVector.magnitude);

                Handles.DrawDottedLine(currentPoint, upVectorPoint, rotationHandleSize);
                Handles.Label(upVectorPoint, currentUpVector.magnitude.ToString("0.00"));
                Vector3 newUpVectorPoint = Handles.FreeMoveHandle(
                    upVectorPoint,
                    Quaternion.identity,
                    HandleUtility.GetHandleSize(currentPoint) * rotationHandleSize,
                    Vector3.zero,
                    Handles.RectangleHandleCap);
                if (newUpVectorPoint != upVectorPoint)
                {
                    if (!recordingUndo)
                    {
                        recordingUndo = true;
                        Undo.RegisterCompleteObjectUndo(line, "Edit Manual Up Vector");
                    }
                    Vector3 newUpVector = (newUpVectorPoint - currentPoint) / maxHandleLength;
                    if (newUpVector.magnitude > 1)
                    {
                        newUpVector.Normalize();
                    }

                    line.ManualUpVectors[i] = newUpVector;
                }
            }
        }