This commit is contained in:
YangHua 2023-11-22 20:30:05 +08:00
commit 9526c90cfb
9 changed files with 402 additions and 118 deletions

View File

@ -380,7 +380,114 @@ Transform:
m_Children: m_Children:
- {fileID: 1326529938} - {fileID: 1326529938}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 13 m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &131091531
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 131091536}
- component: {fileID: 131091535}
- component: {fileID: 131091534}
- component: {fileID: 131091533}
- component: {fileID: 131091532}
m_Layer: 12
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &131091532
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 131091531}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!65 &131091533
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 131091531}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &131091534
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 131091531}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &131091535
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 131091531}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &131091536
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 131091531}
m_LocalRotation: {x: -0, y: -0.7071068, z: -0, w: 0.7071068}
m_LocalPosition: {x: 422.99, y: 30, z: 80.41}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &144713087 --- !u!1 &144713087
GameObject: GameObject:
@ -411,6 +518,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 014683e72ff868e4c9c0d3eec7d87a26, type: 3} m_Script: {fileID: 11500000, guid: 014683e72ff868e4c9c0d3eec7d87a26, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
equipmentCommons:
- {fileID: 727490127}
- {fileID: 2041579131}
- {fileID: 1611173771}
unmannedAerialVehicleManages: unmannedAerialVehicleManages:
- {fileID: 1156703774} - {fileID: 1156703774}
radarMangers: radarMangers:
@ -656,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: 0 value: 1
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}
@ -684,6 +795,18 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8d431a7d95f5da7448bc421314544f20, type: 3} m_Script: {fileID: 11500000, guid: 8d431a7d95f5da7448bc421314544f20, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!114 &727490127 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: -7238547075891962512, guid: 8425122cf585dcc47bbf3eff95ecf176,
type: 3}
m_PrefabInstance: {fileID: 1446243674}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0afac659d8be281448f9ecd22f828b72, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &742343356 --- !u!1 &742343356
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -762,7 +885,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 742343356} m_GameObject: {fileID: 742343356}
m_LocalRotation: {x: 0.30070576, y: 0, z: 0, w: 0.953717} m_LocalRotation: {x: 0.30070576, y: 0, z: 0, w: 0.953717}
m_LocalPosition: {x: 26, y: 190, z: -443} m_LocalPosition: {x: 170.9, y: 190, z: -443}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
@ -916,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}
@ -1325,12 +1448,12 @@ PrefabInstance:
- target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176, - target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 434.09 value: 429.4
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176, - target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176,
type: 3} type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 0 value: 30
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176, - target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176,
type: 3} type: 3}
@ -1360,7 +1483,7 @@ PrefabInstance:
- target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176, - target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 12 value: 13
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176, - target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176,
type: 3} type: 3}
@ -1379,6 +1502,18 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8425122cf585dcc47bbf3eff95ecf176, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 8425122cf585dcc47bbf3eff95ecf176, type: 3}
--- !u!114 &1611173771 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1145900336322340155, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5,
type: 3}
m_PrefabInstance: {fileID: 747100775}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0afac659d8be281448f9ecd22f828b72, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1687255089 --- !u!1 &1687255089
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1871,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}
@ -1950,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}
@ -2075,3 +2210,15 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: ecdd96beb7f93494880c052dfccf9dc1, type: 3} m_SourcePrefab: {fileID: 100100000, guid: ecdd96beb7f93494880c052dfccf9dc1, type: 3}
--- !u!114 &2041579131 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7287081401534477579, guid: 121324ce722bdb944a7cc1c7c3a5077f,
type: 3}
m_PrefabInstance: {fileID: 407575141}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0afac659d8be281448f9ecd22f828b72, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@ -28,13 +28,15 @@ public class DeviceManager : MonoSingleton<DeviceManager>
{ {
data = data.Replace("send2room", ""); data = data.Replace("send2room", "");
string[] info = data.Split(','); string[] info = data.Split(',');
EquipmentCommon equipmentCommon = devices.Find(x => x.deviceID == info[0]); EquipmentCommon equipmentCommon = devices.Find(x => x.deviceID == info[1]);
if (equipmentCommon) if (equipmentCommon)
{ {
equipmentCommon.ReceivingPositionAngle(info); equipmentCommon.ReceivingPositionAngle(info);
} }
} }
public void OnDisalbe() public void OnDisalbe()
{ {
SyncCreateRoom.send2roomRequset -= GetSend2roomMsg; SyncCreateRoom.send2roomRequset -= GetSend2roomMsg;

View File

@ -60,6 +60,10 @@ public class EquipmentCommon : MonoBehaviour
} }
} }
} }
/// <summary>
/// 爆炸预制体
/// </summary>
public GameObject explodePrefab;
void Start() void Start()
{ {
@ -75,7 +79,10 @@ public class EquipmentCommon : MonoBehaviour
if (newValue && equipmentType == "无人机List" && isOnlyOne) if (newValue && equipmentType == "无人机List" && isOnlyOne)
{ {
isOnlyOne = false; isOnlyOne = false;
StartCoroutine(SendMsg()); latestData = GetSyncData();
InvokeRepeating("SendMsg", 0, 0.01f);
UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent<UnmannedAerialVehicleManage>();
unmannedAerialVehicleManage.unmannedAerialVehicles.ForEach(x => x.AddSendMsg());//每个无人机位置传递开启
} }
} }
/// <summary> /// <summary>
@ -161,28 +168,23 @@ public class EquipmentCommon : MonoBehaviour
//位置实时传送 //位置实时传送
private string latestData = ""; private string latestData = "";
private bool isOnlyOne = true; private bool isOnlyOne = true;
public IEnumerator SendMsg() public void SendMsg()
{ {
while (true) var nowData = GetSyncData();
if (!nowData.Equals(latestData))
{ {
yield return new WaitForSeconds(0.01f); latestData = nowData;
Debug.Log(latestData);
var nowData = GetSyncData(); _ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
if (!nowData.Equals(latestData))
{
latestData = nowData;
//Debug.Log(latestData);
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
}
} }
} }
/// <summary> /// <summary>
/// 无人机 /// 无人机整体位置传递
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
protected string GetSyncData() protected string GetSyncData()
{ {
return string.Format("{0},{1},{2},{3},{4},{5},{6}", equipmentCommon.deviceID, transform.position.x, transform.position.y, transform.position.z, transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z); 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);
} }
@ -192,30 +194,65 @@ public class EquipmentCommon : MonoBehaviour
/// <param name="data"></param> /// <param name="data"></param>
public void ReceivingPositionAngle(string[] data) public void ReceivingPositionAngle(string[] data)
{ {
switch (equipmentType) switch (data[0])
{ {
case "无人机List": case "DronePosition"://无人机位置信息传递
Vector3 pos = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3])); Vector3 pos = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3]));
Vector3 rot = new Vector3(float.Parse(data[4]), float.Parse(data[5]), float.Parse(data[6])); Vector3 rot = new Vector3(float.Parse(data[4]), float.Parse(data[5]), float.Parse(data[6]));
transform.position = pos; transform.position = pos;
transform.eulerAngles = rot; transform.eulerAngles = rot;
break; break;
case "激光火控平台": case "Lasing"://激光发射位置传递
LaserFireControlPlatformManger laserFireControlPlatformManger = GetComponent<LaserFireControlPlatformManger>(); LaserFireControlPlatformManger laserFireControlPlatformManger = GetComponent<LaserFireControlPlatformManger>();
if (laserFireControlPlatformManger) if (laserFireControlPlatformManger)
laserFireControlPlatformManger.NonSelfGeneratedEmissionLaser(data); laserFireControlPlatformManger.NonSelfGeneratedEmissionLaser(data);
break; break;
case "探测雷达": case "SingleDronePosition"://单个无人机位置信息传递
UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent<UnmannedAerialVehicleManage>();
if (unmannedAerialVehicleManage)
{
UnmannedAerialVehicle unmannedAerialVehicle = unmannedAerialVehicleManage.unmannedAerialVehicles.Find(x => x.serialNumber == data[2]);
if (unmannedAerialVehicle)
{
Vector3 localPos = new Vector3(float.Parse(data[3]), float.Parse(data[4]), float.Parse(data[5]));
Vector3 localRot = new Vector3(float.Parse(data[6]), float.Parse(data[7]), float.Parse(data[8]));
unmannedAerialVehicle.transform.localPosition = localPos;
unmannedAerialVehicle.transform.localEulerAngles = localRot;
}
}
break; break;
case "地面无线电干扰": case "DroneWasDestroyed"://单个无人机被销毁
UnmannedAerialVehicleManage _unmannedAerialVehicleManage = GetComponent<UnmannedAerialVehicleManage>();
if (_unmannedAerialVehicleManage)
{
UnmannedAerialVehicle unmannedAerialVehicle = _unmannedAerialVehicleManage.unmannedAerialVehicles.Find(x => x.serialNumber == data[2]);
if (unmannedAerialVehicle)
{
unmannedAerialVehicle.AddBao(false);
}
}
break;
case "SetToBeDestroyed"://设备被销毁
GameObject Bao = Instantiate(explodePrefab, transform);
Bao.transform.localPosition = Vector3.zero;
Bao.transform.SetParent(null);
Bao.SetActive(true);
Destroy(transform.gameObject);
break; break;
default: default:
break; break;
} }
} }
private void OnDestroy()
{
// 订阅布尔值变化事件
OnActivationChanged -= OnActivationChangedHandler;
//
OnActivationIsPlayer -= OnActivationChangedIsPlayer;
}
} }
public enum SelectedSide public enum SelectedSide

View File

@ -216,14 +216,12 @@ public class LaserFireControlPlatformManger : MonoBehaviour
/// </summary> /// </summary>
private void StrikeDrone(Transform hit) private void StrikeDrone(Transform hit)
{ {
if(hit.transform.tag== "WRJ") UnmannedAerialVehicle unmannedAerialVehicle = hit.GetComponent<UnmannedAerialVehicle>();
if (unmannedAerialVehicle)
{ {
UnmannedAerialVehicle unmannedAerialVehicle = hit.GetComponent<UnmannedAerialVehicle>(); unmannedAerialVehicle.BeAssaulted("激光打击");
if (unmannedAerialVehicle)
{ StartCoroutine(LaserExtinction());
unmannedAerialVehicle.BeAssaulted("激光打击");
StartCoroutine(LaserExtinction());
}
} }
} }
@ -256,7 +254,7 @@ public class LaserFireControlPlatformManger : MonoBehaviour
protected string GetSyncData() protected string GetSyncData()
{ {
Debug.Log("目标点位..:" + targetPoint.position); Debug.Log("目标点位..:" + targetPoint.position);
return string.Format("{0},{1},{2},{3}", equipmentCommon.deviceID, targetPoint.position.x, targetPoint.position.y, targetPoint.position.z); return string.Format("{0},{1},{2},{3},{4}", "Lasing", equipmentCommon.deviceID, targetPoint.position.x, targetPoint.position.y, targetPoint.position.z);
} }
/// <summary> /// <summary>
@ -278,4 +276,9 @@ public class LaserFireControlPlatformManger : MonoBehaviour
} }
StartCoroutine(LaserExtinction()); StartCoroutine(LaserExtinction());
} }
private void OnDestroy()
{
OnActivationChanged -= OnActivationChangedHandler;
}
} }

View File

@ -170,7 +170,7 @@ public class RadarManger : MonoBehaviour
/// </summary> /// </summary>
public void StartTimer() public void StartTimer()
{ {
if (timerCoroutine == null) if (equipmentCommon.isPlayer && timerCoroutine == null)
{ {
timerCoroutine = StartCoroutine(Timer()); timerCoroutine = StartCoroutine(Timer());
isTimerRunning = true; isTimerRunning = true;
@ -181,7 +181,7 @@ public class RadarManger : MonoBehaviour
/// </summary> /// </summary>
public void StopTimer() public void StopTimer()
{ {
if (timerCoroutine != null) if (equipmentCommon.isPlayer && timerCoroutine != null)
{ {
StopCoroutine(timerCoroutine); StopCoroutine(timerCoroutine);
timerCoroutine = null; timerCoroutine = null;
@ -319,5 +319,9 @@ public class RadarManger : MonoBehaviour
Debug.Log("鼠标离开"); Debug.Log("鼠标离开");
RadarUi.transform.localScale = Vector3.zero; RadarUi.transform.localScale = Vector3.zero;
} }
private void OnDestroy()
{
OnActivationChanged -= OnActivationChangedHandler;
}
} }

View File

@ -7,6 +7,8 @@ using UnityEngine;
/// </summary> /// </summary>
public class SingleMachineTest : MonoBehaviour public class SingleMachineTest : MonoBehaviour
{ {
public List<EquipmentCommon> equipmentCommons = new List<EquipmentCommon>();
/// <summary> /// <summary>
/// 无人机 /// 无人机
/// </summary> /// </summary>
@ -65,8 +67,6 @@ public class SingleMachineTest : MonoBehaviour
} }
} }
} }
} }
[ContextMenu("Add")] [ContextMenu("Add")]
@ -105,7 +105,8 @@ public class SingleMachineTest : MonoBehaviour
if (timerCoroutine == null) if (timerCoroutine == null)
{ {
timerCoroutine = StartCoroutine(Timer()); timerCoroutine = StartCoroutine(Timer());
equipmentCommons.ForEach(x => x.isPlayer = true);
unmannedAerialVehicleManages.ForEach(x => x.isStartRehearsing = true); unmannedAerialVehicleManages.ForEach(x => x.isStartRehearsing = true);
radarMangers.ForEach(x => x.isStartRehearsing = true); radarMangers.ForEach(x => x.isStartRehearsing = true);
laserFireControlPlatformMangers.ForEach(x => x.isStartRehearsing = true); laserFireControlPlatformMangers.ForEach(x => x.isStartRehearsing = true);
@ -122,7 +123,6 @@ public class SingleMachineTest : MonoBehaviour
{ {
StopCoroutine(timerCoroutine); StopCoroutine(timerCoroutine);
timerCoroutine = null; timerCoroutine = null;
unmannedAerialVehicleManages.ForEach(x => x.isStartRehearsing = false); unmannedAerialVehicleManages.ForEach(x => x.isStartRehearsing = false);
radarMangers.ForEach(x => x.isStartRehearsing = false); radarMangers.ForEach(x => x.isStartRehearsing = false);
laserFireControlPlatformMangers.ForEach(x => x.isStartRehearsing = false); laserFireControlPlatformMangers.ForEach(x => x.isStartRehearsing = false);

View File

@ -118,7 +118,7 @@ public class TerrestrialRadioInterferenceManger : MonoBehaviour
/// </summary> /// </summary>
public void StartTimer() public void StartTimer()
{ {
if (timerCoroutine == null) if (equipmentCommon.isPlayer && timerCoroutine == null)
{ {
timerCoroutine = StartCoroutine(Timer()); timerCoroutine = StartCoroutine(Timer());
isTimerRunning = true; isTimerRunning = true;
@ -129,7 +129,7 @@ public class TerrestrialRadioInterferenceManger : MonoBehaviour
/// </summary> /// </summary>
public void StopTimer() public void StopTimer()
{ {
if (timerCoroutine != null) if (equipmentCommon.isPlayer && timerCoroutine != null)
{ {
StopCoroutine(timerCoroutine); StopCoroutine(timerCoroutine);
timerCoroutine = null; timerCoroutine = null;
@ -192,7 +192,7 @@ public class TerrestrialRadioInterferenceManger : MonoBehaviour
UnmannedAerialVehicle unmannedAerialVehicle = col.GetComponent<UnmannedAerialVehicle>(); UnmannedAerialVehicle unmannedAerialVehicle = col.GetComponent<UnmannedAerialVehicle>();
if (unmannedAerialVehicle) if (unmannedAerialVehicle)
{ {
Debug.Log(col.name+"数据链通信频点...:" + unmannedAerialVehicle.dataLinkCommunicationFrequency); //Debug.Log(col.name+"数据链通信频点...:" + unmannedAerialVehicle.dataLinkCommunicationFrequency);
if (unmannedAerialVehicle.dataLinkCommunicationFrequency == "" || InterferingFrequency == "") return;//无数据不执行 if (unmannedAerialVehicle.dataLinkCommunicationFrequency == "" || InterferingFrequency == "") return;//无数据不执行
if(unmannedAerialVehicle.dataLinkCommunicationFrequency== InterferingFrequency) if(unmannedAerialVehicle.dataLinkCommunicationFrequency== InterferingFrequency)
{ {
@ -204,4 +204,9 @@ public class TerrestrialRadioInterferenceManger : MonoBehaviour
} }
} }
private void OnDestroy()
{
OnActivationChanged -= OnActivationChangedHandler;
}
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using DG.Tweening; using DG.Tweening;
using System.Linq; using System.Linq;
using AdamSync;
/// <summary> /// <summary>
/// 无人机 /// 无人机
@ -13,6 +14,10 @@ public class UnmannedAerialVehicle : MonoBehaviour
/// 所属无人机蜂群 /// 所属无人机蜂群
/// </summary> /// </summary>
public UnmannedAerialVehicleManage unmannedAerialVehicleManage; public UnmannedAerialVehicleManage unmannedAerialVehicleManage;
/// <summary>
/// 序列编号
/// </summary>
public string serialNumber = "";
#region #region
/// <summary> /// <summary>
@ -59,7 +64,7 @@ public class UnmannedAerialVehicle : MonoBehaviour
/// <summary> /// <summary>
/// 是否正在攻击目标 /// 是否正在攻击目标
/// </summary> /// </summary>
private bool isEngagedTarget = false; public bool isEngagedTarget = false;
/// <summary> /// <summary>
/// 爆炸预制体 /// 爆炸预制体
/// </summary> /// </summary>
@ -68,13 +73,13 @@ public class UnmannedAerialVehicle : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if (unmannedAerialVehicleManage && unmannedAerialVehicleManage.isStartRehearsing) if (unmannedAerialVehicleManage && unmannedAerialVehicleManage.equipmentCommon.isPlayer && unmannedAerialVehicleManage.isStartRehearsing)
{ {
switch (unmannedAerialVehicleManage.pattern) switch (unmannedAerialVehicleManage.pattern)
{ {
@ -95,13 +100,15 @@ public class UnmannedAerialVehicle : MonoBehaviour
/// </summary> /// </summary>
public void AttackATarget() public void AttackATarget()
{ {
if (!isEngagedTarget) if (!isEngagedTarget)
{ {
List<Collider> colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体 List<Collider> colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体
List<Collider> colliders1 = colliders.FindAll(x => x.transform.tag == "AttackTarget"); List<Collider> colliders1 = colliders.FindAll(x => x.transform.tag == "AttackTarget");
if (colliders1.Count>0) if (colliders1.Count > 0)
{ {
int _number= Random.Range(0, colliders1.Count-1); colliders1.ForEach(x => Debug.Log(x.transform.name));
int _number = Random.Range(0, colliders1.Count - 1);
isEngagedTarget = true; isEngagedTarget = true;
Debug.Log(colliders1[_number].transform.name); Debug.Log(colliders1[_number].transform.name);
AttAck(colliders1[_number].transform); AttAck(colliders1[_number].transform);
@ -116,9 +123,11 @@ public class UnmannedAerialVehicle : MonoBehaviour
{ {
Debug.Log("开始攻击目标..:" + target.name); Debug.Log("开始攻击目标..:" + target.name);
Vector3 _v3 = target.position; Vector3 _v3 = target.position;
transform.DOLookAt(_v3, 0.1f).OnComplete(() => { transform.DOLookAt(_v3, 0.1f).OnComplete(() =>
{
float distance = Vector3.Distance(transform.position, target.position); float distance = Vector3.Distance(transform.position, target.position);
transform.DOMove(target.position, distance / FireSpeed).SetEase(Ease.Linear).OnComplete(()=> { transform.DOMove(target.position, distance / FireSpeed).SetEase(Ease.Linear).OnComplete(() =>
{
if (!target) if (!target)
{ {
BeAssaulted("没有攻击到目标"); BeAssaulted("没有攻击到目标");
@ -130,77 +139,152 @@ public class UnmannedAerialVehicle : MonoBehaviour
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
if (other.tag == "AttackTarget") if (unmannedAerialVehicleManage.equipmentCommon.isPlayer && other.tag == "AttackTarget")
{ {
AddBao(other.transform);
// 销毁objectToDestroy对象 // 销毁objectToDestroy对象
BeAssaulted("攻击到目标"); BeAssaulted("攻击到目标");
GameObject Bao = Instantiate(explodePrefab, other.transform);
Bao.transform.localPosition = Vector3.zero;
Bao.transform.SetParent(null);
Bao.SetActive(true);
Destroy(other.gameObject);
} }
} }
//[]
//public void AddBeAssaulted()
//{
// BeAssaulted("无线电干扰");
//}
/// <summary> /// <summary>
/// 被攻击 /// 被攻击
/// </summary> /// </summary>
/// <param name="type"></param> /// <param name="type"></param>
public void BeAssaulted(string type) public void BeAssaulted(string type)
{ {
switch (type) { switch (type)
{
case "激光打击": case "激光打击":
GameObject Bao1 = Instantiate(explodePrefab, transform); AddBao(true);
Bao1.transform.localPosition = Vector3.zero; //Debug.Log(transform.name+"被激光打击销毁了");
Bao1.transform.SetParent(null);
Bao1.SetActive(true);
DistroyThis();
Debug.Log(transform.name+"被激光打击销毁了");
break; break;
case "无线电干扰": case "无线电干扰":
Vector3 _pos = transform.position - new Vector3(0, 30, 0); Vector3 _pos = transform.position - new Vector3(0, 30, 0);
transform.LookAt(_pos); transform.LookAt(_pos);
transform.DOMove(_pos, 1).OnComplete(() => { transform.DOMove(_pos, 1).OnComplete(() =>
GameObject Bao2 = Instantiate(explodePrefab, transform); {
Bao2.transform.localPosition = Vector3.zero; AddBao(true);
Bao2.transform.SetParent(null);
Bao2.SetActive(true);
DistroyThis();
}); });
Debug.Log(transform.name + "无人机被无线电干扰销毁了"); //Debug.Log(transform.name + "无人机被无线电干扰销毁了");
break; break;
case "攻击到目标": case "攻击到目标":
GameObject Bao3 = Instantiate(explodePrefab, transform); AddBao(true);
Bao3.transform.localPosition = Vector3.zero; //Debug.Log(transform.name + "无人机自杀式攻击销毁了");
Bao3.transform.SetParent(null);
Bao3.SetActive(true);
DistroyThis();
Debug.Log(transform.name + "无人机自杀式攻击销毁了");
break; break;
case "没有攻击到目标": case "没有攻击到目标":
GameObject Bao4 = Instantiate(explodePrefab, transform); AddBao(true);
Bao4.transform.localPosition = Vector3.zero; //Debug.Log(transform.name + "无人机自杀式没有攻击到目标撞击地面销毁了");
Bao4.transform.SetParent(null);
Bao4.SetActive(true);
DistroyThis();
Debug.Log(transform.name + "无人机自杀式销毁了");
break; break;
default: default:
break; break;
} }
} }
void DistroyThis() /// <summary>
/// 销毁单体无人机
/// </summary>
public void AddBao(bool isPassMessage)
{ {
if (isPassMessage)
{
string nowData = GetSyncDis();
Debug.Log(nowData);
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
}
GameObject Bao = Instantiate(explodePrefab, transform);
Bao.transform.localPosition = Vector3.zero;
Bao.transform.SetParent(null);
Bao.SetActive(true);
Destroy(gameObject); Destroy(gameObject);
// 获取组件
//Component component = gameObject.GetComponent<BoxCollider>();
//// 移除组件
//if (component != null)
//{
// Destroy(component);
// transform.localScale = Vector3.zero;
//}
} }
/// <summary>
/// 销毁蓝方设备
/// </summary>
/// <param name="_transform"></param>
void AddBao(Transform _transform)
{
EquipmentCommon _equipmentCommon = _transform.GetComponent<EquipmentCommon>();
string nowData = string.Format("{0},{1}", "SetToBeDestroyed", _equipmentCommon.deviceID);
Debug.Log(nowData);
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
GameObject Bao = Instantiate(explodePrefab, _transform);
Bao.transform.localPosition = Vector3.zero;
Bao.transform.SetParent(null);
Bao.SetActive(true);
Destroy(_transform.gameObject);
}
private void OnBecameInvisible()
{
Debug.Log("测试");
}
void OnDestroy() void OnDestroy()
{ {
transform.DOKill(); transform.DOKill();
//
} }
//位置实时传送
private string latestData = "";
public void AddSendMsg()
{
latestData = GetSyncData();
InvokeRepeating("SendMsg", 0, 0.01f);
}
public void SendMsg()
{
var nowData = GetSyncData();
if (!nowData.Equals(latestData))
{
latestData = nowData;
Debug.Log(latestData);
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
}
}
/// <summary>
/// 单个无人机位置传递
/// </summary>
/// <returns></returns>
protected string GetSyncData()
{
return string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", "SingleDronePosition", unmannedAerialVehicleManage.equipmentCommon.deviceID, serialNumber,
transform.localPosition.x, transform.localPosition.y, transform.localPosition.z,
transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z);
}
/// <summary>
/// 单个无人机被销毁
/// </summary>
/// <returns></returns>
protected string GetSyncDis()
{
return string.Format("{0},{1},{2}", "DroneWasDestroyed", unmannedAerialVehicleManage.equipmentCommon.deviceID, serialNumber);
}
} }

View File

@ -46,18 +46,6 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
public EquipmentCommon equipmentCommon; public EquipmentCommon equipmentCommon;
/// <summary>
/// 测试用
/// </summary>
public string msg;
/// <summary>
/// 测试接受数据
/// </summary>
private List<Weaponitem> weaponitems;
/// <summary>
/// 设备通用脚本
/// </summary>
private Weaponitemone weaponitemones;
/// <summary> /// <summary>
/// 无人机预制体 /// 无人机预制体
@ -130,10 +118,12 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
for (int i = 0; i < unmannedAerialVehicles.Count; i++)
{
unmannedAerialVehicles[i].serialNumber = (i + 1).ToString();
}
unmannedAerialVehicleManages.Add(this); unmannedAerialVehicleManages.Add(this);
equipmentCommon = GetComponent<EquipmentCommon>(); equipmentCommon = GetComponent<EquipmentCommon>();
//weaponitemones = Newtonsoft.Json.JsonConvert.DeserializeObject<Weaponitemone>(msg);
//FillInTheData(weaponitemones);//测试写入
Formation(1);//默认阵型 Formation(1);//默认阵型
// 订阅布尔值变化事件 // 订阅布尔值变化事件
OnActivationChanged += OnActivationChangedHandler; OnActivationChanged += OnActivationChangedHandler;
@ -150,6 +140,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
StartMoveObjectAlongPath(); StartMoveObjectAlongPath();
} }
} }
} }
/// <summary> /// <summary>
@ -257,15 +249,18 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
yield return new WaitForSeconds(0.1f); yield return new WaitForSeconds(0.1f);
for (int i = 0; i < unmannedAerialVehicles.Count; i++) for (int i = 0; i < unmannedAerialVehicles.Count; i++)
{ {
unmannedAerialVehicles[i].batteryLife = batteryLife; if (unmannedAerialVehicles[i] != null)
unmannedAerialVehicles[i].classificationWindResistance = classificationWindResistance; {
unmannedAerialVehicles[i].maximumFlyingSpeed = maximumFlyingSpeed; unmannedAerialVehicles[i].batteryLife = batteryLife;
unmannedAerialVehicles[i].RCS = RCS; unmannedAerialVehicles[i].classificationWindResistance = classificationWindResistance;
unmannedAerialVehicles[i].satellitePositioningFrequency = satellitePositioningFrequency; unmannedAerialVehicles[i].maximumFlyingSpeed = maximumFlyingSpeed;
unmannedAerialVehicles[i].dataLinkCommunicationFrequency = dataLinkCommunicationFrequency; unmannedAerialVehicles[i].RCS = RCS;
unmannedAerialVehicles[i].electronicReconnaissanceCapability = electronicReconnaissanceCapability; unmannedAerialVehicles[i].satellitePositioningFrequency = satellitePositioningFrequency;
unmannedAerialVehicles[i].opticalReconnaissanceCapability = opticalReconnaissanceCapability; unmannedAerialVehicles[i].dataLinkCommunicationFrequency = dataLinkCommunicationFrequency;
unmannedAerialVehicles[i].unmannedAerialVehicleManage = this; unmannedAerialVehicles[i].electronicReconnaissanceCapability = electronicReconnaissanceCapability;
unmannedAerialVehicles[i].opticalReconnaissanceCapability = opticalReconnaissanceCapability;
unmannedAerialVehicles[i].unmannedAerialVehicleManage = this;
}
} }
} }
#endregion #endregion
@ -316,7 +311,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
if (currentCount < totalObjects) if (currentCount < totalObjects)
{ {
Vector3 _vector3 = startPos + new Vector3(j * 2, 0, 0); Vector3 _vector3 = startPos + new Vector3(j * 2, 0, 0);
unmannedAerialVehicles[currentCount].transform.localPosition = _vector3; if (unmannedAerialVehicles[currentCount])
unmannedAerialVehicles[currentCount].transform.localPosition = _vector3;
currentCount++; currentCount++;
} }
else else
@ -350,7 +346,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
if (currentCount < totalObjects) if (currentCount < totalObjects)
{ {
Vector3 position = new Vector3(col * offsetX, 0, -row * offsetZ); Vector3 position = new Vector3(col * offsetX, 0, -row * offsetZ);
unmannedAerialVehicles[currentCount].transform.localPosition = position; if (unmannedAerialVehicles[currentCount])
unmannedAerialVehicles[currentCount].transform.localPosition = position;
currentCount++; currentCount++;
} }
} }
@ -431,7 +428,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
IEnumerator MoveObjectAlongPath(Vector3 positions) // 协程:按路线移动物体 IEnumerator MoveObjectAlongPath(Vector3 positions) // 协程:按路线移动物体
{ {
Vector3 targetPosition = positions + new Vector3(0, 10, 0);// 目标位置为当前顶点坐标 Vector3 targetPosition = new Vector3(positions.x, 10, 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);
@ -439,6 +436,11 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
yield return new WaitForSeconds(_time); // 等待一帧时间 yield return new WaitForSeconds(_time); // 等待一帧时间
isMove = true; isMove = true;
} }
private void OnDestroy()
{
OnActivationChanged -= OnActivationChangedHandler;
}
} }
public enum Pattern public enum Pattern