public void StartRobot() { BuildPathMap(); int vbsize = RecastMove.get_vb_size(); float[] vb = new float[vbsize]; RecastMove.get_vb(vb); Dbgrendermesh.Clear(); for (int i = 0; i < vbsize;) { #if UNITY_EDITOR Vector3 a = new Vector3(vb[i], vb[i + 1], vb[i + 2]); GameObject tempQie = AssetDatabase.LoadAssetAtPath("Assets/Models/obstacle_perfab/CubeOBBOX.prefab", typeof(GameObject)) as GameObject; GameObject tempQie2 = (GameObject)GameObject.Instantiate(tempQie); tempQie2.GetComponent <MeshRenderer>().enabled = true; tempQie2.GetComponent <BoxCollider>().enabled = false; tempQie2.AddComponent <RobotMove>(); tempQie2.GetComponent <RobotMove>().PathMap = PathMap; tempQie2.GetComponent <RobotMove>().max = Dbgrendermesh.m_Mesh.bounds.max; tempQie2.GetComponent <RobotMove>().min = Dbgrendermesh.m_Mesh.bounds.min; //tempQie2.AddComponent<>(); tempQie2.transform.position = a; tempQie2.name = i.ToString(); RobotList.Add(tempQie2); i += 3; #endif } }
public bool LoadOB(string _path) { IntPtr _ptr = Marshal.StringToHGlobalAnsi(_path); RecastMove.maploadob_bin(_ptr); RecastMove.load_ob_bin(_path); //for (int i = 0; i < vbsize;) //{ // Vector3 a = new Vector3(vb[i], vb[i + 1], vb[i + 2]); // // GameObject tempQie = AssetDatabase.LoadAssetAtPath("Assets/Models/obstacle_perfab/CubeOBBOX.prefab", typeof(GameObject)) as GameObject; // //GameObject tempQie = Resources.Load("perfab/CubeOBBOX") as GameObject;//通过prefab获取gameobject // GameObject tempQie2 = (GameObject)GameObject.Instantiate(tempQie); // tempQie2.transform.position = a; // tempQie2.name = i.ToString(); // i += 3; //} return(false); }
public void ShowRecastNavmesh(DbgRenderMesh renderMesh) { renderMesh.Clear(); int vbsize = RecastMove.get_vb_size(); vbsize = RecastMove.get_tri_vert_count() * 3; float[] vb = new float[vbsize]; //RecastMove.get_vb(vb); RecastMove.get_tri_vert_pos(vb); Dbgrendermesh.Clear(); for (int i = 0; i < vbsize;) { Vector3 a = new Vector3(vb[i], vb[i + 1], vb[i + 2]); Vector3 b = new Vector3(vb[i + 3], vb[i + 4], vb[i + 5]); Vector3 c = new Vector3(vb[i + 6], vb[i + 7], vb[i + 8]); Dbgrendermesh.AddTriangle(new DbgRenderTriangle(a, b, c, _vcolor)); i += 9; } renderMesh.Rebuild(); renderMesh.ComputeBounds(); _Bounds = new Bounds(renderMesh.m_BBCenter, renderMesh.m_Max - renderMesh.m_Min); int obsize = RecastMove.get_ob_count() * 3; float[] op = new float[obsize]; RecastMove.get_ob_info(op); for (int i = 0; i != obsize;) { if (first) { break; } first = true; Vector3 pos = new Vector3(op[i++], op[i++], op[i++]); // radius 1.0f, height 2.0f GameObject tempQie = AssetDatabase.LoadAssetAtPath("Assets/Models/obstacle_perfab/CubeOBBOX.prefab", typeof(GameObject)) as GameObject; GameObject tempQie2 = (GameObject)GameObject.Instantiate(tempQie); tempQie2.transform.position = pos; } }
public void ShowRecastNavmesh(DbgRenderMesh renderMesh) { renderMesh.Clear(); int vbsize = RecastMove.get_vb_size(); float[] vb = new float[vbsize]; RecastMove.get_vb(vb); Dbgrendermesh.Clear(); for (int i = 0; i < vbsize;) { Vector3 a = new Vector3(vb[i], vb[i + 1], vb[i + 2]); Vector3 b = new Vector3(vb[i + 3], vb[i + 4], vb[i + 5]); Vector3 c = new Vector3(vb[i + 6], vb[i + 7], vb[i + 8]); Dbgrendermesh.AddTriangle(new DbgRenderTriangle(a, b, c, _vcolor)); i += 9; } renderMesh.Rebuild(); }
public void InputUpdate() { bool leftClick = Input.GetMouseButtonDown(0); bool rightClick = Input.GetMouseButtonDown(1); if (leftClick || rightClick) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray.origin, ray.direction, out hit, 1000.0f)) { if (rightClick) { print(hit.point); float[] _ray = new float[3]; _ray[0] = ray.origin.x; _ray[1] = ray.origin.y; _ray[2] = ray.origin.z; float[] _end = new float[3]; _end[0] = hit.point.x; _end[1] = hit.point.y; _end[2] = hit.point.z; RecastMove.removeboxobstacle(_ray, _end); } else if (leftClick) { print(hit.point); float[] pmin = new float[3]; pmin[0] = hit.point.x - ObstaclesSize.x * 0.5f; pmin[1] = hit.point.y - ObstaclesSize.y * 0.5f; pmin[2] = hit.point.z - ObstaclesSize.z * 0.5f; float[] pmax = new float[3]; pmax[0] = hit.point.x + ObstaclesSize.x * 0.5f; pmax[1] = hit.point.y + ObstaclesSize.y * 0.5f; pmax[2] = hit.point.z + ObstaclesSize.z * 0.5f; RecastMove.addboxobstacle(pmin, pmax); } } } }
public bool LoadBin(string _path) { IntPtr _ptr = Marshal.StringToHGlobalAnsi(_path); RecastMove.mapload_bin(_ptr); RecastMove.load_map_bin(_path); //int vbsize = RecastMove.get_vb_size(); //float[] vb = new float[vbsize]; //RecastMove.get_vb(vb); //m_DbgRenderMesh.Clear(); //for (int i = 0; i < vbsize;) //{ // Vector3 a = new Vector3(vb[i], vb[i + 1], vb[i + 2]); // Vector3 b = new Vector3(vb[i + 3], vb[i + 4], vb[i + 5]); // Vector3 c = new Vector3(vb[i + 6], vb[i + 7], vb[i + 8]); // // m_DbgRenderMesh.AddTriangle(new DbgRenderTriangle(a, b, c, _vcolor)); // i += 9; //} return(false); }
void restarcomput() { pathlist.Clear(); Vector3 point = PathMap[Random.Range(0, PathMap.Count - 1)]; while (!RecastMove.is_valid_point(point.x, point.y, point.z)) { point = PathMap[Random.Range(0, PathMap.Count - 1)]; //point = new Vector3(Random.Range(min.x, max.x), 0.0f, Random.Range(min.z, max.z)); } float[] start = new float[3]; start[0] = this.transform.position.x; start[1] = this.transform.position.y; start[2] = this.transform.position.z; float[] end = new float[3]; end[0] = point.x; end[1] = point.y; end[2] = point.z; int maxPoint = 256 * 3 * 3; float[] _path = new float[maxPoint]; int patchcount = 0; RecastMove.findPath(start, end, _path, ref patchcount); for (int i = 0; i < patchcount * 3;) { Vector3 _i = new Vector3(_path[i], _path[i + 1], _path[i + 2]); pathlist.Add(_i); i += 3; } _endpos = this.transform.position; }
public void ClearAllTempObstacles() { RecastMove.clearAllTempObstacles(); }
public void SaveObstacles(string _path) { IntPtr _ptr = Marshal.StringToHGlobalAnsi(_path); RecastMove.saveObstaclesAll(_ptr); }
// Update is called once per frame void Update() { RecastMove.updateobstacle(); DebugViewUpdate(); InputUpdate(); }
protected virtual void OnDisable() { RecastMove.release_explorer(); }