Example #1
0
    // Build the item
    public void buildItem(GameObject buildItem)
    {
        itemId = ++itemIdCounter;
        Maps.setFloorMapBlock(leftBottomPosition, hDistance, vDistance, 3);

        // If it is a door
        if (no == 1)
        {
            assignedRoom.buildDoor(buildItem, way, leftBottomPosition, hDistance, vDistance);
            Vector2 newLeftBottom = new Vector2();
            // If way is north
            if (way == Way.North)
            {
                newLeftBottom = new Vector2(leftBottomPosition.x, leftBottomPosition.y - 1F);
            }
            // If way is east
            else if (way == Way.East)
            {
                newLeftBottom = new Vector2(leftBottomPosition.x - 1F, leftBottomPosition.y);
            }
            // If way is south
            else if (way == Way.South)
            {
                newLeftBottom = new Vector2(leftBottomPosition.x, leftBottomPosition.y + 1F);
            }
            // If way is west
            else if (way == Way.West)
            {
                newLeftBottom = new Vector2(leftBottomPosition.x + 1F, leftBottomPosition.y);
            }
            Maps.setFloorMapBlock(newLeftBottom, hDistance, vDistance, 4);
        }
        // If it is not a door, its item

        ///bench added by mark
        else if (no == 2)
        {
            assignedRoom.roomItems.Add(buildItem);

            Transform seat = buildItem.transform.GetChild(1);

            if (seat.name == "Seat")
            {
                PathFinderUpdate.AddBounds(seat);
            }
            else
            {
                Debug.LogError("it must be the seat with the collider");
            }
        }
        else
        {
            assignedRoom.roomItems.Add(buildItem);
            Debug.Log(buildItem.name);
        }

        //AstarPath.active.FlushGraphUpdates();
    }
Example #2
0
    // Remove the item
    public void removeItem(GameObject buildItem)
    {
        Maps.setFloorMapBlock(leftBottomPosition, hDistance, vDistance, 2);

        // If it is a door
        if (no == 1)
        {
            assignedRoom.removeDoor(buildItem, way, leftBottomPosition, hDistance, vDistance);
            Vector2 newLeftBottom = new Vector2();
            // If way is north
            if (way == Way.North)
            {
                newLeftBottom = new Vector2(leftBottomPosition.x, leftBottomPosition.y - 1F);
            }
            // If way is east
            else if (way == Way.East)
            {
                newLeftBottom = new Vector2(leftBottomPosition.x - 1F, leftBottomPosition.y);
            }
            // If way is south
            else if (way == Way.South)
            {
                newLeftBottom = new Vector2(leftBottomPosition.x, leftBottomPosition.y + 1F);
            }
            // If way is west
            else if (way == Way.West)
            {
                newLeftBottom = new Vector2(leftBottomPosition.x + 1F, leftBottomPosition.y);
            }
            Maps.setFloorMapBlock(newLeftBottom, hDistance, vDistance, 0);
        }
        // If it is not a door, its item
        ///its a bench edited by mark
        else if (no == 2)
        {
            Transform seat = buildItem.transform.GetChild(1);

            if (seat.name == "Seat")
            {
                PathFinderUpdate.AddBounds(seat);
            }
            else
            {
                Debug.LogError("it must be the seat with the collider");
            }

            assignedRoom.roomItems.Remove(buildItem);
        }
        else
        {
            assignedRoom.roomItems.Remove(buildItem);
        }

        // Delete the game object
        assignedRoom.deleteItem(buildItem);

        //AstarPath.active.FlushGraphUpdates();
    }
Example #3
0
    // Build a door
    public void buildDoor(GameObject door, Way way, Vector2 LBP, int xD, int yD)
    {
        doors.Add(door);

        //pass the child wall with the collider to the pathfinderUpdate
        foreach (Transform child in door.transform)
        {
            if (child.name == "Door 1")
            {
                PathFinderUpdate.AddBounds(child);
            }

            if (child.name == "Door 2")
            {
                PathFinderUpdate.AddBounds(child);
            }
        }
        ///end door graph code

        // If way is north
        if (way == Way.North)
        {
            bottomWall[(int)LBP.x - (int)leftBottom.x].SetActive(false);
            bottomWall[((int)LBP.x - (int)leftBottom.x) + 1].SetActive(false);
        }
        // If way is east
        else if (way == Way.East)
        {
            leftWall[(int)LBP.y - (int)leftBottom.y].SetActive(false);
            leftWall[((int)LBP.y - (int)leftBottom.y) + 1].SetActive(false);
        }
        // If way is south
        else if (way == Way.South)
        {
            topWall[(int)LBP.x - (int)leftBottom.x].SetActive(false);
            topWall[((int)LBP.x - (int)leftBottom.x) + 1].SetActive(false);
        }
        // If way is west
        else if (way == Way.West)
        {
            rightWall[(int)LBP.y - (int)leftBottom.y].SetActive(false);
            rightWall[((int)LBP.y - (int)leftBottom.y) + 1].SetActive(false);
        }

        // flush NAV grid graph update. // edited by mark
        //AstarPath.active.FlushGraphUpdates();
    }
Example #4
0
    // Overloaded constructor room
    public Room(RoomType roomType, Vector2 leftDown, Vector2 leftUp, Vector2 rightDown, Vector2 rightUp, GameObject horizontalWall, GameObject verticalWall, Transform t)
    {
        roomId      = ++roomIdCounter;
        type        = roomType;
        leftBottom  = leftDown;
        leftTop     = leftUp;
        rightBottom = rightDown;
        rightTop    = rightUp;
        // Value (-1,-1) for door means room has no door
        Vector2 door = new Vector2(-1f, -1f);

        leftWall   = new List <GameObject>();
        rightWall  = new List <GameObject>();
        bottomWall = new List <GameObject>();
        topWall    = new List <GameObject>();
        roomItems  = new List <GameObject>();
        doors      = new List <GameObject>();

        // Calculate length of walls
        float      xD = rightBottom.x - leftBottom.x;
        float      yD = leftTop.y - leftBottom.y;
        GameObject wall;

        xLength = xD;
        yLength = yD;

        // Build left wall
        for (int i = 0; i < yD; i++)
        {
            wall = (GameObject)GameObject.Instantiate(verticalWall, new Vector3(leftBottom.x, 0F, leftBottom.y + i), t.rotation);
            leftWall.Add(wall);

            // adjust NAV grid gragh bounds // edited by Mark
            Transform wallChild = wall.transform.GetChild(0);

            if (wallChild.name == "Wall")
            {
                PathFinderUpdate.AddBounds(wallChild);
            }
            else
            {
                Debug.LogError("No wall child object");
            }
        }
        // Build right wall
        for (int i = 0; i < yD; i++)
        {
            wall = (GameObject)GameObject.Instantiate(verticalWall, new Vector3(rightBottom.x, 0F, rightBottom.y + i), t.rotation);
            rightWall.Add(wall);

            // adjust NAV grid gragh bounds // edited by Mark
            Transform wallChild = wall.transform.GetChild(0);

            if (wallChild.name == "Wall")
            {
                PathFinderUpdate.AddBounds(wallChild);
            }
            else
            {
                Debug.LogError("No wall child object");
            }
        }
        // Build bottom wall
        for (int i = 0; i < xD; i++)
        {
            wall = (GameObject)GameObject.Instantiate(horizontalWall, new Vector3(leftBottom.x + i, 0F, leftBottom.y), t.rotation);
            bottomWall.Add(wall);

            // adjust NAV grid gragh bounds // edited by Mark
            Transform wallChild = wall.transform.GetChild(0);

            if (wallChild.name == "Wall")
            {
                PathFinderUpdate.AddBounds(wallChild);
            }
            else
            {
                Debug.LogError("No wall child object");
            }
        }
        // Build top wall
        for (int i = 0; i < xD; i++)
        {
            wall = (GameObject)GameObject.Instantiate(horizontalWall, new Vector3(leftTop.x + i, 0F, leftTop.y), t.rotation);
            topWall.Add(wall);

            // adjust NAV grid gragh bounds // edited by Mark
            Transform wallChild = wall.transform.GetChild(0);

            if (wallChild.name == "Wall")
            {
                PathFinderUpdate.AddBounds(wallChild);
            }
            else
            {
                Debug.LogError("No wall child object");
            }
        }

        // flush NAV grid graph update. // edited by Mark
        //AstarPath.active.FlushGraphUpdates();
    }
Example #5
0
    // Delete the walls and doors of room
    public void deleteWallsDoors()
    {
        // Delete the doors
        for (int i = doors.Count - 1; i >= 0; i--)
        {
            GameObject go = doors[i];

            //pass the child door with the collider to the pathfinderUpdate
            foreach (Transform child in go.transform)
            {
                if (child.name == "Door 1")
                {
                    PathFinderUpdate.AddBounds(child);
                }

                if (child.name == "Door 2")
                {
                    PathFinderUpdate.AddBounds(child);
                }
            }
            ///end door graph code

            Item itemPro = go.GetComponent <Item>();
            itemPro.removeItem(go);
        }

        // Delete left wall
        foreach (GameObject go in leftWall)
        {
            // adjust NAV grid gragh bounds // edited by Mark
            Transform wallChild = go.transform.GetChild(0);

            if (wallChild.name == "Wall")
            {
                PathFinderUpdate.AddBounds(wallChild);
            }
            else
            {
                Debug.LogError("No wall child object");
            }

            GameObject.Destroy(go);
        }
        // Delete right wall
        foreach (GameObject go in rightWall)
        {
            // adjust NAV grid gragh bounds // edited by Mark
            Transform wallChild = go.transform.GetChild(0);

            if (wallChild.name == "Wall")
            {
                PathFinderUpdate.AddBounds(wallChild);
            }
            else
            {
                Debug.LogError("No wall child object");
            }

            GameObject.Destroy(go);
        }
        // Delete bottom wall
        foreach (GameObject go in bottomWall)
        {
            // adjust NAV grid gragh bounds // edited by Mark
            Transform wallChild = go.transform.GetChild(0);

            if (wallChild.name == "Wall")
            {
                PathFinderUpdate.AddBounds(wallChild);
            }
            else
            {
                Debug.LogError("No wall child object");
            }

            GameObject.Destroy(go);
        }
        // Delete top wall
        foreach (GameObject go in topWall)
        {
            // adjust NAV grid gragh bounds // edited by Mark
            Transform wallChild = go.transform.GetChild(0);

            if (wallChild.name == "Wall")
            {
                PathFinderUpdate.AddBounds(wallChild);
            }
            else
            {
                Debug.LogError("No wall child object");
            }

            GameObject.Destroy(go);
        }
        // flush NAV grid graph update. // edited by Chan
        //AstarPath.active.FlushGraphUpdates();
    }