예제 #1
0
        public static bool InLOS(Tile tile1, Tile tile2, float peekFactor, bool debugging = false)
        {
            Vector3 pos1 = tile1.GetPos();
            Vector3 pos2 = tile2.GetPos();

            if (peekFactor < 0)
            {
                peekFactor = GameControl.GetPeekFactor();
            }

            float   dist      = Vector3.Distance(pos2, pos1);
            Vector3 dir       = (pos2 - pos1).normalized;
            Vector3 dirO      = new Vector3(-dir.z, 0, dir.x).normalized;
            float   posOffset = GridManager.GetTileSize() * GridManager.GetGridToTileSizeRatio() * peekFactor;

            LayerMask mask = 1 << TBTK.GetLayerObstacleFullCover();        // | 1<<LayerManager.GetLayerObstacleHalfCover();

            bool flag = false;

            if (!LOSRaycast(pos1, dir, dist, mask, debugging))
            {
                if (debugging)
                {
                    flag = true;
                }
                else
                {
                    return(true);
                }
            }

            if (posOffset == 0)
            {
                return(flag);
            }

            if (!LOSRaycast(pos1 + dirO * posOffset, dir, dist, mask, debugging))
            {
                if (debugging)
                {
                    flag = true;
                }
                else
                {
                    return(true);
                }
            }
            if (!LOSRaycast(pos1 - dirO * posOffset, dir, dist, mask, debugging))
            {
                if (debugging)
                {
                    flag = true;
                }
                else
                {
                    return(true);
                }
            }

            return(flag);
        }