Пример #1
0
 public void SetInitialLink(scrLightOrb link)
 {
     if (link != null)
     {
         // Link the previous orb to this orb.
         previous  = link;
         link.next = this;
         link.line.SetVertexCount(2);
     }
 }
Пример #2
0
    // ---- scrPoolable ----

    /// <param name="initParams">float x, float z, int seriesIndex, int seriesLength</param>
    public override void Init(params object[] initParams)
    {
        Expired = false;

        float x = (float)initParams[0];
        float z = (float)initParams[1];

        spawnPosition      = new Vector3(x, scrLandscape.Instance.GetHeight(x, z), z);
        transform.position = new Vector3(spawnPosition.x, spawnPosition.y + LEVITATE_HEIGHT + BOB_HEIGHT * Mathf.Sin(spawnPosition.x + spawnPosition.y + Time.time * BOB_RATE), spawnPosition.z);

        seriesIndex  = (int)initParams[2];
        seriesLength = (int)initParams[3];

        next     = null;
        previous = null;

        line.SetVertexCount(0);
    }
    private void GenerateLine(float x, float z, int length, float spacing)
    {
        Vector2 direction = new Vector2(x, z) - scrLandscape.Instance.GetCentre();

        direction.Normalize();

        float bend = Random.Range(-0.2f, 0.2f);          // Amount the direction bends per orb.

        // Make sure it is possible to produce the length of string required.
        if (length > pool.Remaining)
        {
            // There aren't enough orbs available for a string, so cease creation.
            if (pool.Remaining < LENGTH_MIN)
            {
                return;
            }

            length = pool.Remaining;
        }

        Vector2     position = new Vector2(x, z);
        scrLightOrb previous = null;

        for (int i = 0; i < length; ++i)
        {
            // Create an orb.
            scrLightOrb current = (scrLightOrb)pool.Create(position.x, position.y, i, length);

            // Link the orb to the previous orb.
            current.SetInitialLink(previous);

            // Prepare for the next orb.
            previous = current;

            // Move to the next position.
            position += direction * spacing;

            // Bend in the direction perpendicular to the current direction.
            Vector2 perp = new Vector2(-direction.y, direction.x);
            direction += perp * bend;
            direction.Normalize();
        }
    }
Пример #4
0
    protected override void ExpireWhenOutOfBounds()
    {
        // If this orb is not out of bounds, the whole series is not out of bounds.
        if (scrLandscape.Instance.Contains(transform.position))
        {
            return;
        }

        // Move backwards until the first in the series is found.
        scrLightOrb first = this;

        while (first.previous != null)
        {
            first = first.previous;
        }

        // Move forwards until the end of the series.
        scrLightOrb orb = first;

        while (orb != null)
        {
            //  The series is not out of bounds if just one of them is in bounds. Also skip the check for this orb as has already been checked.
            if (orb != this && scrLandscape.Instance.Contains(orb.transform.position))
            {
                return;
            }

            orb = orb.next;
        }

        // The function didn't return early, so the series is fully out of bounds. Deactivate all orbs in the series from the first to the last.
        while (first != null)
        {
            first.Expired = true;
            first         = first.next;
        }
    }