Example #1
0
    // Use this for initialization
    void Start()
    {
        camPosCursor = transform.Find("BGCurve CamPos").gameObject.GetComponent <BansheeGz.BGSpline.Components.BGCcCursor> ();
        camRotCursor = transform.Find("BGCurve CamRot").gameObject.GetComponent <BansheeGz.BGSpline.Components.BGCcCursor> ();

        img01 = transform.Find("Canvas").Find("Image").GetComponent <Image>();
    }
        //check if delay is over
        private bool CheckIfDelayIsOver(BGCurveBaseMath math, BGCcCursor cursor)
        {
            var pointsCountMinusOne = Curve.PointsCount - 1;

            if (adjustByTotalLength)
            {
                oldLength = math.GetDistance();
            }

            //curve is not closed and delayed at last point
            var delayAtLastPoint = !Curve.Closed && currentSectionIndex == pointsCountMinusOne;

            //curve may be changing, so we need to adjust a position anyway
            cursor.Distance = delayAtLastPoint ? math.GetDistance() : math[currentSectionIndex].DistanceFromStartToOrigin;
            var delayValue = GetDelayAtPoint(currentSectionIndex);

            // we are still delayed
            if (!(Time.time - delayStarted > delayValue))
            {
                return(false);
            }

            var currentSpeed = speed;

            if (speedField != null)
            {
                //we need to retrieve speed from a field value
                currentSpeed = Curve[currentSectionIndex].GetFloat(speedField.FieldName);
            }

            // delay is over, start moving
            delayStarted = -1;
            if (speedWasPositiveWhileDelayed)
            {
                //                if (delayAtLastPoint) cursor.Distance = 0;
                //                else cursor.Distance += BGCurve.Epsilon;
                cursor.Distance += Mathf.Abs(currentSpeed * Time.deltaTime);
            }
            else
            {
                if (currentSectionIndex > 0)
                {
                    currentSectionIndex--;
                    cursor.Distance -= Mathf.Abs(currentSpeed * Time.deltaTime);
                }
                else
                {
                    if (!skipZeroPoint)
                    {
                        currentSectionIndex = pointsCountMinusOne;
                        cursor.Distance     = math.GetDistance() - Mathf.Abs(currentSpeed * Time.deltaTime);
                    }
                }
            }
            return(true);
        }
        //points was passed and we check if delay is required at this point
        private bool CheckDelayAtPoint(BGCurveBaseMath math, BGCcCursor cursor, int pointIndex, bool speedPositive)
        {
            if (IsDelayRequired(pointIndex))
            {
                //we gotta delay at this point
                currentSectionIndex = pointIndex;
                //move cursor straight to the point
                cursor.Distance = Curve.PointsCount - 1 == pointIndex && !Curve.Closed ? math.GetDistance() : math[pointIndex].DistanceFromStartToOrigin;

                // !!!!!!!  start delay
                StartDelay(speedPositive);
                //we does not need to process movement (it will be ignored at any rate, cause we stick to the particular point)
                return(true);
            }
            return(false);
        }