Exemplo n.º 1
0
    /// <summary>
    /// Gets proper next folder's position. Used to spawn folders in available positions.
    /// </summary>
    /// <returns>KeyValuePair of vertices used to calculate spawn position and spawn position.</returns>
    /// <param name="currentVertexFollowed">Current vertex followed.</param>
    public KeyValuePair <VertexController[], Vector2> GetNextFolderPosition(VertexController currentVertexFollowed)
    {
        int currentVertexIndex          = currentVertexFollowed.transform.GetSiblingIndex();
        int nextVertexIndex             = (currentVertexIndex + 1) % this.transform.childCount;
        VertexController nextVertex     = this.transform.GetChild(nextVertexIndex).GetComponent <VertexController>();
        int nextNextVertexIndex         = (currentVertexIndex + 2) % this.transform.childCount;
        VertexController nextNextVertex = this.transform.GetChild(nextNextVertexIndex).GetComponent <VertexController>();

        float   availableSpaceScale   = 0.5f;
        Vector2 availableSpaceVertex1 = currentVertexFollowed.transform.position + (nextVertex.transform.position - currentVertexFollowed.transform.position) * (1f - availableSpaceScale) / 3f;

        availableSpaceVertex1 += (Vector2)(nextNextVertex.transform.position - currentVertexFollowed.transform.position) * (1f - availableSpaceScale) / 3f;

        Vector2 availableSpaceVertex2 = nextVertex.transform.position + (currentVertexFollowed.transform.position - nextVertex.transform.position) * (1f - availableSpaceScale) / 3f;

        availableSpaceVertex2 += (Vector2)(nextNextVertex.transform.position - nextVertex.transform.position) * (1f - availableSpaceScale) / 3f;

        Vector2 availableSpaceVertex3 = nextNextVertex.transform.position + (currentVertexFollowed.transform.position - nextNextVertex.transform.position) * (1f - availableSpaceScale) / 3f;

        availableSpaceVertex3 += (Vector2)(nextVertex.transform.position - nextNextVertex.transform.position) * (1f - availableSpaceScale) / 3f;

        // Debug lines drawing, uncomment to debug this method
        //Debug.DrawLine(availableSpaceVertex1, availableSpaceVertex2, Color.white, 3f);
        //Debug.DrawLine(availableSpaceVertex2, availableSpaceVertex3, Color.white, 3f);
        //Debug.DrawLine(availableSpaceVertex3, availableSpaceVertex1, Color.white, 3f);

        VertexController[] returnList = { currentVertexFollowed, nextVertex, nextNextVertex };

        return(new KeyValuePair <VertexController[], Vector2>(returnList, Math3d.GetRandomPointInsideTriangle(availableSpaceVertex1, availableSpaceVertex2, availableSpaceVertex3)));
    }