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