protected void OnGUI() { //heightmap, r is height, r and b are walkables m_pGroundHeightmap = (Texture2D)EditorGUILayout.ObjectField("地面图(walkmap)", m_pGroundHeightmap, typeof(Texture2D), false); m_pGroundNormalmap = (Texture2D)EditorGUILayout.ObjectField("地面法线图(normalmap)", m_pGroundNormalmap, typeof(Texture2D), false); if (null != m_pGroundHeightmap && null != m_pGroundNormalmap) { if (GUILayout.Button("创建基础信息")) { BuildBaseData(); } } m_pPathData = (APahtData)EditorGUILayout.ObjectField("已创建的数据", m_pPathData, typeof(APahtData), true); if (null != m_pPathData) { if (GUILayout.Button("创建Swamp信息")) { m_pPathData.FindAllSwamps(); } if (GUILayout.Button("创建JPS邻居表")) { m_pPathData.BakePruningRule(); } /* * if (GUILayout.Button("创建 Block AStar的LDDB")) * { * m_pPathData.GenerateLDDB(); * } */ } }
void Update() { #region Editor test if (TestPath) { TestPath = false; if (null != m_pStart && null != m_pEnd) { switch (m_eGizmo) { case EPathGizmoShow.EPGS_StrictAStar: { m_bHasStrictAStarPath = true; float flength = 0.0f; S2DPoint[] res = GridMath.StrictAStar( new Vector2(m_pStart.transform.position.x, m_pStart.transform.position.z), new Vector2(m_pEnd.transform.position.x, m_pEnd.transform.position.z), m_pPathData.m_byGridStateData, out flength ); m_v2PathStrictAStar = new Vector2[res.Length]; for (int i = 0; i < res.Length; ++i) { m_v2PathStrictAStar[i] = res[i].ToV2(); } CRuntimeLogger.Log(flength); } break; /* * case EPathGizmoShow.EPGS_Swamp: * { * m_pPathData.ResetGrids(); * EPathRes eres = EPathRes.EPR_NoPath; * m_v2PathSwamp = m_pPathData.FindPathAStar( * new Vector2(m_pStart.transform.position.x, m_pStart.transform.position.z), * new Vector2(m_pEnd.transform.position.x, m_pEnd.transform.position.z), * -1, * out eres * ); * m_bSwampPath = true; * } * break; */ case EPathGizmoShow.EPGS_JPS: { m_pPathData.BakePruningRule(); m_pPathData.InitialBlockbasedGrid(); m_pPathData.ResetGrids(); EPathRes eres = EPathRes.EPR_NoPath; m_v2PathJPS = m_pPathData.FindPathJPS( new Vector2(m_pStart.transform.position.x, m_pStart.transform.position.z), new Vector2(m_pEnd.transform.position.x, m_pEnd.transform.position.z), 30, out eres ); m_bJPSPath = true; } break; /* * case EPathGizmoShow.EPGS_BlockAStar: * { * m_pPathData.ResetBlockAStarBlocks(); * * EPathRes eres = EPathRes.EPR_NoPath; * m_v2PathBlockAStar = m_pPathData.FindPathBlockAStar( * new Vector2(m_pStart.transform.position.x, m_pStart.transform.position.z), * new Vector2(m_pEnd.transform.position.x, m_pEnd.transform.position.z), * -1, * out eres * ); * m_bBlockAStarPath = true; * } * break; */ } } } #endregion #region Running Test if (StartPerformanceTest) { for (int i = 0; i < 200; ++i) { S2DPoint p1 = S2DPoint.random; S2DPoint p2 = S2DPoint.random; EPathRes eres = EPathRes.EPR_NoPath; //m_pPathData.FindPathAStarOld(p1.ToV2(), p2.ToV2(), -1, out eres); //m_pPathData.FindPathAStar(p1.ToV2(), p2.ToV2(), -1, out eres); //m_pPathData.FindPathBlockAStar(p1.ToV2(), p2.ToV2(), -1, out eres); //m_pPathData.FindPathJPSOld(p1.ToV2(), p2.ToV2(), -1, out eres); //m_pPathData.FindPathJPS(p1.ToV2(), p2.ToV2(), -1, out eres); //m_pPathData.FindPathJPSMJ(p1.ToV2(), p2.ToV2(), -1, out eres); //blocked jps without multi-jump is the best, it expand more open-list at same time!(so it should be slower..but, not...) //for a partial path, or non-reachable, expand more open-list is even better! m_pPathData.FindPathJPS(p1.ToV2(), p2.ToV2(), 30, out eres); m_pPathData.FindPathJPSMJ(p1.ToV2(), p2.ToV2(), 7, out eres); } } #endregion }