示例#1
0
    private void PlaceWall(GameObject target, WallSide wallSide)
    {
        DngnRoomInfo RoomInfo = target.GetComponent <DngnRoomInfo>();

        //Dont bother placing walls around empty rooms
        if (RoomInfo.m_roomType == DngnRoomInfo.RoomType.Void)
        {
            return;
        }
        Vector3    WallPos      = target.transform.position;
        GameObject AdjacentRoom = null;

        switch (wallSide)
        {
        case (WallSide.North):
            AdjacentRoom = GetNorth(target);
            WallPos     += Vector3.forward * (m_floorSize * 0.5f);
            break;

        case (WallSide.East):
            AdjacentRoom = GetEast(target);
            WallPos     += Vector3.right * (m_floorSize * 0.5f);
            break;

        case (WallSide.South):
            AdjacentRoom = GetSouth(target);
            WallPos     += (-Vector3.forward) * (m_floorSize * 0.5f);
            break;

        case (WallSide.West):
            AdjacentRoom = GetWest(target);
            WallPos     += (-Vector3.right) * (m_floorSize * 0.5f);
            break;
        }
        //If there is void to the north, place a wall there
        if (AdjacentRoom == null)
        {
            //Spawn a wall
            GameObject Wall = GameObject.Instantiate(m_wallPrefab, WallPos, Quaternion.identity) as GameObject;
            //Parent it
            Wall.transform.parent = m_dungeonRoot.transform;
            //Rotate it
            Wall.transform.LookAt(target.transform.position);
            //Mark there is now a wall here
            switch (wallSide)
            {
            case (WallSide.North):
                RoomInfo.m_hasNorthWall = true;
                break;

            case (WallSide.East):
                RoomInfo.m_hasEastWall = true;
                break;

            case (WallSide.South):
                RoomInfo.m_hasSouthWall = true;
                break;

            case (WallSide.West):
                RoomInfo.m_hasWestWall = true;
                break;
            }
            return;
        }
        //If there is a room to the north, only place a wall if its empty
        DngnRoomInfo AdjacentRoomInfo = AdjacentRoom.GetComponent <DngnRoomInfo>();

        if (AdjacentRoomInfo.m_roomType == DngnRoomInfo.RoomType.Void)
        {
            //Spawn a wall
            GameObject Wall = GameObject.Instantiate(m_wallPrefab, WallPos, Quaternion.identity) as GameObject;
            //Parent it
            Wall.transform.parent = m_dungeonRoot.transform;
            //Rotate it
            Wall.transform.LookAt(target.transform.position);
            //Mark there is now a wall here
            switch (wallSide)
            {
            case (WallSide.North):
                RoomInfo.m_hasNorthWall = true;
                break;

            case (WallSide.East):
                RoomInfo.m_hasEastWall = true;
                break;

            case (WallSide.South):
                RoomInfo.m_hasSouthWall = true;
                break;

            case (WallSide.West):
                RoomInfo.m_hasWestWall = true;
                break;
            }
            return;
        }
    }
示例#2
0
    private void PlaceDoor(GameObject target, WallSide wallSide)
    {
        DngnRoomInfo RoomInfo = target.GetComponent <DngnRoomInfo>();

        //Do not connect to empty rooms
        if (RoomInfo.m_roomType == DngnRoomInfo.RoomType.Void)
        {
            return;
        }
        //If there is already a wall in the direction we are trying to place
        //then we want to break out of the function
        //While were at it, get the position we are going to place the door if
        //we get that far, just so we dont need a second switch statement later on
        Vector3    DoorPos      = target.transform.position;
        GameObject AdjacentRoom = null;

        switch (wallSide)
        {
        case (WallSide.North):
            if (RoomInfo.m_hasNorthWall)
            {
                return;
            }
            AdjacentRoom = GetNorth(target);
            DoorPos     += Vector3.forward * (m_floorSize * 0.5f);
            break;

        case (WallSide.East):
            if (RoomInfo.m_hasEastWall)
            {
                return;
            }
            AdjacentRoom = GetEast(target);
            DoorPos     += Vector3.right * (m_floorSize * 0.5f);
            break;

        case (WallSide.South):
            if (RoomInfo.m_hasSouthWall)
            {
                return;
            }
            AdjacentRoom = GetSouth(target);
            DoorPos     += (-Vector3.forward) * (m_floorSize * 0.5f);
            break;

        case (WallSide.West):
            if (RoomInfo.m_hasWestWall)
            {
                return;
            }
            AdjacentRoom = GetWest(target);
            DoorPos     += (-Vector3.right) * (m_floorSize * 0.5f);
            break;
        }
        //Get info from the room we are going to place a door at
        DngnRoomInfo AdjacentRoomInfo = AdjacentRoom.GetComponent <DngnRoomInfo>();

        //Make sure there is a valid room in the direction we are trying
        if (AdjacentRoomInfo.m_roomType == DngnRoomInfo.RoomType.Normal ||
            AdjacentRoomInfo.m_roomType == DngnRoomInfo.RoomType.Start ||
            AdjacentRoomInfo.m_roomType == DngnRoomInfo.RoomType.Boss)
        {
            //Spawn a new door
            GameObject Door = GameObject.Instantiate(m_doorPrefab, DoorPos, Quaternion.identity) as GameObject;
            //Parent it
            Door.transform.parent = m_dungeonRoot.transform;
            //Rotate it
            Door.transform.LookAt(target.transform.position);
            //Note there is now a door here
            switch (wallSide)
            {
            case (WallSide.North):
                //Mark that this room has a north door
                RoomInfo.m_hasNorthWall = true;
                //Give the room a reference to its door so it can be removed later
                MarkHasDoor(target, Door, WallSide.North);
                //Also mark the north room has a south door (its the same door between the two rooms)
                GameObject north = GetNorth(target);
                if (north != null)
                {
                    north.GetComponent <DngnRoomInfo>().m_hasSouthWall = true;
                }
                break;

            case (WallSide.East):
                RoomInfo.m_hasEastWall = true;
                MarkHasDoor(target, Door, WallSide.East);
                GameObject east = GetEast(target);
                if (east != null)
                {
                    east.GetComponent <DngnRoomInfo>().m_hasWestWall = true;
                }
                break;

            case (WallSide.South):
                RoomInfo.m_hasSouthWall = true;
                MarkHasDoor(target, Door, WallSide.South);
                GameObject south = GetSouth(target);
                if (south != null)
                {
                    south.GetComponent <DngnRoomInfo>().m_hasNorthWall = true;
                }
                break;

            case (WallSide.West):
                RoomInfo.m_hasWestWall = true;
                MarkHasDoor(target, Door, WallSide.West);
                GameObject west = GetWest(target);
                if (west != null)
                {
                    west.GetComponent <DngnRoomInfo>().m_hasEastWall = true;
                }
                break;
            }
        }
    }