예제 #1
0
    void CalculateTotalArea()
    {
        //get total area using trapezoids

        //we'll get it as every 60th of a second, so find how many sections we want
        //closer the sections are, the more accurate we'll have for our time
        float sectionWidth = 1.0f / 60.0f;

        float endTime = m_spawnRateCurve.GetLastKeyTime();

        m_totalArea = m_spawnRateCurve.GetAreaUnderCurve(0, endTime, sectionWidth, m_timeSpan);
    }
예제 #2
0
    //gets the size of the area by splitting the curve into segments
    public static float GetAreaUnderCurve(this AnimationCurve animCurve, float startPoint, float endPoint, float segmentSize, float timeScale)
    {
        int numSections = Mathf.CeilToInt((endPoint - startPoint) / segmentSize);

        float section1 = startPoint;
        float section2 = Mathf.Min(segmentSize, endPoint);

        float area = 0;

        while (section1 < section2)
        {
            area += animCurve.GetAreaUnderCurve(section1, section2);

            section1  = section2;
            section2 += segmentSize / timeScale;

            section2 = Mathf.Clamp(section2, 0, endPoint);
        }

        return(area);
    }