private void ShowDirections()
    {
        Handles.color = Color.green;
        Vector3 point = spline.GetPoint(0f);

        Handles.DrawLine(point, point + spline.GetDirection(0f) * directionScale);
        int steps = stepsPerCurve * spline.CurveCount;

        for (int i = 1; i <= steps; i++)
        {
            point = spline.GetPoint(i / (float)steps);
            Handles.DrawLine(point, point + spline.GetDirection(i / (float)steps) * directionScale);
        }
    }
    private void Awake()
    {
        if (frequency <= 0 || items == null || items.Length == 0)
        {
            return;
        }
        float stepSize = frequency * items.Length;

        if (spline.Loop || stepSize == 1)
        {
            stepSize = 1f / stepSize;
        }
        else
        {
            stepSize = 1f / (stepSize - 1);
        }
        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (int i = 0; i < items.Length; i++, p++)
            {
                Transform item     = Instantiate(items[i]) as Transform;
                Vector3   position = spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (lookForward)
                {
                    item.transform.LookAt(position + spline.GetDirection(p * stepSize));
                }
                item.transform.parent = transform;
            }
        }
    }
Exemplo n.º 3
0
    private void ChangeGlobalTime()
    {
        TransferTrajectoryData prevPoint;
        TransferTrajectoryData nextPoint;
        int index;

        FindCurrentPositions(out prevPoint, out nextPoint, out index);
        if (nextPoint == null)
        {
            transform.localPosition = prevPoint.Position;
        }
        else
        {
            float oneTimeSize    = 1f / (Positions.Count - 1);
            float localLerpTime  = (float)((GlobalTime - prevPoint.UTCTime) / (nextPoint.UTCTime - prevPoint.UTCTime));
            float currntTimeLine = Mathf.Lerp(index * oneTimeSize, (index + 1) * oneTimeSize, localLerpTime);
            //float currntTimeLine = Mathf.InverseLerp(nextPoint.UTCTime, prevPoint.UTCTime, GlobalTime); // currentLocalTime / toDestinationLocalTime;
            transform.localPosition = BezierSpline.GetPoint(currntTimeLine);///SpaceTimeParrametrs.Scale;
            transform.LookAt(transform.localPosition + BezierSpline.GetDirection(currntTimeLine));
        }
        if (TrajectoryRenderer != null)
        {
            Vector3[] positions = new Vector3[index + 1];
            for (int i = 0; i < positions.Length; i++)
            {
                positions[i] = Positions[i].Position;
            }
            positions[positions.Length - 1]  = transform.localPosition;
            TrajectoryRenderer.positionCount = positions.Length;
            TrajectoryRenderer.SetPositions(positions);
        }
    }
    public void SetPossition(float progress)
    {
        Vector3 position = spline.GetPoint(progress);

        transform.localPosition = position;
        if (lookForward)
        {
            transform.LookAt(position + spline.GetDirection(progress));
        }
    }