// Use this for initialization
    void Awake()
    {
        //roomEvents = [];
        // Get the size and the grid
        if (!isCorridor)
        {
            size.x   = Random.Range(minSize.x, maxSize.x);
            size.z   = Random.Range(minSize.z, maxSize.z);
            tileGrid = new RoomCell[size.x, size.z];
            // Generate the grid and make the walls
            GenerateGrid();
            MakeWalls();
            // Get the door cells
            doors = GetDoors();
            // Generate the middle
            RoomCell middleCell = GetCellAt(new IntVector2(size.x / 2 - 1, size.z / 2 - 1));
            middle = Instantiate(middlePrefab) as GameObject;
            middle.transform.position = middleCell.transform.position + new Vector3(5f, 0f, 5f);
            middle.transform.SetParent(this.transform);
            GetCellAt(new IntVector2(size.x / 2, size.z / 2)).setFull();
            GetCellAt(new IntVector2(size.x / 2, size.z / 2 - 1)).setFull();
            GetCellAt(new IntVector2(size.x / 2 - 1, size.z / 2)).setFull();
            GetCellAt(new IntVector2(size.x / 2 - 1, size.z / 2 - 1)).setFull();
            // Fill with furniture

            // Fill with NPCs
            if (GameManager.instance.enemies)
            {
                spawnNPCs();
            }
        }
    }
        private void UpdateRoomInfo(RoomCell cell)
        {
            var bookedTimes = cell.BookedTimes;

            bookedTimes.Sort((a, b) => a.Start.CompareTo(b.Start));
            _bookedTimeCells.Clear();
            if (bookedTimes.Count == 0)
            {
                _bookedTimeCells.Add(
                    new BookedTimeCell(
                        "Нет ни одной брони"
                        )
                    );
                return;
            }
            foreach (var bookedTime in bookedTimes)
            {
                _bookedTimeCells.Add(
                    new BookedTimeCell(
                        bookedTime.ToCellString()
                        )
                    );
            }
            ListRoomNumberTextBlock.Text       = cell.Number;
            ListRoomNumberTextBlock.Visibility = Visibility.Visible;

            ListRoomOccupancyTextBlock.Text       = $"Номер заполнен на {cell.OccupancyText}";
            ListRoomOccupancyTextBlock.Visibility = Visibility.Visible;

            ListRoomRequestCountTextBlock.Text       = $"Всего {cell.RequestsCount} заявок на этот номер";
            ListRoomRequestCountTextBlock.Visibility = Visibility.Visible;
        }
示例#3
0
    public void RemoveRoom(RoomCell roomCell)
    {
        var cellsToReplace = new List <Cell>();

        for (int i = 0; i < roomCell.roomInfo.size; i++)
        {
            cellsToReplace.Add(CellFactory.CreateCell(roomCell.id + i, roomCell.transform.position - Vector3.right * roomCell.size * 0.5f * Cell.defaultCellWidth + Vector3.right * i * Cell.defaultCellWidth + Vector3.right * Cell.defaultCellWidth * 0.5f, 1, CellState.Corridor));
            //Setting neighbours
            if (i > 0)
            {
                cellsToReplace[i - 1].rightNeighbour = cellsToReplace[i];
                cellsToReplace[i].leftNeighbour      = cellsToReplace[i - 1];
            }
        }
        cellsToReplace[0].leftNeighbour = roomCell.leftNeighbour;
        cellsToReplace[roomCell.roomInfo.size - 1].rightNeighbour = roomCell.rightNeighbour;
        cells.Remove(roomCell);
        cells.InsertRange(roomCell.id, cellsToReplace);
        foreach (var o in cellsToReplace)
        {
            o.UpdateView();
        }
        UpdateCellIds();
        Destroy(roomCell.gameObject);
    }
示例#4
0
    public void getRooms()
    {
        int count = listContent.childCount;

        for (int i = 0; i < count; i++)
        {
            Destroy(listContent.GetChild(i).gameObject);
        }
        if (PhotonNetwork.GetRoomList().Length == 0)
        {
            Debug.Log("no room ");
            if (noRoomImg != null)
            {
                noRoomImg.SetActive(true);
            }
            return;
        }
        if (noRoomImg != null)
        {
            noRoomImg.SetActive(false);
        }
        foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
        {
            GameObject cell  = Instantiate(roomCell);
            RoomCell   rcell = cell.GetComponent <RoomCell> ();
            rcell.roomName.text    = roomInfo.Name;
            rcell.playerCount.text = roomInfo.PlayerCount + " / " + roomInfo.MaxPlayers;
            rcell.joinButton.onClick.AddListener(() => {
                PhotonNetwork.JoinRoom(roomInfo.Name);
            });
            cell.transform.SetParent(listContent);
        }
    }
示例#5
0
    void SetupCellSurrounding(RoomCell cell)
    {
        RoomCell tempCell;

        if (_cells.TryGetValue(cell.coordinate + Vector2Int.left, out tempCell))
        {
            tempCell.right = cell.room;
            cell.left      = tempCell.room;
        }

        if (_cells.TryGetValue(cell.coordinate + Vector2Int.right, out tempCell))
        {
            tempCell.left = cell.room;
            cell.right    = tempCell.room;
        }

        if (_cells.TryGetValue(cell.coordinate + Vector2Int.up, out tempCell))
        {
            tempCell.down = cell.room;
            cell.top      = tempCell.room;
        }

        if (_cells.TryGetValue(cell.coordinate + Vector2Int.down, out tempCell))
        {
            tempCell.top = cell.room;
            cell.down    = tempCell.room;
        }
    }
示例#6
0
    private void Start()
    {
        Setup();

#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return;
        }
#endif

        if (follow == null)
        {
            return;
        }

        RoomCell cell = RoomManager.Instance.GetCellFromWorld(follow.transform.position);

        if (cell == null)
        {
            Debug.LogError("target outside of the world");
        }
        else
        {
            currentRoom = cell.room;
        }
    }
示例#7
0
    /// <summary>
    /// Finds the first room cell between two rooms that overlaps.
    /// </summary>
    /// <param name="a">The room to check</param>
    /// <param name="b">The existing room</param>
    /// <returns>True if any cells overlap, otherwise false.</returns>
    public static bool DoRoomsOverlap(Room a, Room b)
    {
        bool overlapExists = false;

        for (int i = 0; i < a.Cells.Count; i++)
        {
            RoomCell current      = a.Cells[i];
            Vector3  realPosition = a.Position + current.Position;

            for (int j = 0; j < b.Cells.Count; j++)
            {
                RoomCell suspect         = b.Cells[j];
                Vector3  suspectPosition = b.Position + suspect.Position;

                overlapExists = (realPosition == suspectPosition);
                if (overlapExists)
                {
                    break;
                }
            }

            if (overlapExists)
            {
                break;
            }
        }

        return(overlapExists);
    }
示例#8
0
    /// <summary>
    /// Determines if two rooms share a pair of adjacent "doors".
    /// </summary>
    /// <param name="a">The room to check</param>
    /// <param name="b">The existing room</param>
    /// <returns>True if the two rooms have two adjacent doors, otherwise false.</returns>
    public static bool AreRoomDoorsJoined(Room a, Room b)
    {
        bool roomsJoined = false;

        for (int i = 0; i < a.RoomDoors.Count; i++)
        {
            RoomCell current         = a.RoomDoors[i];
            Vector3  currentPosition = a.Position + current.Position;
            Vector3  currentRotation = a.Rotation + current.Rotation;

            for (int j = 0; j < b.RoomDoors.Count; j++)
            {
                RoomCell suspect         = b.RoomDoors[j];
                Vector3  suspectPosition = b.Position + suspect.Position;
                Vector3  suspectRotation = b.Rotation + suspect.Rotation;

                // We're now doing floating point math...
                // Get the distance between the two cell positions.
                // If that distance is not 1 world unit apart, the two doors are not adjacent.
                float distance    = Vector3.Distance(currentPosition, suspectPosition);
                bool  areAdjacent = Mathf.Abs(distance - 1.0f) < 0.001f;

                // Also, check that the two doors are facing each other.
                Vector3 normalized = (currentRotation - suspectRotation).normalized;
                float   direction  = Vector3.Dot(normalized, Vector3.up);
                bool    areFacing  = Mathf.Approximately(direction, 1.0f);

                roomsJoined |= areAdjacent && areFacing;

                // Unit Test Debug code...
                string stateMessage = string.Format(
                    "The doors at {0} and {1} {2} adjacent, and {3} facing each other.",
                    currentPosition,
                    suspectPosition,
                    (areAdjacent ? "are" : "aren't"),
                    (areFacing ? "are" : "aren't")
                    );

                string distanceMessage = string.Format(
                    "The distance between the rooms is {0} units",
                    distance
                    );

                string anglesMessage = string.Format(
                    "The normalized magnitude between rotations {0} and {1} is {2}.",
                    currentRotation,
                    suspectRotation,
                    direction
                    );

                Console.WriteLine(stateMessage);
                Console.WriteLine(distanceMessage);
                Console.WriteLine(anglesMessage);
            }
        }

        return(roomsJoined);
    }
示例#9
0
    private void CreateCell(int x, int y)
    {
        RoomCell newCell = Instantiate(cellPrefab) as RoomCell;

        cells[x, y]                     = newCell;
        newCell.name                    = "RoomCell " + x + ", " + y;
        newCell.transform.parent        = transform;
        newCell.transform.localPosition = new Vector3(x - sizeX * 0.5f, y - sizeY * 0.5f + 0.5f, 0);
    }
示例#10
0
    RoomCell CreateCell(Vector2Int coord)
    {
        RoomCell cell = new RoomCell(coord, cells.Length);

        UnityEditor.ArrayUtility.Add(ref cells, cell);

        _cells[coord] = cell;

        return(cell);
    }
示例#11
0
    public RoomCell GetCellFromWorld(Vector2 world)
    {
        int coordX = Mathf.FloorToInt(world.x / _roomWorldSize.x);
        int coordY = Mathf.FloorToInt(world.y / _roomWorldSize.y);

        RoomCell cell = null;

        _cells.TryGetValue(new Vector2Int(coordX, coordY), out cell);

        return(cell);
    }
示例#12
0
    public void addCellButton()
    {
        GameObject cell  = Instantiate(roomCell);
        RoomCell   rcell = cell.GetComponent <RoomCell> ();

        rcell.roomName.text    = "room name";
        rcell.playerCount.text = "0명" + " / " + "5명";
        rcell.joinButton.onClick.AddListener(() => {
            PhotonNetwork.JoinRoom("roomInfo.Name");
        });
        cell.transform.SetParent(listContent);
    }
示例#13
0
    public object Clone()
    {
        RoomCell result = new RoomCell
        {
            Position = this.Position,
            Rotation = this.Rotation,
            MeshPath = this.MeshPath,
            Mesh     = this.Mesh,
            CellType = this.CellType
        };

        return(result);
    }
示例#14
0
 // Generates the grid
 protected void GenerateGrid()
 {
     for (int i = 0; i < size.x; i++)
     {
         for (int j = 0; j < size.z; j++)
         {
             RoomCell newCell = Instantiate(cell) as RoomCell;
             newCell.name = "Room Cell at " + i + ", " + j;
             newCell.gameObject.transform.GetChild(0).gameObject.GetComponent <Renderer>().material = floorMaterial;
             tileGrid[i, j]                  = newCell;
             newCell.transform.parent        = transform;
             newCell.transform.localPosition = new Vector3(i - size.x * 0.5f + 0.5f,
                                                           0f, j - size.z * 0.5f + 0.5f);
         }
     }
 }    // Generate
示例#15
0
    protected virtual void Start()
    {
        RoomCell c = RoomManager.Instance.GetCellFromWorld(transform.position);

        if (c == null)
        {
            Debug.LogError("This room object is outside of a room, disabling", gameObject);
        }
        else
        {
            _room = c.room;
            RoomManager.Instance.RegisterRoomObject(_room, this);
        }

        //disabling the room object, it will be reenabled when the room become active
        gameObject.SetActive(false);
    }
示例#16
0
    public void RemoveRoom(Room r)
    {
        Vector2Int originalCoord = cells[r.cell].coordinate;

        for (int y = 0; y < r.size.y; ++y)
        {
            for (int x = 0; x < r.size.x; ++x)
            {
                Vector2Int coord = originalCoord + new Vector2Int(x, y);

                RoomCell c = _cells[coord];
                c.room = -1;

                RoomCell leftcell = GetRoomCell(coord + Vector2Int.left);
                if (leftcell != null)
                {
                    leftcell.right = -1;
                }

                RoomCell rightcell = GetRoomCell(coord + Vector2Int.right);
                if (rightcell != null)
                {
                    rightcell.left = -1;
                }

                RoomCell topcell = GetRoomCell(coord + Vector2Int.up);
                if (topcell != null)
                {
                    topcell.down = -1;
                }

                RoomCell bottomcell = GetRoomCell(coord + Vector2Int.down);
                if (bottomcell != null)
                {
                    bottomcell.top = -1;
                }
            }
        }

        int idx = r.arrayIdx;

        rooms[idx] = null;
        UnityEditor.ArrayUtility.Add(ref freeRooms, idx);
    }
示例#17
0
    void ComputeRoomsWorldRect()
    {
        Vector2 worldPosition = transform.position;

        _roomWorldSize = new Vector2(RetroScreenSettings.instance.width / (float)RetroScreenSettings.instance.pixelPerUnits, RetroScreenSettings.instance.height / (float)RetroScreenSettings.instance.pixelPerUnits);

        for (int i = 0; i < rooms.Length; ++i)
        {
            if (rooms[i] == null)
            {
                continue;
            }

            RoomCell cell = cells[rooms[i].cell];
            rooms[i].worldRect = new Rect(
                worldPosition.x + cell.coordinate.x * _roomWorldSize.x,
                worldPosition.y + cell.coordinate.y * _roomWorldSize.y,
                _roomWorldSize.x * rooms[i].size.x,
                _roomWorldSize.y * rooms[i].size.y);
        }
    }
示例#18
0
    private void LateUpdate()
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return;
        }
#endif

        if (follow == null)
        {
            return;
        }

        RoomCell cell = RoomManager.Instance.GetCellFromWorld(follow.transform.position);

        if (cell == null)
        {
            Debug.LogError("target outside of the world");
        }
        else if (cell.room != currentRoom)
        {
            _inTransition = true;
            previousRoom  = currentRoom;
            currentRoom   = cell.room;

            RoomManager.Instance.SwitchRoomObject(currentRoom, true);

            if (onScreenTransition != null)
            {
                onScreenTransition(ScreenTransitionState.START);
            }
        }

        Vector3 position = follow.position - Vector3.forward * 5.0f;

        Rect cameraRect = new Rect(position.x - _camera.orthographicSize * _camera.aspect, position.y - _camera.orthographicSize, _camera.orthographicSize * 2.0f * _camera.aspect, _camera.orthographicSize * 2.0f);

        if (currentRoom != -1)
        {
            Rect roomRect = RoomManager.Instance.rooms[currentRoom].worldRect;

            if (cameraRect.xMin < roomRect.xMin)
            {
                cameraRect.position = new Vector2(roomRect.xMin, cameraRect.position.y);
            }

            if (cameraRect.yMin < roomRect.yMin)
            {
                cameraRect.position = new Vector2(cameraRect.position.x, roomRect.yMin);
            }

            if (cameraRect.xMax > roomRect.xMax)
            {
                cameraRect.position = new Vector2(roomRect.xMax - cameraRect.width, cameraRect.position.y);
            }

            if (cameraRect.yMax > roomRect.yMax)
            {
                cameraRect.position = new Vector2(cameraRect.position.x, roomRect.yMax - cameraRect.height);
            }

            float z = position.z;
            position   = cameraRect.center;
            position.z = z;
        }

        Vector3 finalPosition = position;
        if (_inTransition)
        {
            finalPosition = Vector3.MoveTowards(_truePosition, position, transitionSpeed * Time.deltaTime);
            if (position == finalPosition)
            {
                _inTransition = false;
                RoomManager.Instance.SwitchRoomObject(previousRoom, false);
                if (onScreenTransition != null)
                {
                    onScreenTransition(ScreenTransitionState.END);
                }
            }
        }

        _truePosition = finalPosition;

        transform.position = _truePosition;
    }
示例#19
0
    public void ExpandRoom(Room r, Vector2Int direction)
    {
        if (direction.x == 1)
        {
            for (int y = 0; y < r.size.y; ++y)
            {
                RoomCell   currentCell     = GetRoomCell(cells[r.cell].coordinate + Vector2Int.right * (r.size.x - 1) + Vector2Int.up * y);
                Vector2Int targetCellCoord = currentCell.coordinate + Vector2Int.right;

                RoomCell targetCell;
                if (!_cells.TryGetValue(targetCellCoord, out targetCell))
                {
                    targetCell = CreateCell(targetCellCoord);
                }

                targetCell.room = r.arrayIdx;

                SetupCellSurrounding(targetCell);
            }
        }
        else if (direction.x == -1)
        {
            //in the case of expanding to the left, we need to change the origin cell, as it should always be the bottom left one
            int newOriginCell = r.cell;
            for (int y = 0; y < r.size.y; ++y)
            {
                RoomCell   currentCell     = GetRoomCell(cells[r.cell].coordinate + Vector2Int.up * y);
                Vector2Int targetCellCoord = currentCell.coordinate + Vector2Int.left;

                RoomCell targetCell;
                if (!_cells.TryGetValue(targetCellCoord, out targetCell))
                {
                    targetCell = CreateCell(targetCellCoord);
                }

                if (y == 0)
                {
                    newOriginCell = targetCell.arrayIdx;
                }

                targetCell.room = r.arrayIdx;

                SetupCellSurrounding(targetCell);
            }

            r.cell = newOriginCell;
        }

        else if (direction.y == 1)
        {
            for (int x = 0; x < r.size.x; ++x)
            {
                RoomCell   currentCell     = GetRoomCell(cells[r.cell].coordinate + Vector2Int.up * (r.size.y - 1) + Vector2Int.right * x);
                Vector2Int targetCellCoord = currentCell.coordinate + Vector2Int.up;

                RoomCell targetCell;
                if (!_cells.TryGetValue(targetCellCoord, out targetCell))
                {
                    targetCell = CreateCell(targetCellCoord);
                }

                targetCell.room = r.arrayIdx;

                SetupCellSurrounding(targetCell);
            }
        }
        else if (direction.y == -1)
        {
            //in the case of expanding to the bottom, we need to change the origin cell, as it should always be the bottom left one
            int newOriginCell = r.cell;
            for (int x = 0; x < r.size.x; ++x)
            {
                RoomCell   currentCell     = GetRoomCell(cells[r.cell].coordinate + Vector2Int.right * x);
                Vector2Int targetCellCoord = currentCell.coordinate + Vector2Int.down;

                RoomCell targetCell;
                if (!_cells.TryGetValue(targetCellCoord, out targetCell))
                {
                    targetCell = CreateCell(targetCellCoord);
                }

                if (x == 0)
                {
                    newOriginCell = targetCell.arrayIdx;
                }

                targetCell.room = r.arrayIdx;

                SetupCellSurrounding(targetCell);
            }

            r.cell = newOriginCell;
        }

        r.size += new Vector2Int(Mathf.Abs(direction.x), Mathf.Abs(direction.y));
    }
示例#20
0
    static void SceneGUIGeneric(bool displayControls, RoomManager manager)
    {
        Vector3 screenSize = new Vector3(RetroScreenSettings.instance.width / (float)RetroScreenSettings.instance.pixelPerUnits, RetroScreenSettings.instance.height / (float)RetroScreenSettings.instance.pixelPerUnits, 0);

        int removeRoom = -1;

        for (int i = 0; i < manager.rooms.Length; ++i)
        {
            Room room = manager.rooms[i];
            if (room == null)
            {
                continue;
            }

            RoomCell originCell = manager.cells[room.cell];

            Rect r = new Rect(originCell.coordinate.x * screenSize.x, originCell.coordinate.y * screenSize.y, screenSize.x * room.size.x, screenSize.y * room.size.y);

            Handles.color = Color.red;
            Handles.DrawSolidRectangleWithOutline(r, new Color(0, 0, 0, 0), Color.red);

            Handles.color = Color.white;
            Handles.Label(r.center, i.ToString(), EditorStyles.whiteLargeLabel);

            if (!displayControls)
            {
                continue;
            }

            Handles.color = Color.red;
            if (Handles.Button(r.center, Quaternion.LookRotation(Vector3.forward), 0.2f, 0.2f, Handles.CircleHandleCap))
            {
                removeRoom = i;
            }

            bool leftExpand  = true;
            bool rightExpand = true;
            bool upExpand    = true;
            bool downExpand  = true;

            Handles.color = Color.green;
            for (int y = 0; y < room.size.y; ++y)
            {
                for (int x = 0; x < room.size.x; ++x)
                {
                    RoomCell cell = manager.GetRoomCell(originCell.coordinate + new Vector2Int(x, y));

                    Vector3 origin = (Vector3)r.min + Vector3.right * screenSize.x * x + Vector3.up * screenSize.y * y;

                    //left add
                    if (cell.left == -1)
                    {
                        if (Handles.Button(origin + Vector3.up * screenSize.y * 0.5f + Vector3.left * screenSize.x * 0.5f, Quaternion.LookRotation(Vector3.forward), 0.2f, 0.2f, Handles.RectangleHandleCap))
                        {
                            manager.AddRoom(new Vector2Int(cell.coordinate.x - 1, cell.coordinate.y));
                        }
                    }
                    else if (cell.left != room.arrayIdx)
                    {
                        leftExpand = false;
                    }

                    //down add
                    if (cell.down == -1)
                    {
                        if (Handles.Button(origin + Vector3.right * screenSize.x * 0.5f + Vector3.down * screenSize.y * 0.5f, Quaternion.LookRotation(Vector3.forward), 0.2f, 0.2f, Handles.RectangleHandleCap))
                        {
                            manager.AddRoom(new Vector2Int(cell.coordinate.x, cell.coordinate.y - 1));
                        }
                    }
                    else if (cell.down != room.arrayIdx)
                    {
                        downExpand = false;
                    }

                    //right add
                    if (cell.right == -1)
                    {
                        if (Handles.Button(origin + screenSize + Vector3.down * screenSize.y * 0.5f + Vector3.right * screenSize.x * 0.5f, Quaternion.LookRotation(Vector3.forward), 0.2f, 0.2f, Handles.RectangleHandleCap))
                        {
                            manager.AddRoom(new Vector2Int(cell.coordinate.x + room.size.x, cell.coordinate.y));
                        }
                    }
                    else if (cell.right != room.arrayIdx)
                    {
                        rightExpand = false;
                    }

                    //top add
                    if (cell.top == -1)
                    {
                        if (Handles.Button(origin + screenSize + Vector3.left * screenSize.x * 0.5f + Vector3.up * screenSize.y * 0.5f, Quaternion.LookRotation(Vector3.forward), 0.2f, 0.2f, Handles.RectangleHandleCap))
                        {
                            manager.AddRoom(new Vector2Int(cell.coordinate.x, cell.coordinate.y + room.size.y));
                        }
                    }
                    else if (cell.top != room.arrayIdx)
                    {
                        upExpand = false;
                    }
                }
            }



            //room extension

            Handles.color = Color.blue;

            if (rightExpand && Handles.Button((Vector3)r.center + Vector3.right * r.width * 0.4f, Quaternion.LookRotation(Vector3.right), 0.4f, 0.2f, Handles.ConeHandleCap))
            { // right
                manager.ExpandRoom(room, Vector2Int.right);
            }

            if (downExpand && Handles.Button((Vector3)r.center + Vector3.down * r.height * 0.4f, Quaternion.LookRotation(Vector3.down), 0.4f, 0.2f, Handles.ConeHandleCap))
            { // down
                manager.ExpandRoom(room, Vector2Int.down);
            }

            if (leftExpand && Handles.Button((Vector3)r.center + Vector3.left * r.width * 0.4f, Quaternion.LookRotation(Vector3.left), 0.4f, 0.2f, Handles.ConeHandleCap))
            { // left
                manager.ExpandRoom(room, Vector2Int.left);
            }

            if (upExpand && Handles.Button((Vector3)r.center + Vector3.up * r.height * 0.4f, Quaternion.LookRotation(Vector3.up), 0.4f, 0.2f, Handles.ConeHandleCap))
            { // up
                manager.ExpandRoom(room, Vector2Int.up);
            }
        }


        if (removeRoom != -1)
        {
            manager.RemoveRoom(manager.rooms[removeRoom]);
        }
    }
示例#21
0
    }     // makeWalls

    // Randomise the doors, and also the enter door (spawn point in this room)
    protected RoomCell[] GetDoors()
    {
        // Number of doors
        int numberOfDoors = Random.Range(1, 4);
        int spawnDoor     = Random.Range(0, numberOfDoors - 1);

        RoomCell[] doors = new RoomCell[numberOfDoors];
        IntVector2 coords;

        if (numberOfDoors > 0)
        {
            coords = new IntVector2(size.x - 1, Random.Range(2, size.z - 2));
            doors [--numberOfDoors] = GetCellAt(coords);
            // If this is the spawn door
            if (spawnDoor == numberOfDoors)
            {
                spawn = new IntVector2((int)GetCellAt(coords).gameObject.transform.position.x,
                                       (int)GetCellAt(coords).gameObject.transform.position.z);
            }            // if
        }
        if (numberOfDoors > 0)
        {
            coords = new IntVector2(Random.Range(2, size.x - 2), size.z - 1);
            doors [--numberOfDoors] = GetCellAt(coords);
            // If this is the spawn door
            if (spawnDoor == numberOfDoors)
            {
                spawn = new IntVector2((int)GetCellAt(coords).gameObject.transform.position.x,
                                       (int)GetCellAt(coords).gameObject.transform.position.z);
            }            // if
        }
        if (numberOfDoors > 0)
        {
            coords = new IntVector2(0, Random.Range(2, size.z - 2));
            doors [--numberOfDoors] = GetCellAt(coords);
            // If this is the spawn door
            if (spawnDoor == numberOfDoors)
            {
                spawn = new IntVector2((int)GetCellAt(coords).gameObject.transform.position.x,
                                       (int)GetCellAt(coords).gameObject.transform.position.z);
            }            // if
        }
        if (numberOfDoors > 0)
        {
            coords = new IntVector2(Random.Range(2, size.x - 2), 0);
            doors [--numberOfDoors] = GetCellAt(coords);
            // If this is the spawn door
            if (spawnDoor == numberOfDoors)
            {
                spawn = new IntVector2((int)GetCellAt(coords).gameObject.transform.position.x,
                                       (int)GetCellAt(coords).gameObject.transform.position.z);
            }            // if
        }


        // TODO : PUT DOORS ON WALLS
        foreach (RoomCell door in doors)
        {
            door.transform.GetChild(1).gameObject.GetComponent <WallControl>().door = true;
            //door.transform.GetChild(1).gameObject.GetComponent<MeshRenderer>().material.color = Color.blue;

            doorInstance = Instantiate(doorPrefab) as GameObject;
            doorInstance.transform.SetParent(door.transform.GetChild(1).gameObject.GetComponent <WallControl>().gameObject.transform);
            doorInstance.transform.localPosition = new Vector3(0f, 0f, -0.05f);
            doorInstance.transform.localRotation = Quaternion.Euler(new Vector3(0f, 180f, 0f));
            doorInstance.transform.localScale    = new Vector3(0.1f, 0.1f, 0.3f);
        }
        return(doors);
    }    // getDoors
        private void UpdateRoomsList(Hotel hotel, DateTime currentDateTime)
        {
            var experimentTimeRange = new TimeRange(
                _experiment.StartDateTime,
                _experiment.EndDateTime.AddDays(ExperimentConfig.ValidDaysAfterEnding)
                );

            _singleRoomCells.Clear();
            var singleRooms = hotel.GetAllRoomsByRoomType(RoomType.SINGLE);

            foreach (var room in singleRooms)
            {
                var newRoomCell = new RoomCell(
                    room.Number,
                    room.IsFree(currentDateTime),
                    room.BookedTimes,
                    room.GetRequestsCount(),
                    $"{room.GetOccupancyInPeriod(experimentTimeRange)}%"
                    );
                if (room.Number == _selectedRoomNumber)
                {
                    UpdateRoomInfo(newRoomCell);
                }
                _singleRoomCells.Add(newRoomCell);
            }

            _doubleRoomCells.Clear();
            var doubleRooms = hotel.GetAllRoomsByRoomType(RoomType.DOUBLE);

            foreach (var room in doubleRooms)
            {
                var newRoomCell = new RoomCell(
                    room.Number,
                    room.IsFree(currentDateTime),
                    room.BookedTimes,
                    room.GetRequestsCount(),
                    $"{room.GetOccupancyInPeriod(experimentTimeRange)}%"
                    );
                if (room.Number == _selectedRoomNumber)
                {
                    UpdateRoomInfo(newRoomCell);
                }
                _doubleRoomCells.Add(newRoomCell);
            }

            _doubleWithSofaRoomCells.Clear();
            var doubleWithSofaRooms = hotel.GetAllRoomsByRoomType(RoomType.DOUBLE_WITH_SOFA);

            foreach (var room in doubleWithSofaRooms)
            {
                var newRoomCell = new RoomCell(
                    room.Number,
                    room.IsFree(currentDateTime),
                    room.BookedTimes,
                    room.GetRequestsCount(),
                    $"{room.GetOccupancyInPeriod(experimentTimeRange)}%"
                    );
                if (room.Number == _selectedRoomNumber)
                {
                    UpdateRoomInfo(newRoomCell);
                }
                _doubleWithSofaRoomCells.Add(newRoomCell);
            }

            _juniorSuiteRoomCells.Clear();
            var juniorSuiteRooms = hotel.GetAllRoomsByRoomType(RoomType.JUNIOR_SUITE);

            foreach (var room in juniorSuiteRooms)
            {
                var newRoomCell = new RoomCell(
                    room.Number,
                    room.IsFree(currentDateTime),
                    room.BookedTimes,
                    room.GetRequestsCount(),
                    $"{room.GetOccupancyInPeriod(experimentTimeRange)}%"
                    );
                if (room.Number == _selectedRoomNumber)
                {
                    UpdateRoomInfo(newRoomCell);
                }
                _juniorSuiteRoomCells.Add(newRoomCell);
            }

            _suiteRoomCells.Clear();
            var suiteRooms = hotel.GetAllRoomsByRoomType(RoomType.SUITE);

            foreach (var room in suiteRooms)
            {
                var newRoomCell = new RoomCell(
                    room.Number,
                    room.IsFree(currentDateTime),
                    room.BookedTimes,
                    room.GetRequestsCount(),
                    $"{room.GetOccupancyInPeriod(experimentTimeRange)}%"
                    );
                if (room.Number == _selectedRoomNumber)
                {
                    UpdateRoomInfo(newRoomCell);
                }
                _suiteRoomCells.Add(newRoomCell);
            }
        }
    // Randomise the doors, and also the enter door (spawn point in this room)
    protected RoomCell[] GetDoors()
    {
        // Number of doors
        int numberOfDoors = Random.Range (1, 4);
        int spawnDoor = Random.Range(0, numberOfDoors-1);
        RoomCell[] doors = new RoomCell[numberOfDoors];
        IntVector2 coords;

        if (numberOfDoors > 0) {
            coords = new IntVector2 (size.x-1, Random.Range (2, size.z - 2));
            doors [--numberOfDoors] = GetCellAt (coords);
            // If this is the spawn door
            if (spawnDoor == numberOfDoors) {
                spawn = new IntVector2 ((int)GetCellAt (coords).gameObject.transform.position.x,
                                        (int)GetCellAt (coords).gameObject.transform.position.z);
            }// if
        }
        if (numberOfDoors > 0) {
            coords = new IntVector2 (Random.Range (2, size.x - 2), size.z-1);
            doors [--numberOfDoors] = GetCellAt (coords);
            // If this is the spawn door
            if (spawnDoor == numberOfDoors) {
                spawn = new IntVector2 ((int)GetCellAt (coords).gameObject.transform.position.x,
                                        (int)GetCellAt (coords).gameObject.transform.position.z);
            }// if
        }
        if (numberOfDoors > 0) {
            coords = new IntVector2 (0, Random.Range (2, size.z - 2));
            doors [--numberOfDoors] = GetCellAt (coords);
            // If this is the spawn door
            if (spawnDoor == numberOfDoors) {
                spawn = new IntVector2 ((int)GetCellAt (coords).gameObject.transform.position.x,
                                        (int)GetCellAt (coords).gameObject.transform.position.z);
            }// if
        }
        if (numberOfDoors > 0) {
            coords = new IntVector2 (Random.Range (2, size.x - 2), 0);
            doors [--numberOfDoors] = GetCellAt (coords);
            // If this is the spawn door
            if (spawnDoor == numberOfDoors) {
                spawn = new IntVector2 ((int)GetCellAt (coords).gameObject.transform.position.x,
                                        (int)GetCellAt (coords).gameObject.transform.position.z);
            }// if
        }

        // TODO : PUT DOORS ON WALLS
        foreach (RoomCell door in doors) {
            door.transform.GetChild(1).gameObject.GetComponent<WallControl>().door = true;
            //door.transform.GetChild(1).gameObject.GetComponent<MeshRenderer>().material.color = Color.blue;

            doorInstance = Instantiate(doorPrefab) as GameObject;
            doorInstance.transform.SetParent(door.transform.GetChild(1).gameObject.GetComponent<WallControl>().gameObject.transform);
            doorInstance.transform.localPosition = new Vector3(0f, 0f, -0.05f);
            doorInstance.transform.localRotation = Quaternion.Euler(new Vector3(0f, 180f, 0f));
            doorInstance.transform.localScale = new Vector3(0.1f, 0.1f, 0.3f);
        }
        return doors;
    }
示例#24
0
    private void LateUpdate()
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return;
        }
#endif

        if (follow == null)
        {
            return;
        }

        RoomCell cell = RoomManager.Instance.GetCellFromWorld(follow.transform.position);

        if (cell == null)
        {
            Debug.LogError("target outside of the world");
        }
        else if (cell.room != currentRoom)
        {
            if (transitionType != TransitionType.INSTANT)
            {
                _inTransition = true;

                _previousTimeScale = Time.timeScale;
                Time.timeScale     = freezeTimeDuringTransition ? 0.0f : Time.timeScale;
            }

            currentRoom = cell.room;
            if (onScreenTransition != null)
            {
                onScreenTransition(ScreenTransitionState.START);
            }
        }

        Vector3 position = follow.position - Vector3.forward * 5.0f;

        Rect cameraRect = new Rect(position.x - _camera.orthographicSize * _camera.aspect, position.y - _camera.orthographicSize, _camera.orthographicSize * 2.0f * _camera.aspect, _camera.orthographicSize * 2.0f);

        if (currentRoom != -1)
        {
            Rect roomRect = RoomManager.Instance.rooms[currentRoom].worldRect;

            if (cameraRect.xMin < roomRect.xMin)
            {
                cameraRect.position = new Vector2(roomRect.xMin, cameraRect.position.y);
            }

            if (cameraRect.yMin < roomRect.yMin)
            {
                cameraRect.position = new Vector2(cameraRect.position.x, roomRect.yMin);
            }

            if (cameraRect.xMax > roomRect.xMax)
            {
                cameraRect.position = new Vector2(roomRect.xMax - cameraRect.width, cameraRect.position.y);
            }

            if (cameraRect.yMax > roomRect.yMax)
            {
                cameraRect.position = new Vector2(cameraRect.position.x, roomRect.yMax - cameraRect.height);
            }

            float z = position.z;
            position   = cameraRect.center;
            position.z = z;
        }

        //position.x = Mathf.RoundToInt(position.x / _pixelSize) * _pixelSize;
        //position.y = Mathf.RoundToInt(position.y / _pixelSize) * _pixelSize;

        if (_inTransition)
        {
            switch (transitionType)
            {
            case TransitionType.MOVING:
                MovingTransition(position);
                break;

            case TransitionType.FADE:
                break;

            default:
                break;
            }
        }
        else
        {
            transform.position = position;
        }
    }