/// <summary> /// 切换两种飞行动作 /// </summary> public int CalculateHiteEdge() { int pointInIndex = -1; int index = -1; Vector3 returnPos = Vector3.zero; int lastIndex = m_lFlyData.Count - 1; for (int i = 0; i < m_lFlyData.Count - 1; i++) { if (GenerateShip.pointInRejectPolygon(m_lFlyData[i].Pos, GenerateShip.GetRejectPolygon()) && i != 0) { pointInIndex = i; break; } } if (pointInIndex != -1) { index = GenerateShip.RayToRejectPolygon(m_lFlyData[pointInIndex - 1].Pos, m_lFlyData[pointInIndex].Pos, ref returnPos, GenerateShip.GetRejectPolygon()); } else { index = GenerateShip.RayToRejectPolygon(m_lFlyData[lastIndex - 1].Pos, m_lFlyData[lastIndex].Pos, ref returnPos, GenerateShip.GetRejectPolygon()); } return(index); //NGUIUtil.DebugLog("hitIndex =" + index,"brown"); }
/// <summary> /// 确认飞行轨迹有效。 /// </summary> public static bool CheckFlyLine(ref List <Vector3> lFlyPoint) { if (lFlyPoint == null || lFlyPoint.Count < 0) { return(false); } //if( lFlyPoint.Count < 2) return false; //if (lFlyPoint.Count==2 && lFlyPoint[0] == lFlyPoint[1]) // return false; lFlyPoint = PathUtil.SmoothSimple(lFlyPoint); if (m_IsSmooth) { if (lFlyPoint == null) { return(false); } if (GenerateShip.pointInRejectPolygon(lFlyPoint [0], GenerateShip.GetOutRejectPolygon())) { Vector3 posRaySrc = lFlyPoint [0]; Vector3 posRayTo0 = lFlyPoint [0] + Vector3.left * 6f; Vector3 posReturn0 = new Vector3(posRayTo0.x, posRayTo0.y, posRayTo0.z); GenerateShip.RayToRejectPolygon(posRaySrc, posRayTo0, ref posReturn0, GenerateShip.GetOutRejectPolygon()); Vector3 posRayTo1 = lFlyPoint [0] + Vector3.right * 6f; Vector3 posReturn1 = new Vector3(posRayTo1.x, posRayTo1.y, posRayTo1.z); GenerateShip.RayToRejectPolygon(posRaySrc, posRayTo1, ref posReturn1, GenerateShip.GetOutRejectPolygon()); Vector3 posRayTo2 = lFlyPoint [0] + Vector3.up * 6f; Vector3 posReturn2 = new Vector3(posRayTo2.x, posRayTo2.y, posRayTo2.z); GenerateShip.RayToRejectPolygon(posRaySrc, posRayTo2, ref posReturn2, GenerateShip.GetOutRejectPolygon()); float fDistance0 = Vector2.Distance(posRaySrc, posReturn0); float fDistance1 = Vector2.Distance(posRaySrc, posReturn1); float fDistance2 = Vector2.Distance(posRaySrc, posReturn2); lFlyPoint.Remove(posRaySrc); if (fDistance0 <= fDistance1) { if (fDistance2 < fDistance0) { lFlyPoint.Insert(0, posReturn2); } else { lFlyPoint.Insert(0, posReturn0); } } else { if (fDistance2 < fDistance1) { lFlyPoint.Insert(0, posReturn2); } else { lFlyPoint.Insert(0, posReturn1); } } } //把进入船的点去掉 for (int i = 0; i < lFlyPoint.Count; i++) { if (GenerateShip.pointInRejectPolygon(lFlyPoint [i], GenerateShip.GetRejectPolygon()) && lFlyPoint.Count - i - 1 > 0) { lFlyPoint.RemoveRange(i + 1, lFlyPoint.Count - i - 1); break; } } } if (lFlyPoint.Count > 1) { if (GenerateShip.pointInRejectPolygon(lFlyPoint [0], GenerateShip.GetOutRejectPolygon())) { Vector3 posRaySrc = lFlyPoint [0]; Vector3 posRayTo0 = lFlyPoint [0] + Vector3.left * 6f; Vector3 posReturn0 = new Vector3(posRayTo0.x, posRayTo0.y, posRayTo0.z); GenerateShip.RayToRejectPolygon(posRaySrc, posRayTo0, ref posReturn0, GenerateShip.GetOutRejectPolygon()); } int nPoint = lFlyPoint.Count; Vector3 posLast = lFlyPoint[nPoint - 1] + (lFlyPoint[nPoint - 1] - lFlyPoint[nPoint - 2]) * 30f; lFlyPoint.Add(posLast); return(true); } return(false); }