/// <summary> /// 是否处于同一个tile中 /// </summary> public static bool IsSameTile(Vector3 pos1, Vector3 pos2, PathMap map) { PathVector3 v1 = new PathVector3(pos1.x, pos1.y, pos1.z); PathVector3 v2 = new PathVector3(pos2.x, pos2.y, pos2.z); if (v1.tx(map) == v2.tx(map) && v2.tz(map) == v2.tz(map)) { return(true); } else { return(false); } }
public void SetPosition( PathVector3 v ) { m_tx = v.tx(m_map); m_tz = v.tz(m_map); position.x = v.x; position.y = v.y; position.z = v.z; }
/// <summary> /// 计算当前节点的花费 /// </summary> /// <param name="origin">一个长度为3的数组保存起始点的X Y Z三个坐标位置</param> /// <param name="target">一个长度为3的数组保存目标点的X Y Z三个坐标位置</param> /// <returns>返回花费,值越大表示这个节点的代价越高</returns> public float SetCost(PathVector3 origin, PathVector3 destination, float extraCost ) { int ox = origin.tx(map); int oz = origin.tz(map); int dx = destination.tx(map); int dz = destination.tz(map); //fromStart = (float)(System.Math.Abs(tx - orx) + System.Math.Abs(tz - orz)) + extraCost; fromStart = parentCount + extraCost; heuristic = (float)(System.Math.Abs(tx - dx) + System.Math.Abs(tz - dz)); cost = fromStart + heuristic; return cost; }
/// <summary> /// 距离(不包括y轴) /// </summary> public static float TileDistance(PathVector3 vec1, PathVector3 vec2, PathMap map) { /* * vec1.x = (float)System.Math.Floor(vec1.x); * vec1.y = 0; * vec1.z = (float)System.Math.Floor(vec1.z); * * vec2.x = (float)System.Math.Floor(vec2.x); * vec2.y = 0; * vec2.z = (float)System.Math.Floor(vec2.z); */ //return (float)System.Math.Sqrt((vec1.x - vec2.x) * (vec1.x - vec2.x) + (vec1.z - vec2.z) * (vec1.z - vec2.z)); int tx1 = vec1.tx(map); int tz1 = vec1.tz(map); int tx2 = vec2.tx(map); int tz2 = vec2.tz(map); return(System.Math.Max(System.Math.Abs(tx1 - tx2), System.Math.Abs(tz1 - tz2))); }
public void SetBlock(Vector3 pos, int data) { if (m_map == null || m_map.m_Data == null || m_map.m_Data.Length == 0) { Build(); Debug.Log("map is null"); return; } PathVector3 pv3 = GridUtility.VectorToPath(pos); int tx = pv3.tx(m_map); int tz = pv3.tz(m_map); bool ok = m_map.CheckValid(pv3); if (!ok) { Debug.Log("position error:" + pos); return; } blocks[tx + tz * m_mapSizeX] = data; }