using UnityEngine;
using System.Collections.Generic;
namespace Pathfinding.Examples {
    [RequireComponent(typeof(
Seeker))]
 
    public class EndingCondition : MonoBehaviour {
        public int hLimit = 1000;
        public Transform targetPoint;
        void Start () {
            Seeker seeker = GetComponent<Seeker>();
 
            
            XPath p = XPath.Construct(transform.position, targetPoint.position, null);
            p.endingCondition = new CustomEndingCondition(p, hLimit);
            
            Debug.DrawLine(transform.position, targetPoint.position, Color.black);
        }
        public class CustomEndingCondition : ABPathEndingCondition {
            public int hLimit = 10000;
            public CustomEndingCondition (ABPath path, int lim) : base(path) {
                hLimit = lim;
            }
            public override bool TargetFound (PathNode node) {
                return node.H < hLimit || node.node == abPath.endNode;
            }
        }
        public void OnPathComplete (Path p) {
            Debug.Log("Got Callback");
            if (p.error) {
                Debug.Log("Ouch, the path returned an error");
                return;
            }
            List<Vector3> path = p.vectorPath;
            for (int j = 0; j < path.Count-1; j++) {
                
                Debug.DrawLine(path[j], path[j+1], AstarMath.IntToColor(1, 0.5F), 1);
            }
        }
    }
}