void MakeMassArrays(int width, int height) { var xRange = (float)width / gridLevel; var yRange = (float)height / gridLevel; var yPos = yRange / 2f; var xPos = xRange / 2f; for (int y = 0; y < gridLevel; y++) { xPos = xRange / 2f; for (int x = 0; x < gridLevel; x++) { var center = new Vector3(xPos - width / 2f, 0, yPos - height / 2f); if (StageCollision.HasBlock(center, new Vector3(xRange / 2f, 0.5f, yRange / 2f))) { var block = StageCollision.GetBlock(center); if (block.GetComponent <BlockProvider>().Decided()) { massArrays[y, x] = new Mass(); } else //まだ決まってない場合==歩ける { massArrays[y, x] = new Mass(center, xRange, yRange, new Vector2(x, y)); } } else { massArrays[y, x] = new Mass(); } xPos += xRange; } yPos += yRange; } }
// Update is called once per frame void Update() { if (DecideDestination()) { playerProvider.StartMove(GetWorldPosByTap()); } if (DecidePutting()) { var block = StageCollision.GetBlockByRay(transform.position + Vector3.up, Vector3.down); //現在の場所 //Debug.Log("block pos:"+block.position); if (block == null) { return; } if (block.GetComponent <BlockProvider>().Decided()) { return; } playerProvider.DecideBlock(block.GetComponent <BlockProvider>()); playerProvider.StopMove(); } }
List <Vector2> Optimize(List <Vector2> nowPath) { var optimizedPath = nowPath; var start = 0; var end = 1; var counter = 0; var finish = false; if (nowPath.Count < 2) { return(nowPath); } //直線で進めるなら省略する while (true) { var startPos = new Vector3(optimizedPath[start].x, 1, optimizedPath[start].y); var endPos = new Vector3(optimizedPath[end].x, 1, optimizedPath[end].y); while (!StageCollision.CanStraight(startPos, endPos)) { end++; if (end >= optimizedPath.Count)//終了 { finish = true; break; } endPos.x = optimizedPath[end].x; endPos.z = optimizedPath[end].y; if (counter++ > 1000) { Debug.LogError("error. don't finish optimize"); break; } } //Debug.Log("start:"+start+" end:"+end); if (start + 1 + (end - start - 2) >= optimizedPath.Count || (end - start - 2) < 0) { break; } optimizedPath.RemoveRange(start + 1, end - start - 2); start++; end = start + 1; if (finish) { break; } if (start >= optimizedPath.Count) { break; } if (counter++ > 1000) { Debug.LogError("error. don't finish optimize"); break; } } optimizedPath.RemoveAt(0); return(optimizedPath); }