无人机群路线及飞行规划
This commit is contained in:
parent
b9e9c7e5b8
commit
8ddc76956d
|
@ -345,11 +345,13 @@ MonoBehaviour:
|
|||
- {fileID: 5185013363439366923}
|
||||
- {fileID: 6839647458606122297}
|
||||
- {fileID: 4299622186163530999}
|
||||
LinePrefab: {fileID: 739704727871026136, guid: 01a28b65d7e53484b8bab2f3cc69ab91,
|
||||
LinePrefab: {fileID: 739704727871026136, guid: 3e35ca2d6b8539a45b9b9bd9ec287f2b,
|
||||
type: 3}
|
||||
airRoute: {fileID: 0}
|
||||
endPosition: {x: 0, y: 0, z: 0}
|
||||
FireSpeed: 20
|
||||
detectionRadius: 50
|
||||
isEngagedTarget: 0
|
||||
batteryLife: 1
|
||||
classificationWindResistance: 1
|
||||
maximumFlyingSpeed: 1
|
||||
|
|
|
@ -240,7 +240,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
isLinkAgain: 0
|
||||
serverIP: 127.0.0.1
|
||||
serverIP: 192.168.6.63
|
||||
port: 12345
|
||||
--- !u!4 &2132962759
|
||||
Transform:
|
||||
|
|
|
@ -767,7 +767,7 @@ PrefabInstance:
|
|||
- target: {fileID: 625513913607457920, guid: 121324ce722bdb944a7cc1c7c3a5077f,
|
||||
type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 121324ce722bdb944a7cc1c7c3a5077f, type: 3}
|
||||
|
@ -1039,7 +1039,7 @@ PrefabInstance:
|
|||
- target: {fileID: 3977472425108262603, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5,
|
||||
type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5, type: 3}
|
||||
|
@ -2006,7 +2006,7 @@ PrefabInstance:
|
|||
- target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162,
|
||||
type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7615181139496386328, guid: 7abae14e48a106d4c8120d0eba515162,
|
||||
type: 3}
|
||||
|
@ -2085,7 +2085,7 @@ PrefabInstance:
|
|||
- target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162,
|
||||
type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7615181139496386328, guid: 7abae14e48a106d4c8120d0eba515162,
|
||||
type: 3}
|
||||
|
|
|
@ -60,16 +60,16 @@ public class ObjectPlanner : MonoBehaviour
|
|||
{
|
||||
isPlanning = false; // 停止规划路线
|
||||
|
||||
Vector3[] positions = new Vector3[lineRenderer.positionCount]; // 创建用于存储顶点坐标的数组
|
||||
lineRenderer.GetPositions(positions); // 获取线条的顶点坐标
|
||||
if (unmannedAerialVehicleManage)
|
||||
{
|
||||
for (int i = 0; i < positions.Length; i++)
|
||||
{
|
||||
unmannedAerialVehicleManage.positions.Enqueue(positions[i]);
|
||||
unmannedAerialVehicleManage.endPosition = positions[positions.Length - 1];
|
||||
}
|
||||
}
|
||||
//Vector3[] positions = new Vector3[lineRenderer.positionCount]; // 创建用于存储顶点坐标的数组
|
||||
//lineRenderer.GetPositions(positions); // 获取线条的顶点坐标
|
||||
//if (unmannedAerialVehicleManage)
|
||||
//{
|
||||
// for (int i = 0; i < positions.Length; i++)
|
||||
// {
|
||||
// unmannedAerialVehicleManage.positions.Enqueue(positions[i]);
|
||||
// unmannedAerialVehicleManage.endPosition = positions[positions.Length - 1];
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,13 +76,9 @@ public class EquipmentCommon : MonoBehaviour
|
|||
}
|
||||
void OnActivationChangedIsPlayer(bool newValue)
|
||||
{
|
||||
if (newValue && equipmentType == "无人机List" && isOnlyOne)
|
||||
if (newValue && equipmentType == "无人机List")
|
||||
{
|
||||
isOnlyOne = false;
|
||||
latestData = GetSyncData();
|
||||
InvokeRepeating("SendMsg", 0, 0.01f);
|
||||
UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent<UnmannedAerialVehicleManage>();
|
||||
//unmannedAerialVehicleManage.unmannedAerialVehicles.ForEach(x => x.AddSendMsg());//每个无人机位置传递开启
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -163,30 +159,29 @@ public class EquipmentCommon : MonoBehaviour
|
|||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 已有路径
|
||||
/// </summary>
|
||||
public Queue<Vector3> positions = new Queue<Vector3>();
|
||||
|
||||
|
||||
|
||||
//位置实时传送
|
||||
private string latestData = "";
|
||||
private bool isOnlyOne = true;
|
||||
public void SendMsg()
|
||||
public bool isMove = true;
|
||||
/// <summary>
|
||||
/// 按规划路径开始移动
|
||||
/// </summary>
|
||||
public void StartMoveObjectAlongPath()
|
||||
{
|
||||
var nowData = GetSyncData();
|
||||
if (!nowData.Equals(latestData))
|
||||
if (isMove && positions.Count > 0)
|
||||
{
|
||||
latestData = nowData;
|
||||
Debug.Log(latestData);
|
||||
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
||||
isMove = false;
|
||||
Vector3 _positions = positions.Dequeue();
|
||||
UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent<UnmannedAerialVehicleManage>();
|
||||
if (unmannedAerialVehicleManage)
|
||||
StartCoroutine(unmannedAerialVehicleManage.MoveObjectAlongPath(_positions,isMove)); // 启动协程,按规划的路线移动物体
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 无人机整体位置传递
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected string GetSyncData()
|
||||
{
|
||||
return string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", "DronePosition", equipmentCommon.deviceID, transform.position.x, transform.position.y, transform.position.z, transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -199,9 +194,7 @@ public class EquipmentCommon : MonoBehaviour
|
|||
{
|
||||
case "DronePosition"://无人机位置信息传递
|
||||
Vector3 pos = new Vector3(float.Parse(data[2]), float.Parse(data[3]), float.Parse(data[4]));
|
||||
Vector3 rot = new Vector3(float.Parse(data[5]), float.Parse(data[6]), float.Parse(data[7]));
|
||||
transform.position = pos;
|
||||
transform.eulerAngles = rot;
|
||||
positions.Enqueue(pos);
|
||||
break;
|
||||
case "Lasing"://激光发射位置传递
|
||||
LaserFireControlPlatformManger laserFireControlPlatformManger = GetComponent<LaserFireControlPlatformManger>();
|
||||
|
|
|
@ -445,10 +445,10 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
|||
{
|
||||
if (airRoute)
|
||||
{
|
||||
ObjectPlanner objectPlanner = airRoute.GetComponent<ObjectPlanner>();
|
||||
if (objectPlanner)
|
||||
DistanceMeasurement distanceMeasurement = airRoute.GetComponent<DistanceMeasurement>();
|
||||
if (distanceMeasurement)
|
||||
{
|
||||
objectPlanner.isPathCanBePlanned = false;
|
||||
distanceMeasurement.isPathCanBePlanned = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -460,11 +460,10 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
|||
{
|
||||
if (airRoute)
|
||||
{
|
||||
ObjectPlanner objectPlanner = airRoute.GetComponent<ObjectPlanner>();
|
||||
if (objectPlanner)
|
||||
DistanceMeasurement distanceMeasurement = airRoute.GetComponent<DistanceMeasurement>();
|
||||
if (distanceMeasurement)
|
||||
{
|
||||
objectPlanner.isPathCanBePlanned = true;
|
||||
objectPlanner.lineRenderer.SetVertexCount(0);
|
||||
distanceMeasurement.isPathCanBePlanned = true;
|
||||
positions.Clear();
|
||||
}
|
||||
}
|
||||
|
@ -473,12 +472,12 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
|||
GameObject _object = Instantiate(LinePrefab);
|
||||
airRoute = _object;
|
||||
airRoute.transform.position = Vector3.zero;
|
||||
ObjectPlanner objectPlanner = airRoute.GetComponent<ObjectPlanner>();
|
||||
if (objectPlanner)
|
||||
DistanceMeasurement distanceMeasurement = airRoute.GetComponent<DistanceMeasurement>();
|
||||
if (distanceMeasurement)
|
||||
{
|
||||
objectPlanner.unmannedAerialVehicleManage = this;
|
||||
objectPlanner.isPathCanBePlanned = true;
|
||||
objectPlanner.SetSelectedObject(transform.gameObject);
|
||||
distanceMeasurement.isPathCanBePlanned = true;
|
||||
distanceMeasurement.markers[0] = transform;
|
||||
distanceMeasurement.unmannedAerialVehicleManage = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -492,13 +491,16 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
|||
if (isMove && positions.Count > 0)
|
||||
{
|
||||
isMove = false;
|
||||
StartCoroutine(MoveObjectAlongPath(positions.Dequeue())); // 启动协程,按规划的路线移动物体
|
||||
Vector3 _positions = positions.Dequeue();
|
||||
var nowData = GetSyncData(_positions);
|
||||
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
||||
StartCoroutine(MoveObjectAlongPath(_positions)); // 启动协程,按规划的路线移动物体
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator MoveObjectAlongPath(Vector3 positions) // 协程:按路线移动物体
|
||||
public IEnumerator MoveObjectAlongPath(Vector3 _positions) // 协程:按路线移动物体
|
||||
{
|
||||
Vector3 targetPosition = new Vector3(positions.x, 150, positions.z);// 目标位置为当前顶点坐标
|
||||
Vector3 targetPosition = new Vector3(_positions.x, 150, _positions.z);// 目标位置为当前顶点坐标
|
||||
float _distance = Vector3.Distance(transform.position, targetPosition);
|
||||
float _time = _distance / FireSpeed;
|
||||
transform.LookAt(endPosition);
|
||||
|
@ -506,6 +508,25 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
|||
yield return new WaitForSeconds(_time); // 等待一帧时间
|
||||
isMove = true;
|
||||
}
|
||||
public IEnumerator MoveObjectAlongPath(Vector3 _positions,bool _isMove) // 协程:按路线移动物体
|
||||
{
|
||||
Vector3 targetPosition = new Vector3(_positions.x, 150, _positions.z);// 目标位置为当前顶点坐标
|
||||
float _distance = Vector3.Distance(transform.position, targetPosition);
|
||||
float _time = _distance / FireSpeed;
|
||||
transform.LookAt(endPosition);
|
||||
transform.DOMove(targetPosition, _time).SetEase(Ease.Linear);
|
||||
yield return new WaitForSeconds(_time); // 等待一帧时间
|
||||
equipmentCommon.isMove = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机整体位置传递
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected string GetSyncData(Vector3 _positions)
|
||||
{
|
||||
return string.Format("{0},{1},{2},{3},{4}", "DronePosition", equipmentCommon.deviceID, _positions.x, _positions.y, _positions.z);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
OnActivationChanged -= OnActivationChangedHandler;
|
||||
|
|
Loading…
Reference in New Issue