Esempio n. 1
0
        // проверка на возможность прохода из from в to
        private bool CanPass(Vector2Int from, Vector2Int to)
        {
            if (!m_Grid.HasNode(from))
            {
                return(false);
            }

            if (!m_Grid.HasNode(to) || m_Grid.GetNode(to).IsOccupied)
            {
                return(false);
            }

            Vector2Int diff = to - from;
            Vector2Int neighbour;

            if (diff.x != 0)
            {
                neighbour = from + new Vector2Int(diff.x, 0);
                if (m_Grid.HasNode(neighbour) && m_Grid.GetNode(neighbour).IsOccupied)
                {
                    return(false);
                }
            }

            if (diff.y != 0)
            {
                neighbour = from + new Vector2Int(0, diff.y);
                if (m_Grid.HasNode(neighbour) && m_Grid.GetNode(neighbour).IsOccupied)
                {
                    return(false);
                }
            }

            return(true);
        }