示例#1
0
    public void CheckForBorders()
    {
        for (int i = 0; i < worldScript.objects.Length; i++)
        {
            left   = empty;
            right  = empty;
            top    = empty;
            bottom = empty;



            if (worldScript.objects[i] == "road" || worldScript.objects[i] == "roadVertical" || worldScript.objects[i] == "cornerRoad" || worldScript.objects[i] == "cornerRoadRightTop" || worldScript.objects[i] == "cornerRoadRightBottom" || worldScript.objects[i] == "cornerRoadLeftBottom" || worldScript.objects[i] == "3wayRoad" || worldScript.objects[i] == "3wayRoadUpwards" || worldScript.objects[i] == "3wayRoadLeft" || worldScript.objects[i] == "3wayRoadDown" || worldScript.objects[i] == "4cornerRoad")
            {
                GameObject parent = GameObject.Find(i.ToString());

                GroundBorders groundScript = parent.GetComponent <GroundBorders>();

                if (groundScript.edgeType != "Left" & groundScript.edgeType != "TopLeft" & groundScript.edgeType != "BottomLeft")
                {
                    left = GameObject.Find((i - 1).ToString());
                }
                if (groundScript.edgeType != "Right" & groundScript.edgeType != "TopRight" & groundScript.edgeType != "BottomRight")
                {
                    right = GameObject.Find((i + 1).ToString());
                }
                if (groundScript.edgeType != "Top" & groundScript.edgeType != "TopLeft" & groundScript.edgeType != "TopRight")
                {
                    top = GameObject.Find((i - gameScript.columns).ToString());
                }
                if (groundScript.edgeType != "Bottom" & groundScript.edgeType != "BottomLeft" & groundScript.edgeType != "BottomRight")
                {
                    bottom = GameObject.Find((i + gameScript.rows).ToString());
                }

                if (GameObject.Find("Road" + i).transform.position == highwayConnect)
                {
                    leftRoad = true;
                    SpecificRoadLogic roadScript = GameObject.Find("Road" + i).GetComponent <SpecificRoadLogic>();
                    roadScript.isHighwayConnected = true;
                }
                else if (GameObject.Find("Road" + System.Convert.ToInt32(left.name)) != null)
                {
                    leftRoad = true;
                }
                else
                {
                    leftRoad = false;
                }
                if (GameObject.Find("Road" + System.Convert.ToInt32(right.name)) != null)
                {
                    rightRoad = true;
                }
                else
                {
                    rightRoad = false;
                }
                if (GameObject.Find("Road" + System.Convert.ToInt32(top.name)) != null)
                {
                    topRoad = true;
                }
                else
                {
                    topRoad = false;
                }
                if (GameObject.Find("Road" + System.Convert.ToInt32(bottom.name)) != null)
                {
                    bottomRoad = true;
                }
                else
                {
                    bottomRoad = false;
                }

                currentRoad = GameObject.Find("Road" + i);
                currentPos  = new Vector3(0, 0, 0);

                CheckForHighway();

                //covers left, left+right, left+right+top, left+right+top+bottom
                //also left+top, left+top+bottom
                //left+bottom
                if (leftRoad == true)
                {
                    //placement snapping
                    if (rightRoad == true)
                    {
                        if (topRoad == true)
                        {
                            if (bottomRoad == true)
                            {
                                if (worldScript.objects[i] != "4cornerRoad")
                                {
                                    currentPos = currentRoad.transform.position;
                                    Destroy(currentRoad);
                                    currentRoad = Instantiate(fourCornerRoad);
                                    currentRoad.transform.position = currentPos;
                                    worldScript.objects[i]         = "4cornerRoad";
                                    currentRoad.name = "Road" + i;
                                }
                            }
                            else
                            {
                                if (worldScript.objects[i] != "3wayRoadUpwards")
                                {
                                    currentPos = currentRoad.transform.position;
                                    Destroy(currentRoad);
                                    currentRoad = Instantiate(threeWayRoadUpwards);
                                    currentRoad.transform.position = currentPos;
                                    worldScript.objects[i]         = "3wayRoadUpwards";
                                    currentRoad.name = "Road" + i;
                                }
                            }
                        }
                        else if (bottomRoad == true)
                        {
                            if (worldScript.objects[i] != "3wayRoadDown")
                            {
                                currentPos = currentRoad.transform.position;
                                Destroy(currentRoad);
                                currentRoad = Instantiate(threeWayRoadDown);
                                currentRoad.transform.position = currentPos;
                                worldScript.objects[i]         = "3wayRoadDown";
                                currentRoad.name = "Road" + i;
                            }
                        }
                        else
                        {
                            if (worldScript.objects[i] != "road")
                            {
                                currentPos = currentRoad.transform.position;
                                Destroy(currentRoad);
                                currentRoad = Instantiate(road);
                                currentRoad.transform.position = currentPos;
                                worldScript.objects[i]         = "road";
                                currentRoad.name = "Road" + i;
                            }
                        }
                    }
                    else if (topRoad == true)
                    {
                        if (bottomRoad == true)
                        {
                            if (worldScript.objects[i] != "3wayRoadLeft")
                            {
                                currentPos = currentRoad.transform.position;
                                Destroy(currentRoad);
                                currentRoad = Instantiate(threeWayRoadLeft);
                                currentRoad.transform.position = currentPos;
                                currentRoad.name       = "Road" + i;
                                worldScript.objects[i] = "3wayRoadLeft";
                            }
                        }
                        else
                        {
                            if (worldScript.objects[i] != "cornerRoad")
                            {
                                currentPos = currentRoad.transform.position;
                                Destroy(currentRoad);
                                currentRoad = Instantiate(cornerRoad);
                                currentRoad.transform.position = currentPos;
                                currentRoad.name       = "Road" + i;
                                worldScript.objects[i] = "cornerRoad";
                            }
                        }
                    }
                    else if (bottomRoad == true)
                    {
                        if (worldScript.objects[i] != "cornerRoadLeftBottom")
                        {
                            currentPos = currentRoad.transform.position;
                            Destroy(currentRoad);
                            currentRoad = Instantiate(cornerRoadLeftBottom);
                            currentRoad.transform.position = currentPos;
                            worldScript.objects[i]         = "cornerRoadLeftBottom";
                            currentRoad.name = "Road" + i;
                        }
                    }
                    else
                    {
                        if (worldScript.objects[i] != "road")
                        {
                            currentPos = currentRoad.transform.position;
                            Destroy(currentRoad);
                            currentRoad = Instantiate(road);
                            currentRoad.transform.position = currentPos;
                            worldScript.objects[i]         = "road";
                            currentRoad.name = "Road" + i;
                        }
                    }
                }

                //covers right, right+top, right+top+bottom
                //right+bottom
                else if (rightRoad == true)
                {
                    if (topRoad == true)
                    {
                        if (bottomRoad == true)
                        {
                            if (worldScript.objects[i] != "3wayRoad")
                            {
                                currentPos = currentRoad.transform.position;
                                Destroy(currentRoad);
                                currentRoad = Instantiate(threeWayRoad);
                                currentRoad.transform.position = currentPos;
                                worldScript.objects[i]         = "3wayRoad";
                                currentRoad.name = "Road" + i;
                            }
                        }
                        else
                        {
                            if (worldScript.objects[i] != "cornerRoadRightTop")
                            {
                                currentPos = currentRoad.transform.position;
                                Destroy(currentRoad);
                                currentRoad = Instantiate(cornerRoadRightTop);
                                currentRoad.transform.position = currentPos;
                                worldScript.objects[i]         = "cornerRoadRightTop";
                                currentRoad.name = "Road" + i;
                            }
                        }
                    }
                    else if (bottomRoad == true)
                    {
                        if (worldScript.objects[i] != "cornerRoadRightBottom")
                        {
                            currentPos = currentRoad.transform.position;
                            Destroy(currentRoad);
                            currentRoad = Instantiate(cornerRoadRightBottom);
                            currentRoad.transform.position = currentPos;
                            worldScript.objects[i]         = "cornerRoadRightBottom";
                            currentRoad.name = "Road" + i;
                        }
                    }
                    else
                    {
                        if (worldScript.objects[i] != "road")
                        {
                            currentPos = currentRoad.transform.position;
                            Destroy(currentRoad);
                            currentRoad = Instantiate(road);
                            currentRoad.transform.position = currentPos;
                            worldScript.objects[i]         = "road";
                            currentRoad.name = "Road" + i;
                        }
                    }
                }

                //covers top, top+bottom
                else if (topRoad == true)
                {
                    if (bottomRoad == true)
                    {
                        if (worldScript.objects[i] != "roadVertical")
                        {
                            currentPos = currentRoad.transform.position;
                            Destroy(currentRoad);
                            currentRoad = Instantiate(roadVertical);
                            currentRoad.transform.position = currentPos;
                            currentRoad.name       = "Road" + i;
                            worldScript.objects[i] = "roadVertical";
                        }
                    }
                    else
                    {
                        if (worldScript.objects[i] != "roadVertical")
                        {
                            currentPos = currentRoad.transform.position;
                            Destroy(currentRoad);
                            currentRoad = Instantiate(roadVertical);
                            currentRoad.transform.position = currentPos;
                            currentRoad.name       = "Road" + i;
                            worldScript.objects[i] = "roadVertical";
                        }
                    }
                }

                //covers bottom
                else if (bottomRoad == true)
                {
                    if (worldScript.objects[i] != "roadVertical")
                    {
                        currentPos = currentRoad.transform.position;
                        Destroy(currentRoad);
                        currentRoad = Instantiate(roadVertical);
                        currentRoad.transform.position = currentPos;
                        currentRoad.name       = "Road" + i;
                        worldScript.objects[i] = "roadVertical";
                    }
                }
            }
        }
    }
    public void GroundBuild()
    {
        for (int r = 0; r < rows; r++)
        {
            lastGroundPos.x = 0;
            groundPos.z     = lastGroundPos.z - 1;
            for (int c = 0; c < columns; c++)
            {
                groundPos.x = lastGroundPos.x + 1;

                currentObject = Instantiate(ground);
                currentObject.transform.position = groundPos;
                currentObject.transform.name     = groundCount.ToString();
                groundCount++;
                lastGroundPos.x = groundPos.x;

                GroundBorders borderScript = currentObject.GetComponent <GroundBorders>();

                if (r == 0)
                {
                    if (c == 0)
                    {
                        borderScript.edgeType = "TopLeft";
                    }
                    else if (c == columns - 1)
                    {
                        borderScript.edgeType = "TopRight";
                    }
                    else
                    {
                        borderScript.edgeType = "Top";
                    }
                }
                else if (r == rows - 1)
                {
                    if (c == 0)
                    {
                        borderScript.edgeType = "BottomLeft";
                    }
                    else if (c == columns - 1)
                    {
                        borderScript.edgeType = "BottomRight";
                    }
                    else
                    {
                        borderScript.edgeType = "Bottom";
                    }
                }
                else if (c == 0)
                {
                    borderScript.edgeType = "Left";
                }
                else if (c == columns - 1)
                {
                    borderScript.edgeType = "Right";
                }
                else
                {
                    borderScript.edgeType = "Main";
                }
            }
            lastGroundPos.z = groundPos.z;
        }

        Camera.main.transform.position = new Vector3(columns / 2, 8, -rows);
    }