예제 #1
0
    private void CreateMapUI()
    {
        Room[,] map = MissionManager.instance.RoomMap;
        mapUI       = new MapRoomUI[map.GetLength(0), map.GetLength(1)];

        for (var i = 0; i < map.GetLength(0); i++)
        {
            for (var j = 0; j < map.GetLength(1); j++)
            {
                if (map[i, j] != null)
                {
                    RoomEntrances entrances = map[i, j].GetComponent <RoomEntrances>();

                    MapRoomUI mapRoom = Instantiate(roomUIPrefab);
                    mapRoom.Init(entrances.Type);
                    mapUI[i, j] = mapRoom;
                    RectTransform roomRect = mapRoom.GetComponent <RectTransform>();
                    roomWidth  = roomRect.rect.width;
                    roomHeight = roomRect.rect.height;
                    roomWidth  = roomWidth - (roomWidth / dividebythisWidth);
                    roomHeight = roomHeight - (roomHeight / dividebythisHeight);
                    roomRect.SetParent(roomParent, false);


                    Vector2 centerDelta = new Vector2(entrances.x - startingRoom.x, entrances.y - startingRoom.y);
                    roomRect.anchoredPosition = new Vector3(roomWidth, roomHeight, 0) * centerDelta;

                    CreateDoors(mapRoom, entrances);
                }
            }
        }
        mapUI[startingRoom.x, startingRoom.y].ExploreRoom();
    }
예제 #2
0
    void CreateDoors(MapRoomUI mapRoom, RoomEntrances entrances)
    {
        RectTransform mapRoomRect = mapRoom.GetComponent <RectTransform>();

        foreach (var exit in entrances.ActiveExits)
        {
            if (!exit.gameObject.activeSelf)
            {
                return;
            }
            Vector2 posDelta = Vector2.zero;

            switch (exit.ExitDirection)
            {
            case RoomEntrances.ExitDirection.Left:
                posDelta = new Vector2(-roomWidth / 2, 0);
                break;

            case RoomEntrances.ExitDirection.Right:
                posDelta = new Vector2(roomWidth / 2, 0);
                break;

            case RoomEntrances.ExitDirection.Top:
                posDelta = new Vector2(0, roomHeight / 2);
                break;

            case RoomEntrances.ExitDirection.Bot:
                posDelta = new Vector2(0, -roomHeight / 2);
                break;
            }

            //TODO: #66 Different door vertical vs horizontal
            RectTransform doorRect = Instantiate(doorPrefab).GetComponent <RectTransform>();
            doorRect.SetParent(mapRoomRect, false);
            doorRect.anchoredPosition = posDelta;
        }
    }