コード例 #1
0
    private float RandomBlossomY(float rand_x)
    {
        Vector2[] spaces = BlossomSpace.GetSpaces(m_enBranchType);
        float     y1     = -99;
        float     y2     = -99;
        float     rand_y = 0;

        for (int i = 0; i < spaces.Length; i++)
        {
            var next_i = i + 1;
            if (next_i == spaces.Length)
            {
                next_i = 0;
            }
            if (spaces[i].x >= rand_x && spaces[next_i].x < rand_x)
            {
                var slope    = (spaces[i].y - spaces[next_i].y) / (spaces[i].x - spaces[next_i].x);
                var constant = spaces[i].y - (spaces[i].x * slope);
                y1 = slope * rand_x + constant;
            }
            if (spaces[i].x <= rand_x && spaces[next_i].x > rand_x)
            {
                var slope    = (spaces[i].y - spaces[next_i].y) / (spaces[i].x - spaces[next_i].x);
                var constant = spaces[i].y - (spaces[i].x * slope);
                y2 = slope * rand_x + constant;
            }
        }

        if (y1 == -99)
        {
            y1 = y2;
        }
        else if (y2 == -99)
        {
            y2 = y1;
        }

        if (y1 > y2)
        {
            rand_y = Random.Range(y1, y2);
        }
        else if (y1 < y2)
        {
            rand_y = Random.Range(y2, y1);
        }
        else if (y1 == y2)
        {
            rand_y = y1;
        }

        return(rand_y);
    }
コード例 #2
0
    private float RandomBlossomX()
    {
        Vector2[] spaces = BlossomSpace.GetSpaces(m_enBranchType);
        var       min_x  = spaces[0].x;
        var       max_x  = spaces[0].x;
        var       x      = spaces[0].x;

        foreach (Vector2 v in spaces)
        {
            x = v.x;
            if (x > max_x)
            {
                max_x = x;
            }
            else if (x < min_x)
            {
                min_x = x;
            }
        }

        float rand = Random.Range((int)(min_x * 10), (int)(max_x * 10));

        return(rand / 10.0f);
    }