コード例 #1
0
    /// <summary>
    /// Check the free points and recalculate their values if a point have been added inside it's curve
    /// </summary>
    /// <param name="addedPoint">The added point to the path</param>
    public void PathPointAddedEvent(CameraPathControlPoint addedPoint)
    {
        float pointPercentage = addedPoint.percentage;

        for (int i = 0; i < realNumberOfPoints; i++)//Check freepoints have not been affected by the addition
        {
            CameraPathPoint point = _points[i];
            if (point.positionModes == CameraPathPoint.PositionModes.Free)
            {
                float cPointPercentageA = point.cpointA.percentage;
                float cPointPercentageB = point.cpointB.percentage;
                if (pointPercentage > cPointPercentageA && pointPercentage < cPointPercentageB)
                {
                    if (pointPercentage < point.percent)
                    {
                        //new point added before
                        point.cpointA = addedPoint;
                    }
                    else
                    {
                        //new point added after
                        point.cpointB = addedPoint;
                    }
                    cameraPath.GetCurvePercentage(point);//Recalculate free point values
                }
            }
        }
    }
コード例 #2
0
    private static void SceneGUIEaseBased()
    {
        CameraPathDelayList pointList = _cameraPath.delayList;
        Camera sceneCamera            = Camera.current;
        int    pointCount             = pointList.realNumberOfPoints;

        for (int i = 0; i < pointCount; i++)
        {
            CameraPathDelay point = pointList[i];
            if (_cameraPath.enableUndo)
            {
                Undo.RecordObject(point, "Modifying Ease Curves");
            }

            if (Vector3.Dot(sceneCamera.transform.forward, point.worldPosition - sceneCamera.transform.position) < 0)
            {
                continue;
            }

            string pointLabel = "";
            if (point == pointList.introPoint)
            {
                pointLabel += "start point";
            }
            else if (point == pointList.outroPoint)
            {
                pointLabel += "end point";
            }
            else
            {
                pointLabel += point.displayName;

                if (point.time > 0)
                {
                    pointLabel += "\ndelay: " + point.time.ToString("F2") + " sec";
                }
                else
                {
                    pointLabel += "\ndelay indefinitely";
                }
            }

            Handles.Label(point.worldPosition, pointLabel);
            float pointHandleSize = HandleUtility.GetHandleSize(point.worldPosition) * HANDLE_SCALE;
            Handles.color = (i == selectedPointIndex) ? _cameraPath.selectedPointColour : _cameraPath.unselectedPointColour;
            if (Handles.Button(point.worldPosition, Quaternion.identity, pointHandleSize, pointHandleSize, Handles.DotCap))
            {
                ChangeSelectedPointIndex(i);
                GUI.changed = true;
            }

//            float unitPercent = 0.5f;
            Vector3 easeUp = Vector3.up * _cameraPath.pathLength * 0.1f;
            Handles.color = CameraPathColours.RED;
            if (point != pointList.outroPoint)
            {
                float   outroEasePointPercent = _cameraPath.GetOutroEasePercentage(point);
                Vector3 outroEasePoint        = _cameraPath.GetPathPosition(outroEasePointPercent, true);
                Vector3 outroeaseDirection    = _cameraPath.GetPathDirection(outroEasePointPercent, false);

                Handles.Label(outroEasePoint, "Ease Out\n" + point.displayName);
                Vector3 newPosition = Handles.Slider(outroEasePoint, outroeaseDirection);

                float movement = Vector3.Distance(outroEasePoint, newPosition);
                if (movement > Mathf.Epsilon)
                {
                    float newPercent   = NearestmMousePercentage();
                    float curvePercent = _cameraPath.GetCurvePercentage(_cameraPath.delayList.GetPoint(point.index), _cameraPath.delayList.GetPoint(point.index + 1), newPercent);
                    point.outroEndEasePercentage = curvePercent;
                }

                float percentWidth = (outroEasePointPercent - point.percent);
//                float easeSpace = _cameraPath.pathLength * percentWidth;
//                float easeLength = unitPercent / percentWidth;
                float percentMovement = percentWidth / 10.0f;
                for (float e = point.percent; e < outroEasePointPercent; e += percentMovement)
                {
                    float   eB        = e + percentMovement;
                    Vector3 lineStart = _cameraPath.GetPathPosition(e, true);
                    Vector3 lineEnd   = _cameraPath.GetPathPosition(eB, true);
                    Handles.DrawLine(lineStart, lineEnd);
                    float   animCurvePercentA = (e - point.percent) / percentWidth;
                    float   animCurvePercentB = (eB - point.percent) / percentWidth;
                    Vector3 lineEaseUpA       = easeUp * point.outroCurve.Evaluate(animCurvePercentA);
                    Vector3 lineEaseUpB       = easeUp * point.outroCurve.Evaluate(animCurvePercentB);
                    Handles.DrawLine(lineStart + lineEaseUpA, lineEnd + lineEaseUpB);
                }
            }

            if (point != pointList.introPoint)
            {
                float   introEasePointPercent = _cameraPath.GetIntroEasePercentage(point);
                Vector3 introEasePoint        = _cameraPath.GetPathPosition(introEasePointPercent, true);
                Vector3 introEaseDirection    = _cameraPath.GetPathDirection(introEasePointPercent, false);

                Handles.color = CameraPathColours.RED;
                Handles.Label(introEasePoint, "Ease In\n" + point.displayName);
                Vector3 newPosition = Handles.Slider(introEasePoint, -introEaseDirection);

                float movement = Vector3.Distance(introEasePoint, newPosition);
                if (movement > Mathf.Epsilon)
                {
                    float newPercent   = NearestmMousePercentage();
                    float curvePercent = 1 - _cameraPath.GetCurvePercentage(_cameraPath.delayList.GetPoint(point.index - 1), _cameraPath.delayList.GetPoint(point.index), newPercent);
                    point.introStartEasePercentage = curvePercent;
                }

                float percentWidth = (point.percent - introEasePointPercent);
//                float easeSpace = _cameraPath.pathLength * percentWidth;
//                float easeLength = unitPercent / percentWidth;
                float percentMovement = percentWidth / 10.0f;
                for (float e = introEasePointPercent; e < point.percent; e += percentMovement)
                {
                    float   eB        = e + percentMovement;
                    Vector3 lineStart = _cameraPath.GetPathPosition(e, true);
                    Vector3 lineEnd   = _cameraPath.GetPathPosition(eB, true);
                    Handles.DrawLine(lineStart, lineEnd);
                    float   animCurvePercentA = (e - introEasePointPercent) / percentWidth;
                    float   animCurvePercentB = (eB - introEasePointPercent) / percentWidth;
                    Vector3 lineEaseUpA       = easeUp * point.introCurve.Evaluate(animCurvePercentA);
                    Vector3 lineEaseUpB       = easeUp * point.introCurve.Evaluate(animCurvePercentB);
                    Handles.DrawLine(lineStart + lineEaseUpA, lineEnd + lineEaseUpB);
                }
            }
        }
    }