修改数据格式,添加接受逻辑

This commit is contained in:
YangHua 2023-11-20 18:35:43 +08:00
parent bbd6889f3e
commit cddd9c869a
2 changed files with 51 additions and 33 deletions

View File

@ -17,10 +17,10 @@ public class GameManager : MonoBehaviour
public TenkokuModule tenkokuModule;
public System.Collections.Generic.List<ModelInfo> modelsInfo = new System.Collections.Generic.List<ModelInfo>();
public Transform dviceContent;
public GameObject wrjDrag;
public GameObject ldDrag;
public GameObject hpDrag;
public GameObject wxdDrag;
public DragController wrjDrag;
public DragController ldDrag;
public DragController hpDrag;
public DragController wxdDrag;
public GameObject Teacher;
public GameObject student;
// Start is called before the first frame update
@ -55,8 +55,8 @@ public class GameManager : MonoBehaviour
{
for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("蜂群无人机").device_count; i++)
{
GameObject wrj = Instantiate(wrjDrag, dviceContent);
wrj.GetComponent<DragController>().deviceID = UIBootstrap.Instance.GetDeviceByName("蜂群无人机").id;
DragController wrj = Instantiate(wrjDrag, dviceContent);
wrj.deviceID = UIBootstrap.Instance.GetDeviceByName("蜂群无人机").id;
}
}
}
@ -67,24 +67,24 @@ public class GameManager : MonoBehaviour
{
for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("探测雷达").device_count; i++)
{
GameObject ld = Instantiate(ldDrag, dviceContent);
ld.GetComponent<DragController>().deviceID = UIBootstrap.Instance.GetDeviceByName("探测雷达").id;
DragController ld = Instantiate(ldDrag, dviceContent);
ld.deviceID = UIBootstrap.Instance.GetDeviceByName("探测雷达").id;
}
}
if (UIBootstrap.Instance.GetDeviceByName("激光火控平台").device_count > 0)
{
for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("激光火控平台").device_count; i++)
{
GameObject hp = Instantiate(hpDrag, dviceContent);
hp.GetComponent<DragController>().deviceID = UIBootstrap.Instance.GetDeviceByName("激光火控平台").id;
DragController hp = Instantiate(hpDrag, dviceContent);
hp.deviceID = UIBootstrap.Instance.GetDeviceByName("激光火控平台").id;
}
}
if (UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").device_count > 0)
{
for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").device_count; i++)
{
GameObject wxd = Instantiate(wxdDrag, dviceContent);
wxd.GetComponent<DragController>().deviceID = UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").id;
DragController wxd = Instantiate(wxdDrag, dviceContent);
wxd.deviceID = UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").id;
}
}
}
@ -112,6 +112,7 @@ public class GameManager : MonoBehaviour
yield return new WaitForSeconds(0.5f);
Debug.Log(msg);
string[] data = msg.Split(',');
switch (data[0])
{
case "online":
@ -131,6 +132,20 @@ public class GameManager : MonoBehaviour
{
UnmannedAerialVehicleManage.unmannedAerialVehicleManages[i].isStartRehearsing = true;
}
break;
case "无人机List":
GameObject wrj = Instantiate(wrjDrag.model);
wrj.transform.position = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3]));
wrj.transform.eulerAngles = new Vector3(float.Parse(data[4]), float.Parse(data[5]), float.Parse(data[6]));
break;
case "地面无线电干扰":
break;
case "探测雷达":
break;
case "激光火控平台":
break;
case "Stop":
GlobalFlag.isStartRehearsing = false;

View File

@ -37,7 +37,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
/// 布尔值变化时触发的事件
/// </summary>
public event System.Action<bool> OnActivationChanged;
/// <summary>
/// 间隔时间
/// </summary>
@ -58,7 +58,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
/// 设备通用脚本
/// </summary>
private Weaponitemone weaponitemones;
/// <summary>
/// 无人机预制体
/// </summary>
@ -83,14 +83,14 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
/// <summary>
/// 已有路径
/// </summary>
public Queue<Vector3> positions=new Queue<Vector3>();
public Vector3 endPosition=new Vector3();
public Queue<Vector3> positions = new Queue<Vector3>();
public Vector3 endPosition = new Vector3();
/// <summary>
/// 飞行速度
/// </summary>
public float FireSpeed = 20.0f;
#region
/// <summary>
@ -137,7 +137,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
Formation(1);//默认阵型
// 订阅布尔值变化事件
OnActivationChanged += OnActivationChangedHandler;
}
// Update is called once per frame
@ -155,7 +155,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
}
}
}
if (isStartRehearsing && isStartRehearsing&&pattern == Pattern.)
if (isStartRehearsing && isStartRehearsing && pattern == Pattern.)
{
if (airRoute)
{
@ -169,7 +169,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
/// </summary>
public void modeSwitch(int patternCut)
{
switch (patternCut) {
switch (patternCut)
{
case 0://待机
pattern = Pattern.;
break;
@ -178,7 +179,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
break;
case 2:
pattern = Pattern.;
break;
default:
break;
@ -195,16 +196,16 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
{
if (newValue)
{
}
else
{
}
}
#endregion
#region
@ -216,13 +217,14 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
{
if (equipmentCommon)
{
string msg = $"send2room {equipmentCommon.equipmentType}+{transform.position.ToString().Replace(" ","")}+{transform.eulerAngles.ToString().Replace(" ", "")}";
string msg = $"send2room {equipmentCommon.equipmentType}+{transform.position.ToString().Replace(" ", "")}+{transform.eulerAngles.ToString().Replace(" ", "").Replace("(", "").Replace(")", "")}";
Debug.Log(msg);
_ = SyncCreateRoom.SendMessageAsync(msg);
}
for (int i=0;i< weaponitemone.Count; i++)
for (int i = 0; i < weaponitemone.Count; i++)
{
switch (weaponitemone[i].para_name) {
switch (weaponitemone[i].para_name)
{
case "续航时间:":
batteryLife = weaponitemone[i].para_value;
break;
@ -251,7 +253,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
default:
break;
}
if(i== (weaponitemone.Count - 1))
if (i == (weaponitemone.Count - 1))
{
StartCoroutine(WeaponitemoneDataAddition());
}
@ -265,7 +267,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
IEnumerator WeaponitemoneDataAddition()
{
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;
unmannedAerialVehicles[i].classificationWindResistance = classificationWindResistance;
@ -287,7 +289,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
/// <param name="number"></param>
public void Formation(int number)
{
switch (number) {
switch (number)
{
case 1:
GenerateFormation();
break;
@ -369,8 +372,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
{
Debug.Log("cols..:" + cols);
Debug.Log("rows..:" + rows);
box.center = new Vector3(cols-1, 0, -(rows-1));
box.size = new Vector3(cols*2, 1, 2 * rows);
box.center = new Vector3(cols - 1, 0, -(rows - 1));
box.size = new Vector3(cols * 2, 1, 2 * rows);
}
}
@ -431,7 +434,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
/// </summary>
public void StartMoveObjectAlongPath()
{
if (isMove&&positions.Count > 0)
if (isMove && positions.Count > 0)
{
isMove = false;
StartCoroutine(MoveObjectAlongPath(positions.Dequeue())); // 启动协程,按规划的路线移动物体