예제 #1
0
    // Use this for initialization
    void Start()
    {
        BGCcCursorChangeLinear linear = trackLine.GetComponent <BGCcCursorChangeLinear>();
        BGCcCursor             cursor = trackLine.GetComponent <BGCcCursor>();

        linear.Speed = speed;
    }
예제 #2
0
        //Add field with values
        private static BGCurvePointField NewFloatField(BGCcCursorChangeLinear changeCursor, string fieldName, params float[] values)
        {
            var curve = changeCursor.Curve;
            var field = curve.AddField(fieldName, BGCurvePointField.TypeEnum.Float);

            for (var i = 0; i < values.Length; i++)
            {
                curve[i].SetFloat(fieldName, values[i]);
            }
            return(field);
        }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        curve        = GetComponent <BGCurve>();
        math         = GetComponent <BGCcMath>();
        cursor       = GetComponent <BGCcCursor>();
        cursorLinear = GetComponent <BGCcCursorChangeLinear>();

        //startingspeed = objectPrefab.GetComponent<XXXXXX>().speed;

        currentSpeed       = startingSpeed;
        speedBeforeStopped = startingSpeed;
        cursorLinear.Speed = startingSpeed;

        //distance = math.Math[pointListIndex].DistanceFromStartToOrigin;
        distance = math.Math.GetDistance(pointIndex);

        //Instantiate the object
        objectToMove = Instantiate(objectPrefab, curve[0].PositionWorld, Quaternion.Euler(0, 0, 0));

        //Sets the object so that the path moves the object
        GetComponent <BGCcCursorObjectTranslate>().ObjectToManipulate = objectToMove.transform;


        //Sets the overflow to the right one in BGCCursorChangeLinear
        switch (overflowType)
        {
        case OverflowType.Stop:
            cursorLinear.OverflowControl = BGCcCursorChangeLinear.OverflowControlEnum.Stop;
            break;

        case OverflowType.Cycle:
            cursorLinear.OverflowControl = BGCcCursorChangeLinear.OverflowControlEnum.Cycle;
            break;

        case OverflowType.PingPong:
            cursorLinear.OverflowControl = BGCcCursorChangeLinear.OverflowControlEnum.PingPong;
            break;
        }
    }
 private void Register(BGCcCursorChangeLinear curve)
 {
     sequences.Add(new Sequence(curve));
 }
            public Sequence(BGCcCursorChangeLinear changeCursor)
            {
                this.changeCursor = changeCursor;
                var cursor = changeCursor.Cursor;
                var curve  = changeCursor.Curve;

                Curve   = curve;
                started = Time.time;


                if (!Curve.gameObject.activeInHierarchy)
                {
                    return;
                }

                ThrowIf("Stop overflow control is not supported", changeCursor.OverflowControl == BGCcCursorChangeLinear.OverflowControlEnum.Stop);


                var pointsCount = curve.PointsCount;

                ThrowIf("Curve should have at least 2 points.", pointsCount < 2);

                var math = changeCursor.Cursor.Math.Math;

                var sectionIndex  = cursor.CalculateSectionIndex();
                var speed         = changeCursor.CurrentSpeed;
                var speedPositive = speed > 0;

                if (speedPositive)
                {
                    //=================================== Positive speed
                    //first point
                    if (curve.Closed && sectionIndex == pointsCount - 1)
                    {
                        expectedPoints.Add(new ExpectedPoint(0, math.GetDistance() - cursor.Distance, speed, 0));
                    }
                    else if (!curve.Closed && sectionIndex == pointsCount - 2)
                    {
                        expectedPoints.Add(new ExpectedPoint(pointsCount - 1, math.GetDistance() - cursor.Distance, speed, 0));
                    }
                    else
                    {
                        expectedPoints.Add(new ExpectedPoint(sectionIndex + 1, math[sectionIndex + 1].DistanceFromStartToOrigin - cursor.Distance, speed, 0));
                    }

                    //go towards end
                    for (var i = sectionIndex + 2; i < pointsCount; i++)
                    {
                        expectedPoints.Add(new ExpectedPoint(i, math[i - 1].Distance, changeCursor.GetSpeedAtPoint(i - 1), changeCursor.GetDelayAtPoint(i - 1)));
                    }

                    //add last point
                    if (curve.Closed && sectionIndex != pointsCount)
                    {
                        expectedPoints.Add(new ExpectedPoint(0, math[pointsCount - 1].Distance, changeCursor.GetSpeedAtPoint(pointsCount - 1), changeCursor.GetDelayAtPoint(pointsCount - 1)));
                    }


                    if (changeCursor.OverflowControl == BGCcCursorChangeLinear.OverflowControlEnum.PingPong)
                    {
                        if (curve.Closed)
                        {
                            expectedPoints.Add(new ExpectedPoint(pointsCount - 1, math[pointsCount - 1].Distance,
                                                                 changeCursor.GetSpeedAtPoint(pointsCount - 1), changeCursor.GetDelayAtPoint(0)));
                        }

                        //go all the way down
                        for (var i = pointsCount - 2; i >= 0; i--)
                        {
                            expectedPoints.Add(new ExpectedPoint(i, math[i].Distance, changeCursor.GetSpeedAtPoint(i), changeCursor.GetDelayAtPoint(i + 1)));
                        }
                    }
                    else
                    {
                        if (!curve.Closed)
                        {
                            expectedPoints.Add(new ExpectedPoint(0, math[pointsCount - 2].Distance, 0, changeCursor.GetDelayAtPoint(pointsCount - 1)));
                        }
                    }

                    //go up to initial position
                    for (var i = 1; i <= sectionIndex; i++)
                    {
                        expectedPoints.Add(new ExpectedPoint(i, math[i - 1].Distance, changeCursor.GetSpeedAtPoint(i - 1), changeCursor.GetDelayAtPoint(i - 1)));
                    }

                    //last point
                    expectedPoints.Add(new ExpectedPoint(-1, cursor.Distance - math[sectionIndex].DistanceFromStartToOrigin, speed, changeCursor.GetDelayAtPoint(sectionIndex)));
                }
                else
                {
                    //=================================== Negative speed
                    //first point
                    expectedPoints.Add(new ExpectedPoint(sectionIndex, cursor.Distance - math[sectionIndex].DistanceFromStartToOrigin, speed, 0));

                    //go towards start
                    for (var i = sectionIndex - 1; i >= 0; i--)
                    {
                        expectedPoints.Add(new ExpectedPoint(i, math[i].Distance, changeCursor.GetSpeedAtPoint(i), changeCursor.GetDelayAtPoint(i + 1)));
                    }

                    if (changeCursor.OverflowControl == BGCcCursorChangeLinear.OverflowControlEnum.PingPong)
                    {
                        for (var i = 1; i < pointsCount; i++)
                        {
                            expectedPoints.Add(new ExpectedPoint(i, math[i - 1].Distance, changeCursor.GetSpeedAtPoint(i - 1), changeCursor.GetDelayAtPoint(i - 1)));
                        }

                        if (curve.Closed)
                        {
                            expectedPoints.Add(new ExpectedPoint(0, math[pointsCount - 1].Distance, changeCursor.GetSpeedAtPoint(pointsCount - 1), changeCursor.GetDelayAtPoint(pointsCount - 1)));
                            expectedPoints.Add(new ExpectedPoint(pointsCount - 1, math[pointsCount - 1].Distance,
                                                                 changeCursor.GetSpeedAtPoint(pointsCount - 1), changeCursor.GetDelayAtPoint(0)));
                        }
                    }
                    else
                    {
                        if (curve.Closed)
                        {
                            expectedPoints.Add(new ExpectedPoint(pointsCount - 1, math[pointsCount - 1].Distance,
                                                                 changeCursor.GetSpeedAtPoint(pointsCount - 1), changeCursor.GetDelayAtPoint(0)));
                        }
                        else
                        {
                            expectedPoints.Add(new ExpectedPoint(pointsCount - 1, 0, 0, changeCursor.GetDelayAtPoint(0)));
                        }
                    }


                    //go from end to initial section
                    for (var i = pointsCount - 2; i > sectionIndex; i--)
                    {
                        expectedPoints.Add(new ExpectedPoint(i, math[i].Distance, changeCursor.GetSpeedAtPoint(i), changeCursor.GetDelayAtPoint(i + 1)));
                    }

                    //last point
                    expectedPoints.Add(new ExpectedPoint(-1, math[sectionIndex].DistanceFromEndToOrigin - cursor.Distance, changeCursor.GetSpeedAtPoint(sectionIndex),
                                                         changeCursor.GetDelayAtPoint(sectionIndex + 1)));
                }
            }
예제 #6
0
 private void Awake()
 {
     m_Animate   = transform.parent?.GetComponent <BGCcCursorChangeLinear>();
     m_Rotate    = transform.parent?.GetComponent <BGCcCursorObjectRotate>();
     m_Translate = transform.parent?.GetComponent <BGCcCursorObjectTranslate>();
 }