void Awake() { this.pathList = new List<GameObject> (); this.aStarUtils = new AStarUtils (this.cols, this.rows); // cols for(int i = 0; i < this.cols; i++) { // rows for(int j = 0; j < this.rows; j++) { AStarUnit aStarUnit = new AStarUnit(); if(i != 0 && j != 0 && Random.Range(1, 10) <= 3) { aStarUnit.isPassable = false; GameObject gameObject = (GameObject)Instantiate(cubeObject); if(gameObject != null) { gameObject.transform.localPosition = new Vector3(i - this.cols * 0.5f + 0.5f, 0f, j - this.cols * 0.5f + 0.5f); } }else{ aStarUnit.isPassable = true; } this.aStarUtils.GetNode(i,j).AddUnit(aStarUnit); } } }
public void LoadFromPD() { if (InitPathData() == false) { return; } GameObject map = GameObject.FindWithTag("Map"); if (map) { byte[] bytes = PathData.LoadPathData(loadFileName); ByteArray.StartRead(bytes); int width = ByteArray.ReadInt(); int height = ByteArray.ReadInt(); textureGrid = new Texture2D(width, height, TextureFormat.ARGB32, false); aStarUtils = new AStarUtils(textureGrid.width, textureGrid.height); int x, z; bool bPassable; for (x = 0; x < textureGrid.width; x++) { for (z = 0; z < textureGrid.height; z++) { bPassable = ByteArray.ReadByte() == 0 ? true : false; textureGrid.SetPixel(x, z, bPassable ? Color.white : Color.black); aStarUtils.GetNode(x, z).walkable = bPassable; } } textureGrid.Apply(); gridPlane.material.mainTexture = textureGrid; bRayEnd = true; Debug.Log(width + "-" + height); } }
void Awake() { this.pathList = new List <GameObject> (); this.aStarUtils = new AStarUtils(this.cols, this.rows); // cols for (int i = 0; i < this.cols; i++) { // rows for (int j = 0; j < this.rows; j++) { AStarUnit aStarUnit = new AStarUnit(); if (i != 0 && j != 0 && Random.Range(1, 10) <= 3) { aStarUnit.isPassable = false; GameObject gameObject = (GameObject)Instantiate(cubeObject); if (gameObject != null) { gameObject.transform.localPosition = new Vector3(i - this.cols * 0.5f + 0.5f, 0f, j - this.cols * 0.5f + 0.5f); } } else { aStarUnit.isPassable = true; } this.aStarUtils.GetNode(i, j).AddUnit(aStarUnit); } } }
public void LoadFromJPG() { if (InitPathData() == false) { return; } GameObject map = GameObject.FindWithTag("Map"); if (map) { textureGrid = PathData.LoadPathJPG(loadFileName); gridPlane.material.mainTexture = textureGrid; aStarUtils = new AStarUtils(textureGrid.width, textureGrid.height); int x, z; bool bPassable; for (x = 0; x < cols; x++) { for (z = 0; z < rows; z++) { bPassable = textureGrid.GetPixel(x, z) == Color.white ? true : false; aStarUtils.GetNode(x, z).walkable = bPassable; } } bRayEnd = true; } }
void Awake() { _aStarUtils = new AStarUtils (_cols, _rows); _moveableObj = Instantiate(pathObject); // cols for(int i = 0; i < _cols; i++) { // rows for(int j = 0; j < _rows; j++) { AStarUnit aStarUnit = new AStarUnit(); if(i != 0 && j != 0 && Random.Range(1, 10) <= 3) { aStarUnit.isPassable = false; GameObject gameObject = Instantiate(cubeObject); if(gameObject != null) { gameObject.transform.localPosition = new Vector3(i - this._cols * 0.5f + 0.5f, 0f, j - this._cols * 0.5f + 0.5f); } }else{ aStarUnit.isPassable = true; } _aStarUtils.GetNode(i,j).AddUnit(aStarUnit); } } }
public void StartRay() { if (bStart == false) { if (InitPathData() == true) { aStarUtils = new AStarUtils(cols, rows); textureGrid = new Texture2D(cols, rows); bStart = true; bRaying = false; bRayEnd = false; } } }
void Awake() { Application.targetFrameRate = 600; this.pathList = new List <GameObject> (); this.aStarUtils = new AStarUtils(this.cols, this.rows); Debug.Log("start"); // cols for (int i = 0; i < this.cols; i++) { // rows for (int j = 0; j < this.rows; j++) { AStarUnit aStarUnit = new AStarUnit(); if (i != 0 && j != 0 && Random.Range(1, 10) <= 1) { aStarUnit.isPassable = false; GameObject gameObject = (GameObject)Instantiate(cubeObject); if (gameObject != null) { var x = i - this.cols * 0.5f + 0.5f; var y = 0f; var z = j - this.rows * 0.5f + 0.5f; //Debug.Log(string.Format("x: {0}, y: {1}, z: {2}", x, y, z)); gameObject.transform.localPosition = new Vector3(x, y, z); } } else { aStarUnit.isPassable = true; } this.aStarUtils.GetNode(i, j).AddUnit(aStarUnit); } } // 设置底板格子数量 var mt = sceneGrid.GetComponent <Renderer>().material; Debug.Log(mt); if (mt != null) { //Debug.Log("setMaterial"); mt.SetTextureScale("_MainTex", new Vector2(cols, rows)); } // 设置底板宽度 sceneGrid.transform.localScale = new Vector3(cols / unit, 1, rows / unit); }
public void StartRay() { if (bStart == false) { if (InitPathData () == true) { aStarUtils = new AStarUtils(cols,rows); textureGrid = new Texture2D (cols, rows); bStart = true; bRaying = false; bRayEnd = false; } } }
public void LoadFromPD() { if (InitPathData () == false) return; GameObject map = GameObject.FindWithTag ("Map"); if (map) { byte[] bytes = PathData.LoadPathData(loadFileName); ByteArray.StartRead (bytes); int width = ByteArray.ReadInt(); int height = ByteArray.ReadInt(); textureGrid = new Texture2D (width, height,TextureFormat.ARGB32,false); aStarUtils = new AStarUtils(textureGrid.width,textureGrid.height); int x, z; bool bPassable; for(x = 0;x<textureGrid.width;x++) { for(z = 0;z<textureGrid.height;z++) { bPassable = ByteArray.ReadByte() == 0 ? true : false; textureGrid.SetPixel (x, z, bPassable ? Color.white : Color.black); aStarUtils.GetNode (x, z).walkable = bPassable; } } textureGrid.Apply (); gridPlane.material.mainTexture = textureGrid; bRayEnd = true; Debug.Log (width + "-" + height); } }
public void LoadFromJPG() { if (InitPathData () == false) return; GameObject map = GameObject.FindWithTag ("Map"); if (map) { textureGrid = PathData.LoadPathJPG (loadFileName); gridPlane.material.mainTexture = textureGrid; aStarUtils = new AStarUtils(textureGrid.width,textureGrid.height); int x, z; bool bPassable; for(x = 0;x<cols;x++) { for(z = 0;z<rows;z++) { bPassable = textureGrid.GetPixel (x, z) == Color.white ? true : false; aStarUtils.GetNode (x, z).walkable = bPassable; } } bRayEnd = true; } }