Beispiel #1
0
    void SamplePath(int stepsPerSegment)
    {
        curve = new AnimationCurve();
        float minPos   = path.MinPos;
        float maxPos   = path.MaxPos;
        float stepSize = 1f / Mathf.Max(1, stepsPerSegment);

        pathLength = 0;
        Vector3 p0 = path.EvaluatePosition(0);

        curve.AddKey(new Keyframe(0, 0));
        for (float pos = minPos + stepSize; pos < (maxPos + stepSize / 2); pos += stepSize)
        {
            Vector3 p = path.EvaluatePosition(pos);
            pathLength += Vector3.Distance(p0, p);
            curve.AddKey(new Keyframe(pathLength, pos));
            p0 = p;
        }

        for (int i = 0; i < curve.keys.Length; i++)
        {
            // TODO: replace this with something that does not depend on editor
            AnimationUtility.SetKeyLeftTangentMode(curve, i, AnimationUtility.TangentMode.Linear);
            AnimationUtility.SetKeyRightTangentMode(curve, i, AnimationUtility.TangentMode.Linear);
        }
    }
Beispiel #2
0
        internal static void DrawPathGizmos(CinemachinePath path, GizmoType selectionType)
        {
            // Draw the path
            Color colorOld = Gizmos.color;

            Gizmos.color = (Selection.activeGameObject == path.gameObject)
                ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor;
            float   step    = 1f / path.m_Appearance.steps;
            Vector3 lastPos = path.EvaluatePosition(path.MinPos);
            Vector3 lastW   = (path.EvaluateOrientation(path.MinPos)
                               * Vector3.right) * path.m_Appearance.width / 2;

            for (float t = path.MinPos + step; t <= path.MaxPos + step / 2; t += step)
            {
                Vector3 p  = path.EvaluatePosition(t);
                Vector3 w  = (path.EvaluateOrientation(t) * Vector3.right) * path.m_Appearance.width / 2;
                Vector3 w2 = w * 1.2f;
                Vector3 p0 = p - w2;
                Vector3 p1 = p + w2;
                Gizmos.DrawLine(p0, p1);
                Gizmos.DrawLine(lastPos - lastW, p - w);
                Gizmos.DrawLine(lastPos + lastW, p + w);
                lastPos = p;
                lastW   = w;
            }
            Gizmos.color = colorOld;
        }
    void SetCartPosition(float distanceAlongPath)
    {
        if (m_Path == null)
        {
            return;
        }

        m_CurrentDistance = m_Path.NormalizePathDistance(distanceAlongPath);
        float pathPos = m_Path.GetPathPositionFromDistance(m_CurrentDistance);

        transform.position = m_Path.EvaluatePosition(pathPos);
        transform.rotation = m_Path.EvaluateOrientation(pathPos);
    }
Beispiel #4
0
        internal static void DrawPathGizmos(CinemachinePath path, GizmoType selectionType)
        {
            // Draw the path
            Color colorOld = Gizmos.color;

            Gizmos.color = (Selection.activeGameObject == path.gameObject)
                ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor;
            float   step    = 1f / path.m_Resolution;
            Vector3 lastPos = path.EvaluatePosition(path.MinPos);
            Vector3 lastW   = (path.EvaluateOrientation(path.MinPos)
                               * Vector3.right) * path.m_Appearance.width / 2;

            for (float t = path.MinPos + step; t <= path.MaxPos + step / 2; t += step)
            {
                Vector3    p  = path.EvaluatePosition(t);
                Quaternion q  = path.EvaluateOrientation(t);
                Vector3    w  = (q * Vector3.right) * path.m_Appearance.width / 2;
                Vector3    w2 = w * 1.2f;
                Vector3    p0 = p - w2;
                Vector3    p1 = p + w2;
                Gizmos.DrawLine(p0, p1);
                Gizmos.DrawLine(lastPos - lastW, p - w);
                Gizmos.DrawLine(lastPos + lastW, p + w);
#if false
                // Show the normals, for debugging
                Gizmos.color = Color.red;
                Vector3 y = (q * Vector3.up) * path.m_Appearance.width / 2;
                Gizmos.DrawLine(p, p + y);
                Gizmos.color = (Selection.activeGameObject == path.gameObject)
                    ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor;
#endif
                lastPos = p;
                lastW   = w;
            }
            Gizmos.color = colorOld;
        }