/// <summary> /// Start is called on the frame when a script is enabled just before /// any of the Update methods is called the first time. /// </summary> void Start() { AStarPoint[,] array = new AStarPoint[(int)128, (int)64]; for (int i = 0; i < array.GetLength(0); ++i) { for (int j = 0; j < array.GetLength(1); ++j) { var obj = GameObject.Instantiate(m_Rect); obj.SetActive(true); obj.transform.SetParent(transform); obj.transform.localScale = Vector3.one; obj.GetComponent <RectTransform>().anchoredPosition = new Vector2(i * 10, j * 10); var img = obj.GetComponent <Image>(); array[i, j] = new AStarPoint(i, j); array[i, j].Value = m_Txt.GetPixel(i, j) == Color.white?0:1; array[i, j].Position = obj.GetComponent <RectTransform>().anchoredPosition; img.color = array[i, j].Value == 0?Color.white:Color.black; } } AStarMap map = new AStarMap(new AStarMapData(array)); float t = Time.time; //var rst = map.GetPath(new AStarNode(1,1),new AStarNode(6,10),false); AStar.GetInstance().FindPathAsyn(map, new AStarNode(10, 10), new AStarNode(115, 32), true, (e) => { print("1cost time " + (Time.time - t)); StartCoroutine(showPath(e, map)); }); AStar.GetInstance().FindPathAsyn(map.Clone(), new AStarNode(11, 9), new AStarNode(115, 8), true, (e) => { print("2cost time " + (Time.time - t)); StartCoroutine(showPath(e, map)); }); AStar.GetInstance().FindPathAsyn(map.Clone(), new AStarNode(17, 23), new AStarNode(66, 8), true, (e) => { print("3cost time " + (Time.time - t)); StartCoroutine(showPath(e, map)); }); AStar.GetInstance().FindPathAsyn(map.Clone(), new AStarNode(66, 7), new AStarNode(15, 22), true, (e) => { print("4cost time " + (Time.time - t)); StartCoroutine(showPath(e, map)); }); AStar.GetInstance().FindPathAsyn(map.Clone(), new AStarNode(115, 31), new AStarNode(11, 11), true, (e) => { print("5cost time " + (Time.time - t)); StartCoroutine(showPath(e, map)); }); }
void OnMouseClickHandler(CirclePointSprite sprite) { float ti = Time.time; AStar.GetInstance().FindPathAsyn(map.Clone(), new Vector3(2, 2.4f, 0), sprite.transform.localPosition, 0, true, (e) => { print("cost time " + (Time.time - ti)); StartCoroutine(showPath(e, map)); }); }