示例#1
0
    private List <BuildingSegment> GenerateFloor(int level)
    {
        List <BuildingSegment> newFloor = new List <BuildingSegment>();
        float floorWidth = 0;

        for (int i = 0; i < floor.Segments[level].segments.Count; ++i)
        {
            FloorSegmentType segmentType = floor.Segments[level].segments[i];
            if (level == 0 && segmentType == FloorSegmentType.stairsDown)
            {
                segmentType = FloorSegmentType.empty;
            }
            if (level == floorsNumber - 1 && segmentType == FloorSegmentType.stairsUp)
            {
                segmentType = FloorSegmentType.empty;
            }

            BuildingSegment segment = Instantiate(floor.GetSegmentPrefab(segmentType), buildingParent);
            segment.transform.localPosition = new Vector3(floorWidth + segment.GetRoomWidth() / 2, ((float)level + .5f) * segment.GetSegmentHeight());
            segment.SetApartmentRoomBounds(segment.transform.position.x + segment.GetHallWidth() / 2 - segment.GetSegmentWidth() / 2 + 1.5f, segment.transform.position.x + segment.GetHallWidth() / 2 + segment.GetSegmentWidth() / 2 - 3);

            newFloor.Add(segment);
            floorWidth += segment.GetSegmentWidth();
        }

        for (int i = 0; i < newFloor.Count; ++i)
        {
            newFloor[i].SetApartmentCorridorBounds(0, floorWidth);
        }

        return(newFloor);
    }
示例#2
0
    public Apartment GetUpperNeighbour(Apartment apartment)
    {
        BuildingSegment segment    = apartment.GetComponentInParent <BuildingSegment>();
        int             floorIndex = GetFloorIndex(segment);

        if (floorIndex < 0)
        {
            return(null);
        }
        int apartmentIndex = GetApartmentIndexInFloor(floorIndex, segment);

        if (apartmentIndex < 0)
        {
            return(null);
        }

        if (building.Count <= floorIndex + 1)
        {
            return(null);
        }

        BuildingSegment upperNeighbourSegment = building[floorIndex + 1][apartmentIndex];

        return(upperNeighbourSegment.GetComponentInChildren <Apartment>());
    }
示例#3
0
    void SpawnPlayer()
    {
        GameObject playerGO = Instantiate(gameManager.playerPrefab);
        Player     player   = playerGO.GetComponent <Player>();

        player.Init();
        BuildingSegment buildingSegment = building[0][1];

        buildingSegment.apartmentRoom.Enter(player);
        player.transform.position = buildingSegment.apartmentRoom.floorTransform.position;
    }
示例#4
0
 void SpawnItems()
 {
     for (int i = 0; i < gameManager.itemPrefabs.Length; i++)
     {
         GameObject      itemGO          = Instantiate(gameManager.itemPrefabs[i]);
         BuildingSegment buildingSegment = building[0][1];
         Item            item            = itemGO.GetComponent <Item>();
         itemGO.transform.position = buildingSegment.apartmentRoom.floorTransform.position;
         itemGO.transform.Translate(new Vector3((float)3 * (1 - i), item.yOffset, 0f));
         item.currentApartment = buildingSegment.GetComponentInChildren <Apartment>();
     }
 }
示例#5
0
 int GetFloorIndex(BuildingSegment segment)
 {
     for (int i = 0; i < building.Count; i++)
     {
         List <BuildingSegment> floor = building[i];
         if (floor.Contains(segment))
         {
             return(i);
         }
     }
     return(-1);
 }
示例#6
0
    int GetApartmentIndexInFloor(int floorIndex, BuildingSegment segment)
    {
        List <BuildingSegment> floor = building[floorIndex];

        for (int i = 0; i < floor.Count; i++)
        {
            if (floor[i] == segment)
            {
                return(i);
            }
        }
        return(-1);
    }