コード例 #1
0
    // Use this for initialization
    void Start()
    {
        instance = this;

        basementHeight = 1.5f - floorHeight / 2;
        float elementHeight;


        gridElements   = new gridElement[width * width * height];
        cornerElements = new cornerElement[(width + 1) * (width + 1) * (height + 1)];

        for (int y = 0; y < height + 1; y++)
        {
            for (int x = 0; x < width + 1; x++)
            {
                for (int z = 0; z < width + 1; z++)
                {
                    cornerElement cornerElementInstance = Instantiate(cornerElement, Vector3.zero, Quaternion.identity, this.transform);
                    cornerElementInstance.Initialize(x, y, z);
                    cornerElements[x + (width + 1) * (z + (width + 1) * y)] = cornerElementInstance;
                }
            }
        }


        for (int y = 0; y < height; y++)
        {
            float yPos = y;
            if (y == 0)
            {
                elementHeight = floorHeight;
            }
            else if (y == 1)
            {
                elementHeight = basementHeight;
                yPos          = floorHeight / 2 + basementHeight / 2;
            }
            else
            {
                elementHeight = 1;
            }
            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < width; z++)
                {
                    gridElement gridElementInstance = Instantiate(gridElement, new Vector3(x, yPos, z), Quaternion.identity, this.transform);
                    gridElementInstance.Initialize(x, y, z, elementHeight);
                    gridElements[x + width * (z + width * y)] = gridElementInstance;
                }
            }
        }

        foreach (cornerElement corner in cornerElements)
        {
            corner.SetNearGridElements();
        }

        SetRandomize();
    }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        blockCount   = -width * length;
        housingCount = 0;
        instance     = this;
        blockSize    = 3;
        avratio      = 0.00f;

        basementHeight = 1.5f - floorHeight / 2;
        float elementHeight = 1;

        gridElements   = new gridElement[width * length * height];
        cornerElements = new cornerElement[(width + 1) * (length + 1) * (height + 1)];

        for (int y = 0; y < height + 1; y++)
        {
            for (int x = 0; x < width + 1; x++)
            {
                for (int z = 0; z < length + 1; z++)
                {
                    cornerElement cornerElementInstance = Instantiate(cornerElement, Vector3.zero, Quaternion.identity, this.transform);
                    cornerElementInstance.Initialize(x, y, z);
                    cornerElements[x + (width + 1) * (z + (length + 1) * y)] = cornerElementInstance;
                }
            }
        }

        for (int y = 0; y < height; y++)
        {
            float yPos = y;
            if (y == 0)
            {
                elementHeight = floorHeight;
            }
            else if (y == 1)
            {
                elementHeight = basementHeight;
                yPos          = floorHeight / 2 + basementHeight / 2;
            }
            else
            {
                elementHeight = 1;
            }

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < length; z++)
                {
                    gridElement gridElementInstance = Instantiate(gridElement, new Vector3(x, yPos, z), Quaternion.identity, this.transform);
                    gridElementInstance.Initialize(x, y, z, elementHeight);
                    gridElements[x + width * (z + length * y)] = gridElementInstance;
                }
            }
        }


        foreach (cornerElement corner in cornerElements)
        {
            corner.SetNearGridElements();
        }

        foreach (gridElement gridElement in gridElements)
        {
            gridElement.SetEnable(gridElement.GetCoord());
        }
    }