public void Load(KdtreeAsset treeasset) { if (treeasset != null) { float time = Time.realtimeSinceStartup; Simulator.Instance.CreateKdtreeFromAsset(treeasset); LogMgr.LogFormat("Load cost :{0}", Time.realtimeSinceStartup - time); this.asset = treeasset; } }
void Add2Rvo() { BeginSample("Add2Rvo"); float firsttime = Time.realtimeSinceStartup; if (ExactMode == ExactType.ZERO) { BeginSample("ZERO COST"); int[] uses = new int[20]; for (int i = 0; i < ObsTriangles.Length; i++) { NavmeshTriangle node = ObsTriangles [i]; uses [0] = uses [1] = uses [2] = 0; if (node != null) { for (int j = 0; j < node.connections.Count; j++) { NavmeshTriangle other = node.connections [j]; if (other != null) { int a = node.SharedEdge(other); if (a != -1) { uses [a] = 1; } } } for (int j = 0; j < 3; j++) { if (uses [j] == 0) { var v1 = node.GetVertex(j); var v2 = node.GetVertex((j + 1) % 3); Simulator.Instance.addObstacle(v1, v2); } } } ShowProgress("插入障碍点", (float)i / (ObsTriangles.Length)); } EndSample(); } if (ExactMode >= ExactType.ONE) { BeginSample("Buildsegments"); Buildsegments(); EndSample(); BeginSample("RemoveUnused"); RemoveUnused(); EndSample(); BeginSample("PushSegmentstoObstacles"); PushSegmentstoObstacles(); EndSample(); } ShowProgress("准备构建ObstacleTree", 0); float time = Time.realtimeSinceStartup; BeginSample("processObstacles"); if (processObstacles) { Simulator.Instance.processObstacles(); } EndSample(); LogMgr.LogFormat("Add2Rvo cost :{0} processObstacles cost :{1} ", Time.realtimeSinceStartup - firsttime, Time.realtimeSinceStartup - time); ShowProgress("构建ObstacleTree 完成", 1); this.ClearProgressBar(); EndSample(); #if !UNITY_EDITOR ObsTriangles = null; segments = null; tree = null; point2triangle = null; #else if (ObstacleDebug >= DebugMode.ShowAll && UnityEditor.EditorUtility.DisplayDialog("tips", "export kdtree asset or not ?", "OK", "NO")) { string assetpath = UnityEditor.EditorUtility.SaveFilePanelInProject("save", "kdtree", "asset", "please enter a filename"); if (!string.IsNullOrEmpty(assetpath)) { KdtreeAsset node = ScriptableObject.CreateInstance <KdtreeAsset> (); ScriptCommand cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.GET_KDTREE); cmd.Excute(); ScriptCommand obscmd = ScriptCommand.Create((int)FrameWorkCmdDefine.GET_OBSTACLES); obscmd.Excute(); KdTree tree = cmd.ReturnParams.ReadObject() as KdTree; IList <Obstacle> obstacles = obscmd.ReturnParams.ReadObject() as IList <Obstacle>; node.CreateKdtree(tree, obstacles); cmd.Release(true); obscmd.Release(true); UnityEditor.AssetDatabase.CreateAsset(node, assetpath); } } #endif }