Пример #1
0
    void SetPoints()
    {
        if (pointList.Count == 0)
        {
            Debug.LogError("pointList should never have zero points!");
            return;
        }

        if (pointList.Count == 1)
        {
            lr.positionCount = 2;
            lr.SetPosition(0, pointList.First.Value);
            lr.SetPosition(1, transform.position);
        }

        lr.enabled = pointList.Count > 1;
        if (!lr.enabled)
        {
            return;
        }

        Vector3[] pList = new Vector3[pointList.Count + 1];
        pList [pointList.Count] = transform.position;
        Vector3 prevPos = transform.position;

        LinkedListNode <Vector3> lln = pointList.First;
        int index = 0;

        do
        {
            if (parentObj != null)
            {
                lln.Value += parentObj.transform.forward.normalized * idleSpeed;
            }

            pList [index] = lln.Value;
            prevPos       = lln.Value;
            index++;
            lln = lln.Next;
        } while (lln != null);

        if (splinePrecision <= 1)
        {
            lr.positionCount = pList.Length;
            lr.SetPositions(pList);
        }
        else
        {
            Slonersoft.Spline sp = new Slonersoft.Spline(pList);
            sp.tension = 0.4f;

            int totalPoints = (splinePrecision * pList.Length) + 1;
            lr.positionCount = totalPoints;
            for (int i = 0; i < totalPoints; i++)
            {
                float   t   = (float)i / (float)(totalPoints - 1);
                Vector3 pos = sp.Evaluate(t);
                lr.SetPosition(i, pos);
            }
        }
    }