Exemplo n.º 1
0
        public void RoomEntered(Collider collider)
        {
            PlayerController player = collider.GetComponent <PlayerController>();

            if (player)
            {
                _isClosed = true;
                OnRoomEntered?.Invoke(this);
            }
        }
Exemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == playerTag)
        {
            CameraController.instance.ChangeTarget(transform);

            if (!roomComplete && closedWhenEntered)
            {
                CloseDoors();
                OnAnyRoomEntered?.Invoke(this);
                OnRoomEntered?.Invoke(other.GetComponent <Health>());
            }
        }
    }
Exemplo n.º 3
0
    private void UpdateLoop()
    {
        var hits = Physics2D.OverlapBoxAll(transform.position, transform.localScale, transform.eulerAngles.z);

        if (hits.Length <= 0)
        {
            foreach (GameObject obj in objectsInsideRoom.ToList())
            {
                RemoveFromRoom(obj);
            }

            return;
        }

        if (hits.Length == 1)
        {
            var hit = hits[0].gameObject;

            bool clearObjects = objectsInsideRoom.Count > 1 || objectsInsideRoom.Count > 0 && objectsInsideRoom[0] != hit;
            if (clearObjects)
            {
                foreach (GameObject obj in objectsInsideRoom.ToList())
                {
                    bool isHit = hit == obj;
                    if (!isHit)
                    {
                        RemoveFromRoom(obj);
                    }
                }
            }

            AddToRoom(hit.gameObject);

            return;
        }

        // hits.Lenght > 1
        var hitObjects = new List <GameObject>();

        foreach (Collider2D hitCollider in hits)
        {
            var hit = hitCollider.gameObject;
            AddToRoom(hit);

            hitObjects.Add(hit);
        }

        foreach (GameObject obj in objectsInsideRoom.ToList())
        {
            bool isNoLongerInRoom = !hitObjects.Contains(obj);
            if (isNoLongerInRoom)
            {
                RemoveFromRoom(obj);
            }
        }

        void RemoveFromRoom(GameObject obj)
        {
            if (!IsInRoom(obj))
            {
                return;
            }

            OnObjectExit.Invoke(obj);
            OnRoomExited?.Invoke(this, obj);
            objectsInsideRoom.Remove(obj);
        }

        void AddToRoom(GameObject obj)
        {
            if (IsInRoom(obj))
            {
                return;
            }

            OnObjectEnter.Invoke(obj);
            OnRoomEntered?.Invoke(this, obj);
            objectsInsideRoom.Add(obj);
        }

        bool IsInRoom(GameObject obj) => objectsInsideRoom.Contains(obj);
    }
Exemplo n.º 4
0
 public void RoomEntered()
 {
     _isClosed = true;
     OnRoomEntered?.Invoke(this);
 }