Esempio n. 1
0
        void Update()
        {
            Vector2 _viewSource;

            if (ViewOrigin != null)
            {
                _viewSource = ViewOrigin.position;
            }
            else
            {
                _viewSource = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            }

            foreach (RoomVisiblility room in RoomVisiblility.allRooms)
            {
                Profiler.BeginSample("Check Origin Room");
                bool isInRoom = RoomVisiblility.ContainsPt(room, _viewSource);
                Profiler.EndSample();
                if (isInRoom)
                {
                    Profiler.BeginSample("Update View Mesh");
                    UpdateMesh(room.GenerateViewMeshData(_viewSource));
                    Profiler.EndSample();
                    break;
                }
            }
        }
Esempio n. 2
0
        public static bool ContainsPt(RoomVisiblility room, Vector2 point, float checkDistance = 20f)
        {
            Vector2 FarAway = new Vector2(room.transform.position.x, room.transform.position.y + checkDistance);
            Vector2 Dir     = (point - FarAway).normalized;

            int hits = 0;

            foreach (RaycastHit2D hit in Physics2D.LinecastAll(point, FarAway, room.ViewLayerMask))
            {
                if (hit.collider.gameObject == room.gameObject)
                {
                    hits++;
                    room.debugHit.Addd(hit.point, Color.black);
                }
            }

            return(hits % 2 != 0);
        }