Esempio n. 1
0
    ///** Creates and returns a rect that's JUST made up of these rooms. */
    //public Rect GetBoundsOfRooms (string[] _roomKeys) {
    //    Rect returnRect = new Rect (0,0, 0,0);
    //    for (int i=0; i<_roomKeys.Length; i++) {
    //        RoomData rd = GetRoomData (_roomKeys [i]);
    //        if (rd == null) { Debug.LogError ("Oops! This room doesn't exist in this world! " + _roomKeys[i] + ", world " + worldIndex); continue; }
    //        returnRect = MathUtils.GetCompoundRect (returnRect, rd.BoundsGlobalBL);
    //    }
    //    return returnRect;
    //}


    public RoomData GetRoomNeighbor(RoomData originLD, RoomOpening opening)
    {
        // Get the neighbor, ignoring ITS openings.
        RoomData neighbor = GetRoomAtSide(originLD, opening.posCenter, opening.side);

        if (neighbor == null)
        {
            return(null);
        }                                      // NOTHing there? Return null!
        // Ok, if this neighbor HAS a corresponding opening, return it!!
        Rect opRect = opening.GetCollRectGlobal(originLD.PosGlobal);

        for (int i = 0; i < neighbor.Openings.Count; i++)
        {
            Rect otherOpRect = neighbor.Openings[i].GetCollRectGlobal(neighbor.PosGlobal);
            if (opRect.Overlaps(otherOpRect))
            {
                return(neighbor);
            }
        }
        // Ah, NO corresponding opening. Return null.
        return(null);
    }