Exemple #1
0
        public Pathfinder(Vector3 startPosition, Vector3 targetPosition, AIController pathRequester, PathfinderManager.PathfindingComplete callback = null)
        {
            _gridGenerator = GridGenerator.GetInstance();
            _gridGenerator.startPosition = startPosition;
            _gridGenerator.endPosition   = targetPosition;

            start  = _gridGenerator.NodeFromWorldPosition(startPosition);
            target = _gridGenerator.NodeFromWorldPosition(targetPosition);

            _pathRequester = pathRequester;
            _callback      = callback;
        }
Exemple #2
0
        public bool IsPointWithinPlayableArea(Vector2 testPoint, bool testNotOnCharacter = false)
        {
            var boundsGameObject = GameObject.FindGameObjectsWithTag("MapBounds");

            if (boundsGameObject.Length > 0)
            {
                foreach (var boundsFound in boundsGameObject)
                {
                    var            applicableBounds       = boundsFound.GetComponents <BoxCollider2D>();
                    List <Vector2> tempResults            = new List <Vector2>();
                    bool           containedWithinABounds = false;

                    foreach (var bound in applicableBounds)
                    {
                        if (bound.bounds.Contains(testPoint))
                        {
                            containedWithinABounds = true;
                            break;
                        }
                    }

                    if (testNotOnCharacter)
                    {
                        var allCharacters = GameObject.FindObjectsOfType <ActorStats>();

                        if (allCharacters.Any(actor =>
                                              ((Vector2)actor.gameObject.transform.position - testPoint).magnitude <= 0.2f))
                        {
                            return(false);
                        }
                    }

                    if (containedWithinABounds)
                    {
                        var tempNode = GridGenerator.GetInstance()?.NodeFromWorldPosition(testPoint);

                        return(tempNode != null && !tempNode.obstructed);
                    }
                }
            }

            return(false);
        }
        public List <Node> FindPath()
        {
            gridGenerator = GridGenerator.GetInstance();

            return(FindPathActual(start, end));
        }