protected void CalculateAndSetColors()
    {
        int tempCount = count;

        for (int i = 0; tempCount > 0; ++i, tempCount -= 1023)
        {
            int startIndex = i * 1023;
            for (int j = 0; j < Mathf.Min(tempCount, 1023); ++j)
            {
                colors [i][j] = ColorManipulation.LerpColorsCorrected(StartColor, EndColor, (float)(startIndex + j) / (float)count);
            }
            propBlocks[i].Clear();
            propBlocks[i].SetVectorArray("_Color", colors[i]);
        }
    }
    public void UpdatePositions(Transform baseTransform, Vector3 startPosition, Vector3 endPosition)
    {
        if (Vector3.Magnitude(previousEnd - endPosition) < 0.0001f)
        {
            return;
        }
        previousEnd = endPosition;

        Vector3 direction = (endPosition - startPosition).normalized;
        float   distance  = Vector3.Magnitude(endPosition - startPosition);

        count = Mathf.FloorToInt((distance - MarginToLast) / DistanceBetweenDraws);

        if (count <= 0)
        {
            return;
        }

        AllocateInstanceMemory(count);          //Could possibly reuse a single list as memory, since we're setting it every frame. But RewindDrawer keeps them, so easier this way.

        //Why is copying transforms such a bitch
        tempObject.transform.position   = baseTransform.position;
        tempObject.transform.rotation   = baseTransform.rotation;
        tempObject.transform.localScale = baseTransform.localScale;
        Transform tempTransform = tempObject.transform;

        tempTransform.position = startPosition;

        int tempCount = count;

        for (int i = 0; tempCount > 0; ++i, tempCount -= 1023)
        {
            for (int j = 0; j < Mathf.Min(tempCount, 1023); ++j)
            {
                tempTransform.position += direction * DistanceBetweenDraws;
                positions [i][j]        = tempTransform.localToWorldMatrix;
                colors [i][j]           = ColorManipulation.LerpColorsCorrected(StartColor, EndColor, (float)(i * 1023 + j) / (float)count);
            }
        }

        CalculateAndSetColors();
    }
Beispiel #3
0
    void Update()
    {
        if (updated)
        {
            renderer.material.SetColor("_Color", ColorManipulation.LerpColorsCorrected(color1, color2, ratio));
            updated = false;
        }

        transform.position = papaTransform.position;

        if (timePassed >= timeLimit)
        {
            timePassed = 0;
            timeLimit  = Random.Range(0, 3);
            rb.AddRelativeTorque(Random.insideUnitSphere * Random.Range(10, 200));
        }
        else
        {
            timePassed += Time.deltaTime;
        }
    }