예제 #1
0
    private void Start()
    {
        tempXSize = 0;
        tempZSize = 0;

        buildingObject = new GameObject[1500];

        buildingNum = 0;

        for (int i = 0; i < road.vertices.Length; ++i)
        {
            if (road.isBuildingPlace[i] == (int)buildingDirection.NOTBUILDINGPLACE)
            {
                continue;
            }

            int     prefab = Random.Range(0, buildingPrefab.Length);
            Vector3 size   = buildingPrefab[prefab].GetComponent <MeshRenderer>().bounds.size;

            tempXSize = size.x / 12;
            if (tempXSize < 1)
            {
                tempXSize = 0.5f;
            }
            else if (tempXSize >= 2)
            {
                tempXSize = 1.0f;
            }

            i += (int)tempXSize;

            if (((i + road.xSize + 1) < (road.xSize * road.zSize)) &&
                road.isBuildingPlace[i + road.xSize + 1] != (int)buildingDirection.NOTBUILDINGPLACE)
            {
                tempZSize = size.x / 12;
                if (tempZSize < 1)
                {
                    tempZSize = 0.5f;
                }
                else if (tempZSize >= 2)
                {
                    tempZSize = 1.0f;
                }

                road.isBuildingPlace[i + (road.xSize + 1)] = (int)buildingDirection.NOTBUILDINGPLACE;
            }

            if (road.isBuildingPlace[i] == (int)buildingDirection.DOWN)
            {
                buildingObject[buildingNum] = Instantiate(buildingPrefab[prefab], road.vertices[i], Quaternion.identity);
            }
            else if (road.isBuildingPlace[i] == (int)buildingDirection.UP)
            {
                buildingObject[buildingNum] = Instantiate(buildingPrefab[prefab], road.vertices[i], Quaternion.Euler(0, 180, 0));
            }
            else if (road.isBuildingPlace[i] == (int)buildingDirection.LEFT)
            {
                buildingObject[buildingNum] = Instantiate(buildingPrefab[prefab], road.vertices[i], Quaternion.Euler(0, 90, 0));
            }
            else if (road.isBuildingPlace[i] == (int)buildingDirection.RIGHT)
            {
                buildingObject[buildingNum] = Instantiate(buildingPrefab[prefab], road.vertices[i], Quaternion.Euler(0, -90, 0));
            }
            else
            {
                continue;
            }

            makeNotBuildingPlace(i);

            buildingObject[buildingNum].transform.SetParent(buildingParent.transform);

            if (road.isBuildingPlace[i + 1] != (int)buildingDirection.NOTBUILDINGPLACE)
            {
                tempXSize += size.x / 12;
                if (tempXSize < 1)
                {
                    tempXSize = 1.0f;
                }
                else if (tempXSize >= 2)
                {
                    tempXSize = 2.0f;
                }

                i += (int)tempXSize;
            }
            if (((i + road.xSize + 1) < (road.xSize * road.zSize)) &&
                road.isBuildingPlace[i + road.xSize + 1] != (int)buildingDirection.NOTBUILDINGPLACE)
            {
                tempZSize = size.x / 12;
                if (tempZSize < 1)
                {
                    tempZSize = 0.5f;
                }
                else if (tempZSize >= 2)
                {
                    tempZSize = 1.0f;
                }

                for (int j = 0; j < (int)tempZSize; ++j)
                {
                    road.isBuildingPlace[i + road.xSize + 1] = (int)buildingDirection.NOTBUILDINGPLACE;
                }
            }

            buildingObject[buildingNum].AddComponent <BoxCollider>();
            BoxCollider col = buildingObject[buildingNum].GetComponent <BoxCollider>();
            col.tag = "buildingBoxCollider";

            ++buildingNum;
        }

        map.UpdateMesh();
        road.RefreshRoadVertices();
        road.UpdateMesh();
    }