void Awake() { manager = GameObject.Find ("JPSManager").GetComponent<JPSManager>(); }
void Awake() { instance = this; pathfinding = GetComponent<JPSplus>(); Texture2D map = (Texture2D) Resources.Load("Levelmap"); gridSize.x = map.width; gridSize.y = map.height; precompute = new int[(int)gridSize.x,(int)gridSize.y][]; //if(File.Exists (fileName)){ // var sr = File.OpenText(fileName); JPValues = new int[(int)gridSize.x, (int)gridSize.y][]; GBValues = new Vector2[(int)gridSize.x, (int)gridSize.y][]; if (File.Exists (Application.dataPath + "/Resources/" + JPFile)){ StreamReader sr = File.OpenText(Application.dataPath + "/Resources/" + JPFile); string nodeInfo; for (int i = 0; i < gridSize.x; i++){ for (int j = 0; j < gridSize.y; j++){ nodeInfo = sr.ReadLine (); int[] nodeInfoArray = new int[8]; // 8 = each possible direction //nodeInfoArray = nodeInfo.Split(","[0]); string[] aux = nodeInfo.Split(','); // ReOrder nodeInfoArray[0] = int.Parse(aux[5]); //NW nodeInfoArray[1] = int.Parse(aux[3]); //N nodeInfoArray[2] = int.Parse(aux[6]); //NE nodeInfoArray[3] = int.Parse(aux[1]); //W nodeInfoArray[4] = int.Parse(aux[2]); //E nodeInfoArray[5] = int.Parse(aux[7]); //SW nodeInfoArray[6] = int.Parse(aux[4]); //S nodeInfoArray[7] = int.Parse(aux[8]); //SE precompute[j,i] = nodeInfoArray; JPValues[j,i] = nodeInfoArray; //navmesh[i,j] = map.GetPixel(i * map.width / gridSize.x, (gridSize.y - 1 - j) * map.height / gridSize.y).r >= 0.5f; } } } if (File.Exists(Application.dataPath + "/Resources/" + GBFile)) { StreamReader sr = File.OpenText(Application.dataPath + "/Resources/" + GBFile); string goalbound; for (int i = 0; i < gridSize.x; i++) { for (int j = 0; j < gridSize.y; j++) { goalbound = sr.ReadLine(); Vector2[] gbValues = new Vector2[16]; string[] aux = goalbound.Split('/'); for (int k = 1; k < 17; k++) { int startInd = aux[k].IndexOf("(") + 1; ; float aXPosition = float.Parse(aux[k].Substring(startInd, aux[k].IndexOf(",") - startInd)); startInd = aux[k].IndexOf(",") + 1; float aYPosition = float.Parse(aux[k].Substring(startInd, aux[k].IndexOf(")") - startInd)); gbValues[k-1] = new Vector2(aXPosition, aYPosition); } GBValues[j, i] = gbValues; } } } }