示例#1
0
    public bool orientAndPlace(int xTL, int yTL, float height, GameObjectData[,] placements, bool[,,] rules, int index, int width, System.Random rand, GameObjectData nonce)
    {
        //oversight assumes left to right up to down placement
        int minX = Mathf.Min(placementRadius * maxScaling, placements.GetLength(1) - xTL);

        for (int i = 1; i <= minX; i++)
        {
            if (placements[i + xTL, yTL] != null)
            {
                minX = i;
            }
        }

        float minScale = placementRadius == 0 ? 1000000 : Mathf.Min((float)minX / placementRadius, (float)(placements.GetLength(0) - yTL) / placementRadius);

        if (minScale < minScaling)
        {
            placements[xTL, yTL] = nonce;

            return(false);
        }


        float scale = BiomeData.Range(rand, minScaling, Mathf.Min(minScale, maxScaling));

        Vector3 position = new Vector3(((float)(xTL + placementRadius / 2)), height - 1, ((float)(yTL + placementRadius / 2)));
        Vector3 scaling  = new Vector3(scale, scale, scale);

        for (int i = xTL; i <= placementRadius; i++)
        {
            for (int j = xTL; j <= placementRadius; j++)
            {
                placements[i, j] = nonce;
            }
        }

        for (int i = Mathf.Max(xTL - width, 0); i < Mathf.Min(xTL + placementRadius * scale + width, placements.GetLength(0)); i++)
        {
            for (int j = Mathf.Max(yTL - width, 0); j < Mathf.Min(yTL + placementRadius * scale + width, placements.GetLength(0)); j++)
            {
                rules[i, j, index] = false;
            }
        }
        float angle = BiomeData.Range(rand, 0, 360f);

        placements[xTL, yTL]           = new GameObjectData();
        placements[xTL, yTL].rotation  = Quaternion.AngleAxis(angle, Vector3.up);
        placements[xTL, yTL].gamePiece = prefab;
        placements[xTL, yTL].placeable = true;
        placements[xTL, yTL].position  = position;
        placements[xTL, yTL].scale     = scaling;

        return(true);
    }