示例#1
0
        private void ResetHandleSettings()
        {
            if (selectedIndex == -1)
            {
                return;
            }

            if (Tools.pivotRotation == PivotRotation.Global)
            {
                handleRotation = Quaternion.identity;
                return;
            }

            Vector3 pos    = linePath.GetPoint(selectedIndex);
            Vector3 normal = linePath.GetNormal(selectedIndex);

            if (currentTool == Tool.Rotate)
            {
                Quaternion offsetRot = Quaternion.FromToRotation(handleRotation * Vector3.up, normal);
                handleRotation = offsetRot * handleRotation;
            }
            else
            {
                if (selectedIndex == 0)
                {
                    Vector3 guidePos = linePath.GetPoint(selectedIndex + 1);
                    Vector3 toGuide  = guidePos - pos;
                    if (toGuide == Vector3.zero)
                    {
                        toGuide = Vector3.forward;
                    }

                    handleRotation = Quaternion.LookRotation(toGuide, normal);
                }
                else
                {
                    Vector3 guidePos = linePath.GetPoint(selectedIndex - 1);
                    Vector3 toGuide  = guidePos - pos;
                    if (toGuide == Vector3.zero)
                    {
                        toGuide = Vector3.forward;
                    }

                    handleRotation = Quaternion.LookRotation(toGuide, normal);
                }
            }
        }
示例#2
0
        protected virtual void OnSceneGUI()
        {
            linePath        = target as LinePath;
            handleTransform = linePath.transform;

            if (currentTool != Tools.current ||
                currentPivotRotation != Tools.pivotRotation)
            {
                currentTool          = Tools.current;
                currentPivotRotation = Tools.pivotRotation;

                ResetHandleSettings();
            }

            for (int i = 0; i < linePath.PointCount; i++)
            {
                ShowPoint(i);
            }

            for (int i = 1; i < linePath.PointCount; i++)
            {
                Handles.color = Color.white;
                Handles.DrawLine(
                    linePath.transform.TransformPoint(linePath.Points[i]),
                    linePath.transform.TransformPoint(linePath.Points[i - 1]));
            }

            if (linePath.Loop)
            {
                Handles.DrawLine(
                    linePath.transform.TransformPoint(linePath.Points[0]),
                    linePath.transform.TransformPoint(linePath.Points[linePath.Points.Length - 1]));
            }

            Handles.color = Color.green.SetA(0.3f);
            Handles.SphereHandleCap(0, linePath.GetPoint(0f), Quaternion.identity, 0.1f, EventType.Repaint);

            Handles.color = Color.red.SetA(0.3f);
            Handles.SphereHandleCap(0, linePath.GetPoint(1f), Quaternion.identity, 0.1f, EventType.Repaint);

            if (linePath.NormalType == NormalType.Perpendicular)
            {
                for (int i = 0; i < linePath.Normals.Length; i++)
                {
                    Vector3 pos    = linePath.GetPoint(i);
                    Vector3 normal = linePath.GetNormal(i);

                    Handles.color = Color.red;
                    Handles.DrawLine(pos, pos + normal * 0.8f);
                }
            }

            int numIterations = 10 * linePath.PointCount;

            for (int i = 1; i < numIterations; i++)
            {
                float alpha = i / (float)numIterations;

                Vector3 pos    = linePath.GetPoint(alpha);
                Vector3 normal = linePath.GetNormal(alpha);

                Handles.color = Color.green;
                Handles.DrawLine(pos, pos + normal * 0.4f);
            }
        }