Exemplo n.º 1
0
    HallSection SpawnHall(ZDir direction)
    {
        Vector3 loc;

        if (direction.IsPositive())
        {
            loc = halls[frontierPos].transform.position + Vector3.forward * HallSection.ZLength;
        }
        else
        {
            loc = halls[frontierNeg].transform.position + Vector3.back * HallSection.ZLength;
        }
        var hall = Instantiate(HallObject, loc, Quaternion.identity);

        hall.TriggerHandler  += HallTriggerHandler;
        hall.transform.parent = transform;

        if (direction.IsPositive())
        {
            halls[++frontierPos] = hall;
        }
        else
        {
            halls[--frontierNeg] = hall;
        }

        return(hall);
    }
Exemplo n.º 2
0
    // this REQUIRES that the memos are placed in such a way that players can NEVER pick them up from inside the trigger zone
    IEnumerator roomSwitch()
    {
        // close door
        doorClosing = true;
        Door.Instance.TryCloseDoor();
        yield return(new WaitWhile(() => Door.Instance.Open));

        doorClosing = false;

        // switch rooms
        currentRoom.Despawn();
        if (destroyCurrentRoomOnSwitch)
        {
            destroyCurrentRoomOnSwitch = false;
            Destroy(currentRoom.gameObject);             // ... onSwitch
        }

        currentRoom    = waitingRoom;
        currentRoomDir = currentRoomDir.Flipped();

        if (pooledRooms.Count > 0)
        {
            nextRoomIndex = (int)Mathf.Repeat(nextRoomIndex + 1, pooledRooms.Count);
            var nextPrefab = pooledRooms[nextRoomIndex];
            waitingRoom = nextPrefab.Respawn(currentRoomDir.Flipped());
        }

        nextIsBedroom = false;

        currentRoomTrigger = currentRoomDir.IsPositive() ? FrontTrigger : BackTrigger;
        waitingRoomTrigger = currentRoomDir.IsNegative() ? FrontTrigger : BackTrigger;
    }
Exemplo n.º 3
0
    // moves an already instantiated room
    public Room Respawn(ZDir direction)
    {
        switchLights(true);

        if (twin != null)
        {
            return(twin);
        }

        if (spawned)
        {
            Room twinning = Initialize(this, direction);

            twinning.twin = this;
            twin          = twinning;

            return(twin);
        }

        spawned = true;

        transform.position    = Vector3.zero;
        transform.eulerAngles = new Vector3(0, direction.IsNegative() ? 0 : 180, 0);

        return(this);
    }
Exemplo n.º 4
0
    // define the direction of the room as the direction you face when walking into it
    public static Room Initialize(Room room, ZDir direction)
    {
        room.spawned = true;

        var r = Instantiate(room);

        r.transform.eulerAngles = new Vector3(0, direction.IsNegative() ? 0 : 180, 0);
        return(r);
    }
Exemplo n.º 5
0
 public static ZDir Flipped(this ZDir original)
 {
     if (original == ZDir.Positive)
     {
         return(ZDir.Negative);
     }
     else
     {
         return(ZDir.Positive);
     }
 }
Exemplo n.º 6
0
    public void Initialize(ZDir direction)
    {
        initialized = true;

        Memo.MemoPickedUp += onMemoPickedUp;

        Vector3 pos = transform.position + (direction.IsPositive() ? Vector3.forward : Vector3.back) * HallSection.ZLength / 2;

        halls    = new Dictionary <int, HallSection>(MaxSections);
        halls[0] = Instantiate(HallObject, pos, Quaternion.identity);
        halls[0].TriggerHandler  += HallTriggerHandler;
        halls[0].transform.parent = transform;

        for (int i = 1; i < MaxSections; i++)
        {
            SpawnHall(direction);
        }
    }
Exemplo n.º 7
0
 public static bool IsNegative(this ZDir query)
 {
     return(query == ZDir.Negative);
 }
Exemplo n.º 8
0
 public static bool IsPositive(this ZDir query)
 {
     return(query == ZDir.Positive);
 }
Exemplo n.º 9
0
        private Point3[] GetOcclusionMapping(Dominant dominant, XDir xDir, YDir yDir, ZDir zDir)
        {
            if (dominant == Dominant.X)
            {
                return(new[]
                {
                    new Point3((int)xDir, 0, (int)zDir),
                    new Point3((int)xDir, (int)yDir, 0),
                    new Point3((int)xDir, (int)yDir, (int)zDir),
                });
            }

            if (dominant == Dominant.Y)
            {
                return(new[]
                {
                    new Point3(0, (int)yDir, (int)zDir),
                    new Point3((int)xDir, (int)yDir, 0),
                    new Point3((int)xDir, (int)yDir, (int)zDir),
                });
            }

            if (dominant == Dominant.Z)
            {
                return(new[]
                {
                    new Point3(0, (int)yDir, (int)zDir),
                    new Point3((int)xDir, 0, (int)zDir),
                    new Point3((int)xDir, (int)yDir, (int)zDir),
                });
            }

            throw new NotSupportedException();
        }
Exemplo n.º 10
0
 private int GetOcclusion(Dominant dominant, XDir xDir, YDir yDir, ZDir zDir)
 {
     return(CalculateOcclusion(GetOcclusionValues(GetOcclusionMapping(dominant, xDir, yDir, zDir))));
 }