void Update() { //press o to save if (Input.GetKeyDown(KeyCode.O) && debugMode) { Texture2D tex = new Texture2D(width, height); GameObject[] debugcubes = GameObject.FindGameObjectsWithTag("debugCubePathfinding"); foreach (GameObject cube in debugcubes) { pathfindingDebugInfoholder pdi = cube.GetComponent <pathfindingDebugInfoholder>(); float f = System.Convert.ToInt32(!pdi.closed); tex.SetPixel((int)pdi.place.x, (int)pdi.place.y, new Color(0f, f, 0f)); } byte[] bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/../pathfindingdebugimage.png", bytes); } }
//debug funktion som skapar en kub på varje node position och byter färge på de som är closed public void createDebugNodes() { GameObject empty = new GameObject(); GameObject cubeparent = Instantiate(empty, Vector3.zero, Quaternion.identity) as GameObject; cubeparent.name = "debuggrid"; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { GameObject cube = Instantiate(debugNodePrefab, gridposToWorld(map[x, y].pos), Quaternion.identity) as GameObject; cube.transform.parent = cubeparent.transform; cube.tag = "debugCubePathfinding"; pathfindingDebugInfoholder pdi = cube.AddComponent("pathfindingDebugInfoholder") as pathfindingDebugInfoholder; pdi.place = new Vector2(x, y); pdi.closed = map[x, y].Closed; pdi.updColor(); //debugcubes.Add(cube); //if(map[x,y].Closed || map[x,y].Used){ // cube.renderer.material = debugMat1; //} } } }