Esempio n. 1
0
    void Start()
    {
        prevParam = 0.0f;
        manager   = GetComponent <SteeringManagerComponent>();
        Heuristic heuristic = new EuclideanHeuristic();

        finder   = new ASearch(heuristic.Heuristic);
        follower = new CoherentPathFollower();
        manager[moveBehavior].SetEnabled(false);
        manager[moveBehavior].SetFloat("ArriveRadius", lookAhead * 0.75f);
        target = new PointActor(Vector3.zero);
        manager[moveBehavior].SetActor("Target", target);
    }
Esempio n. 2
0
    private void Start()
    {
        var pathHeuristic = new EuclideanHeuristic();
        var graph         = new TilemapGraph(_tilemap);
        var graphNodeCost = new NodeCostChainOfResponsibilities(new List <IGraphNodeCost>
        {
            new ObstacleGraphNodeCost(_obstacles),
            new FloorGraphNodeCost(_tilemap)
        });

        _pathFinder             = new PathFinder(graph, graphNodeCost, pathHeuristic);
        _reevaluatePathInterval = 3;
    }
    void Start()
    {
        prevParam = 0.0f;
        manager = GetComponent<SteeringManagerComponent>();
        Heuristic heuristic = new EuclideanHeuristic();

        finder = new ASearch(heuristic.Heuristic);
        follower = new CoherentPathFollower();
        manager[moveBehavior].SetEnabled(false);
        manager[moveBehavior].SetFloat("ArriveRadius", lookAhead * 0.75f);
        target = new PointActor(Vector3.zero);
        manager[moveBehavior].SetActor("Target", target);
    }
    // Use this for initialization
    void Start()
    {
        this.draw = false;
        this.currentClickNumber = 1;
        this.navMesh = NavigationManager.Instance.NavMeshGraphs [0];

        IHeuristic heuristic = null;

        switch (Heuristic)
        {
            case HeuristicType.Zero:
                heuristic = new ZeroHeuristic();
                break;
            case HeuristicType.Euclidean:
                heuristic = new EuclideanHeuristic();
                break;
            default:
                break;
        }

        this.aStarPathFinding = new AStarPathfinding(this.navMesh, new SimpleUnorderedNodeList(), new HashTableNodeList(), heuristic);
    }
    public void FindPath()
    {
        StopCoroutine("FollowPathCoroutine");
        Node fromNode = graph.FindNodeFromWorldPosition(transform.position);
        Node goalNode = graph.FindNodeFromWorldPosition(goal.position);
        EuclideanHeuristic euclideanH = new EuclideanHeuristic(goalNode);

        Stopwatch timer = new Stopwatch();

        if (list)
        {
            // List + Euclidean
            timer.Start();
            for (int i = 0; i < repeatCount; i++)
            {
                path = new PathfinderList(graph).PathFindAStar(fromNode, goalNode, euclideanH);
            }
            timer.Stop();
            Debug.Log("[List + Euclidean] Pathfinding took: " + timer.ElapsedMilliseconds + "ms");
            timer.Reset();
        }

        if (heapEuclidean)
        {
            // Heap + Euclidean
            timer.Start();
            for (int i = 0; i < repeatCount; i++)
            {
                path = new PathfinderHeap(graph, true).PathFindAStar(fromNode, goalNode, euclideanH);
            }
            timer.Stop();
            Debug.Log("[Heap + Euclidean] Pathfinding took: " + timer.ElapsedMilliseconds + "ms");
            timer.Reset();
        }

        if (heapCluster)
        {
            // Heap + Cluster
            ClusterHeuristic clusterH;
            if (heuristic == null)
            {
                clusterH = new ClusterHeuristic(goalNode, graph);
            }
            else
            {
                clusterH = (ClusterHeuristic)heuristic;
            }
            timer.Start();
            if (clusterH.CanReach(fromNode))
            {
                for (int i = 0; i < repeatCount; i++)
                {
                    path = new PathfinderHeap(graph, true).PathFindAStar(fromNode, goalNode, clusterH);
                }
            }
            else
            {
                path = null;
            }
            timer.Stop();
            Debug.Log("[Heap + Cluster] Pathfinding took: " + timer.ElapsedMilliseconds + "ms");
            timer.Reset();
            heuristic = clusterH;
        }

        if (nodeArray)
        {
            // Heap + Euclidean + Node Array
            timer.Start();
            for (int i = 0; i < repeatCount; i++)
            {
                path = new PathfinderHeapNodeArray(graph).PathFindAStar(fromNode, goalNode, euclideanH);
            }
            timer.Stop();
            Debug.Log("[Heap + Euclidean + Node Array] Pathfinding took: " + timer.ElapsedMilliseconds + "ms");
            timer.Reset();
        }
        if (heuristic == null)
        {
            heuristic = euclideanH;
        }
    }