コード例 #1
0
    public float GetSpeed(float percentage)
    {
        if (realNumberOfPoints < 2)
        {
            if (realNumberOfPoints == 1)
            {
                return((this[0]).speed);
            }
            Debug.Log("Not enough points to define a speed");
            return(0);
        }

        if (percentage >= 1)
        {
            return(((CameraPathSpeed)GetPoint(realNumberOfPoints - 1)).speed);
        }

        percentage = Mathf.Clamp(percentage, 0.0f, 0.999f);

        switch (interpolation)
        {
        case Interpolation.SmoothStep:
            return(SmoothStepInterpolation(percentage));

        case Interpolation.Linear:
            return(LinearInterpolation(percentage));

        case Interpolation.None:
            CameraPathSpeed point = (CameraPathSpeed)GetPoint(GetNextPointIndex(percentage));
            return(point.speed);

        default:
            return(LinearInterpolation(percentage));
        }
    }
コード例 #2
0
    private float SmoothStepInterpolation(float percentage)
    {
        int             index  = GetLastPointIndex(percentage);
        CameraPathSpeed pointP = (CameraPathSpeed)GetPoint(index);
        CameraPathSpeed pointQ = (CameraPathSpeed)GetPoint(index + 1);

        if (percentage < pointP.percent)
        {
            return(pointP.speed);
        }
        if (percentage > pointQ.percent)
        {
            return(pointQ.speed);
        }

        float startPercentage = pointP.percent;
        float endPercentage   = pointQ.percent;

        if (startPercentage > endPercentage)
        {
            endPercentage += 1;
        }

        float curveLength     = endPercentage - startPercentage;
        float curvePercentage = percentage - startPercentage;
        float ct = curvePercentage / curveLength;

        return(Mathf.Lerp(pointP.speed, pointQ.speed, CPMath.SmoothStep(ct)));
    }
コード例 #3
0
    public override void FromXML(XmlNodeList nodes)
    {
        Clear();
        foreach (XmlNode node in nodes)
        {
            CameraPathSpeed newCameraPathPoint = gameObject.AddComponent <CameraPathSpeed>();//CreateInstance<CameraPathSpeed>();
            newCameraPathPoint.hideFlags = HideFlags.HideInInspector;
            CameraPathPoint.PositionModes positionModes = (CameraPathPoint.PositionModes)Enum.Parse(typeof(CameraPathPoint.PositionModes), node["positionModes"].FirstChild.Value);
            switch (positionModes)
            {
            case CameraPathPoint.PositionModes.Free:
                CameraPathControlPoint cPointA = cameraPath[int.Parse(node["cpointA"].FirstChild.Value)];
                CameraPathControlPoint cPointB = cameraPath[int.Parse(node["cpointB"].FirstChild.Value)];
                float curvePercentage          = float.Parse(node["curvePercentage"].FirstChild.Value);
                AddPoint(newCameraPathPoint, cPointA, cPointB, curvePercentage);
                break;

            case CameraPathPoint.PositionModes.FixedToPoint:
                CameraPathControlPoint point = cameraPath[int.Parse(node["point"].FirstChild.Value)];
                AddPoint(newCameraPathPoint, point);
                break;
            }
            newCameraPathPoint.FromXML(node, cameraPath);
        }
    }
コード例 #4
0
    private float SmoothStepInterpolation(float percentage)
    {
        int             lastPointIndex   = base.GetLastPointIndex(percentage);
        CameraPathSpeed cameraPathSpeed  = (CameraPathSpeed)base.GetPoint(lastPointIndex);
        CameraPathSpeed cameraPathSpeed2 = (CameraPathSpeed)base.GetPoint(lastPointIndex + 1);

        if (percentage < cameraPathSpeed.percent)
        {
            return(cameraPathSpeed.speed);
        }
        if (percentage > cameraPathSpeed2.percent)
        {
            return(cameraPathSpeed2.speed);
        }
        float percent = cameraPathSpeed.percent;
        float num     = cameraPathSpeed2.percent;

        if (percent > num)
        {
            num += 1f;
        }
        float num2 = num - percent;
        float num3 = percentage - percent;
        float val  = num3 / num2;

        return(Mathf.Lerp(cameraPathSpeed.speed, cameraPathSpeed2.speed, CPMath.SmoothStep(val)));
    }
コード例 #5
0
    private float LinearInterpolation(float percentage)
    {
        int             index  = GetLastPointIndex(percentage);
        CameraPathSpeed pointP = (CameraPathSpeed)GetPoint(index);
        CameraPathSpeed pointQ = (CameraPathSpeed)GetPoint(index + 1);

        if (percentage < pointP.percent)
        {
            return(pointP.speed);
        }
        if (percentage > pointQ.percent)
        {
            return(pointQ.speed);
        }

        float startPercentage = pointP.rawPercent;
        float endPercentage   = pointQ.rawPercent;

        if (startPercentage > endPercentage)
        {
            endPercentage += 1;
        }

        float curveLength     = endPercentage - startPercentage;
        float curvePercentage = percentage - startPercentage;
        float ct = curvePercentage / curveLength;

        Debug.Log(percentage + " " + curveLength + " " + curvePercentage + " " + ct);
        float output = Mathf.Lerp(pointP.speed, pointQ.speed, ct);

//        Debug.Log(output);
        return(output);
    }
コード例 #6
0
    //public override void FromXML(XmlNodeList nodes)
    //{
    //    Clear();
    //    foreach (XmlNode node in nodes)
    //    {
    //        CameraPathSpeed newCameraPathPoint = gameObject.AddComponent<CameraPathSpeed>();//CreateInstance<CameraPathSpeed>();
    //        newCameraPathPoint.hideFlags = HideFlags.HideInInspector;
    //        CameraPathPoint.PositionModes positionModes = (CameraPathPoint.PositionModes)Enum.Parse(typeof(CameraPathPoint.PositionModes), node["positionModes"].FirstChild.Value);
    //        switch (positionModes)
    //        {
    //            case CameraPathPoint.PositionModes.Free:
    //                CameraPathControlPoint cPointA = cameraPath[int.Parse(node["cpointA"].FirstChild.Value)];
    //                CameraPathControlPoint cPointB = cameraPath[int.Parse(node["cpointB"].FirstChild.Value)];
    //                float curvePercentage = float.Parse(node["curvePercentage"].FirstChild.Value);
    //                AddPoint(newCameraPathPoint, cPointA, cPointB, curvePercentage);
    //                break;

    //            case CameraPathPoint.PositionModes.FixedToPoint:
    //                CameraPathControlPoint point = cameraPath[int.Parse(node["point"].FirstChild.Value)];
    //                AddPoint(newCameraPathPoint, point);
    //                break;
    //        }
    //        newCameraPathPoint.FromXML(node, cameraPath);
    //    }
    //}

    public override void FromXML(XMLNodeList nodes)
    {
        if (nodes == null)
        {
            Debug.Log("not speed node");
            return;
        }
        Clear();
        foreach (XMLNode node in nodes)
        {
            CameraPathSpeed newCameraPathPoint = gameObject.AddComponent <CameraPathSpeed>();//CreateInstance<CameraPathSpeed>();
            newCameraPathPoint.hideFlags = HideFlags.HideInInspector;
            CameraPathPoint.PositionModes positionModes = (CameraPathPoint.PositionModes)Enum.Parse(typeof(CameraPathPoint.PositionModes), node.GetValue("positionModes>0>_text"));
            switch (positionModes)
            {
            case CameraPathPoint.PositionModes.Free:
                CameraPathControlPoint cPointA = cameraPath[int.Parse(node.GetValue("cpointA>0>_text"))];
                CameraPathControlPoint cPointB = cameraPath[int.Parse(node.GetValue("cpointB>0>_text"))];
                float curvePercentage          = float.Parse(node.GetValue("curvePercentage>0>_text"));
                AddPoint(newCameraPathPoint, cPointA, cPointB, curvePercentage);
                break;

            case CameraPathPoint.PositionModes.FixedToPoint:
                CameraPathControlPoint point = cameraPath[int.Parse(node.GetValue("point>0>_text"))];
                AddPoint(newCameraPathPoint, point);
                break;
            }
            newCameraPathPoint.FromXML(node, cameraPath);
        }
    }
コード例 #7
0
    public void AddSpeedPoint(CameraPathControlPoint atPoint)
    {
        CameraPathSpeed point = gameObject.AddComponent <CameraPathSpeed>();//CreateInstance<CameraPathSpeed>();

        point.hideFlags = HideFlags.HideInInspector;
        AddPoint(point, atPoint);
        RecalculatePoints();
    }
コード例 #8
0
    public void AddSpeedPoint(CameraPathControlPoint atPoint)
    {
        CameraPathSpeed cameraPathSpeed = base.get_gameObject().AddComponent <CameraPathSpeed>();

        cameraPathSpeed.set_hideFlags(2);
        base.AddPoint(cameraPathSpeed, atPoint);
        this.RecalculatePoints();
    }
コード例 #9
0
    public CameraPathSpeed AddSpeedPoint(CameraPathControlPoint curvePointA, CameraPathControlPoint curvePointB, float curvePercetage)
    {
        CameraPathSpeed point = gameObject.AddComponent <CameraPathSpeed>();//CreateInstance<CameraPathSpeed>();

        point.hideFlags = HideFlags.HideInInspector;
        AddPoint(point, curvePointA, curvePointB, Mathf.Clamp01(curvePercetage));
        RecalculatePoints();
        return(point);
    }
コード例 #10
0
    public CameraPathSpeed AddSpeedPoint(CameraPathControlPoint curvePointA, CameraPathControlPoint curvePointB, float curvePercetage)
    {
        CameraPathSpeed cameraPathSpeed = base.get_gameObject().AddComponent <CameraPathSpeed>();

        cameraPathSpeed.set_hideFlags(2);
        base.AddPoint(cameraPathSpeed, curvePointA, curvePointB, Mathf.Clamp01(curvePercetage));
        this.RecalculatePoints();
        return(cameraPathSpeed);
    }
コード例 #11
0
    private static void SceneGUISpeedBased()
    {
        DisplayAtPoint();

        CameraPathSpeedList pointList = _cameraPath.speedList;
        Camera sceneCamera            = Camera.current;
        int    pointCount             = pointList.realNumberOfPoints;

        for (int i = 0; i < pointCount; i++)
        {
            CameraPathSpeed point = pointList[i];
            if (_cameraPath.enableUndo)
            {
                Undo.RecordObject(point, "Modifying Speed Point");
            }
            if (Vector3.Dot(sceneCamera.transform.forward, point.worldPosition - sceneCamera.transform.position) < 0)
            {
                continue;
            }

            string pointLabel = point.displayName;
            pointLabel += "\nvalue: " + point.speed + " m/s";
            pointLabel += "\npercent: " + point.percent;
            pointLabel += "\na percent: " + _cameraPath.DeNormalisePercentage(point.percent);

            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;
            }

            if (i == selectedPointIndex)
            {
                CPPSlider(point);
            }
        }
    }
コード例 #12
0
    public float GetSpeed(float percentage)
    {
        if (base.realNumberOfPoints < 2)
        {
            if (base.realNumberOfPoints == 1)
            {
                return(this[0].speed);
            }
            Debug.Log("Not enough points to define a speed");
            return(0f);
        }
        else
        {
            if (percentage >= 1f)
            {
                return(((CameraPathSpeed)base.GetPoint(base.realNumberOfPoints - 1)).speed);
            }
            percentage = Mathf.Clamp(percentage, 0f, 0.999f);
            switch (this.interpolation)
            {
            case CameraPathSpeedList.Interpolation.None:
            {
                CameraPathSpeed cameraPathSpeed = (CameraPathSpeed)base.GetPoint(base.GetNextPointIndex(percentage));
                return(cameraPathSpeed.speed);
            }

            case CameraPathSpeedList.Interpolation.Linear:
                return(this.LinearInterpolation(percentage));

            case CameraPathSpeedList.Interpolation.SmoothStep:
                return(this.SmoothStepInterpolation(percentage));

            default:
                return(this.LinearInterpolation(percentage));
            }
        }
    }
コード例 #13
0
    private static void AddCPathPoints()
    {
        if (SceneView.focusedWindow != null)
        {
            SceneView.focusedWindow.wantsMouseMove = true;
        }

        Handles.color = _cameraPath.selectedPointColour;
        CameraPathPointList pointList = null;

        switch (_pointMode)
        {
        case CameraPath.PointModes.AddOrientations:
            pointList = _cameraPath.orientationList;
            break;

        case CameraPath.PointModes.AddFovs:
            pointList = _cameraPath.fovList;
            break;

        case CameraPath.PointModes.AddTilts:
            pointList = _cameraPath.tiltList;
            break;

        case CameraPath.PointModes.AddEvents:
            pointList = _cameraPath.eventList;
            break;

        case CameraPath.PointModes.AddSpeeds:
            pointList = _cameraPath.speedList;
            break;

        case CameraPath.PointModes.AddDelays:
            pointList = _cameraPath.delayList;
            break;
        }
        int numberOfPoints = pointList.realNumberOfPoints;

        for (int i = 0; i < numberOfPoints; i++)
        {
            CameraPathPoint point           = pointList[i];
            float           pointHandleSize = HandleUtility.GetHandleSize(point.worldPosition) * HANDLE_SCALE * 0.4f;
            Handles.DotCap(0, point.worldPosition, Quaternion.identity, pointHandleSize);
        }

        float   mousePercentage = NearestmMousePercentage();// _track.GetNearestPoint(mousePlanePoint);
        Vector3 mouseTrackPoint = _cameraPath.GetPathPosition(mousePercentage, true);

        Handles.Label(mouseTrackPoint, "Add New Point");
        float      newPointHandleSize = HandleUtility.GetHandleSize(mouseTrackPoint) * HANDLE_SCALE;
        Ray        mouseRay           = Camera.current.ScreenPointToRay(new Vector3(Event.current.mousePosition.x, Screen.height - Event.current.mousePosition.y - 30, 0));
        Quaternion mouseLookDirection = Quaternion.LookRotation(-mouseRay.direction);

        if (Handles.Button(mouseTrackPoint, mouseLookDirection, newPointHandleSize, newPointHandleSize, Handles.DotCap))
        {
            CameraPathControlPoint curvePointA = _cameraPath[_cameraPath.GetLastPointIndex(mousePercentage, false)];
            CameraPathControlPoint curvePointB = _cameraPath[_cameraPath.GetNextPointIndex(mousePercentage, false)];
            float curvePercentage = _cameraPath.GetCurvePercentage(curvePointA, curvePointB, mousePercentage);
            switch (_pointMode)
            {
            case CameraPath.PointModes.AddOrientations:
                Quaternion            pointRotation  = Quaternion.LookRotation(_cameraPath.GetPathDirection(mousePercentage));
                CameraPathOrientation newOrientation = ((CameraPathOrientationList)pointList).AddOrientation(curvePointA, curvePointB, curvePercentage, pointRotation);
                ChangeSelectedPointIndex(pointList.IndexOf(newOrientation));
                break;

            case CameraPath.PointModes.AddFovs:
                float         pointFOV    = _cameraPath.fovList.GetValue(mousePercentage, CameraPathFOVList.ProjectionType.FOV);
                float         pointSize   = _cameraPath.fovList.GetValue(mousePercentage, CameraPathFOVList.ProjectionType.Orthographic);
                CameraPathFOV newFOVPoint = ((CameraPathFOVList)pointList).AddFOV(curvePointA, curvePointB, curvePercentage, pointFOV, pointSize);
                ChangeSelectedPointIndex(pointList.IndexOf(newFOVPoint));
                break;

            case CameraPath.PointModes.AddTilts:
                float          pointTilt    = _cameraPath.GetPathTilt(mousePercentage);
                CameraPathTilt newTiltPoint = ((CameraPathTiltList)pointList).AddTilt(curvePointA, curvePointB, curvePercentage, pointTilt);
                ChangeSelectedPointIndex(pointList.IndexOf(newTiltPoint));
                break;

            case CameraPath.PointModes.AddEvents:
                CameraPathEvent newEventPoint = ((CameraPathEventList)pointList).AddEvent(curvePointA, curvePointB, curvePercentage);
                ChangeSelectedPointIndex(pointList.IndexOf(newEventPoint));
                break;

            case CameraPath.PointModes.AddSpeeds:
                _cameraPath.speedList.listEnabled = true;    //if we're adding speeds then we probable want to enable it
                CameraPathSpeed newSpeedPoint = ((CameraPathSpeedList)pointList).AddSpeedPoint(curvePointA, curvePointB, curvePercentage);
                newSpeedPoint.speed = _animator.pathSpeed;
                ChangeSelectedPointIndex(pointList.IndexOf(newSpeedPoint));
                break;

            case CameraPath.PointModes.AddDelays:
                CameraPathDelay newDelayPoint = ((CameraPathDelayList)pointList).AddDelayPoint(curvePointA, curvePointB, curvePercentage);
                ChangeSelectedPointIndex(pointList.IndexOf(newDelayPoint));
                break;
            }
            GUI.changed = true;
        }
    }
コード例 #14
0
ファイル: LuaPathCamera.cs プロジェクト: cedar-x/unilua_story
 //lsy add
 public void spdNeeds(CameraPathSpeed speed, int index, float percent, float curvePercentage, int mySpeed)
 {
     //Debug.Log("-----------spdNeeds--------------");
     speed.index = index;
     speed.percent = percent;
     speed.curvePercentage = curvePercentage;
     speed.speed = mySpeed;
 }