添加动态获取分组操作

This commit is contained in:
YangHua 2024-02-29 00:34:02 +08:00
parent 95464f34f8
commit 730ca9d9e7
3 changed files with 79 additions and 27 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
@ -23,6 +24,7 @@ public class FormationManager : MonoSingleton<FormationManager>
public bool isStartFormation; public bool isStartFormation;
public List<FormationInfo> formationInfos = new List<FormationInfo>(); public List<FormationInfo> formationInfos = new List<FormationInfo>();
public FormationInfo formationInfo; public FormationInfo formationInfo;
public List<UnmannedAerialVehicleManage> allUavms = new List<UnmannedAerialVehicleManage>();
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
@ -123,8 +125,12 @@ public class FormationManager : MonoSingleton<FormationManager>
} }
} }
/// <summary>
public void SetGroupUAVMState(int uavmGroupID,int patternCut) /// 切换无人机状态
/// </summary>
/// <param name="uavmGroupID"></param>
/// <param name="patternCut"></param>
public void SetGroupUAVMState(int uavmGroupID, int patternCut)
{ {
List<UnmannedAerialVehicleManage> uavms = GroupUAVM(uavmGroupID); List<UnmannedAerialVehicleManage> uavms = GroupUAVM(uavmGroupID);
for (int j = 0; j < uavms.Count; j++) for (int j = 0; j < uavms.Count; j++)
@ -174,4 +180,47 @@ public class FormationManager : MonoSingleton<FormationManager>
formationInfo = null; formationInfo = null;
CheckBtns(0); CheckBtns(0);
} }
public int wrjCount = 0;
/// <summary>
/// 动态添加已经生成得数据
/// </summary>
public void WhenSpawn()
{
List<EquipmentCommon> equipList = DeviceManager.Instance.devices;
for (int i = 0; i < equipList.Count; i++)
{
int index = i;
if (equipList[index] != null && equipList[index].gameObject.layer == 11 && equipList[index].GetComponent<UnmannedAerialVehicleManage>())
{
if (!allUavms.Contains(equipList[index].GetComponent<UnmannedAerialVehicleManage>()))
{
allUavms.Add(equipList[index].GetComponent<UnmannedAerialVehicleManage>());
}
}
}
formationInfo = new FormationInfo();
for (int i = 0; i < allUavms.Count; i++)
{
if (allUavms[i].groupId == wrjCount)
{
formationInfo.groupIndex = wrjCount;
formationInfo.uavms.Add(allUavms[i]);
}
}
//wrjCount = -1;
//formationInfo = null;
//allUavms = .Where(x => x != null && x.gameObject.layer == 11 && x.GetComponent<UnmannedAerialVehicleManage>()).ToList();
//List<UnmannedAerialVehicleManage> uavms = DeviceManager.Instance.devices;
}
} }

View File

@ -447,21 +447,16 @@ public class GameManager : MonoSingleton<GameManager>
device.transform.position = new Vector3(float.Parse(deviceTran[0]), float.Parse(deviceTran[1]), float.Parse(deviceTran[2])); device.transform.position = new Vector3(float.Parse(deviceTran[0]), float.Parse(deviceTran[1]), float.Parse(deviceTran[2]));
device.transform.eulerAngles = new Vector3(float.Parse(deviceTran[3]), float.Parse(deviceTran[4]), float.Parse(deviceTran[5])); device.transform.eulerAngles = new Vector3(float.Parse(deviceTran[3]), float.Parse(deviceTran[4]), float.Parse(deviceTran[5]));
} }
UnmannedAerialVehicleManage uavm = device.GetComponent<UnmannedAerialVehicleManage>();
if (!string.IsNullOrEmpty(data.r2) || data.r2 != "") if (!string.IsNullOrEmpty(data.r2) || data.r2 != "")
{ {
int wrjModelCount = int.Parse(data.r2); int wrjModelCount = int.Parse(data.r2);
UnmannedAerialVehicleManage uavm = device.GetComponent<UnmannedAerialVehicleManage>();
if (uavm) if (uavm)
{ {
uavm.wrjModel = (WRJModel)wrjModelCount; uavm.wrjModel = (WRJModel)wrjModelCount;
device.name = uavm.wrjModel.ToString(); device.name = uavm.wrjModel.ToString();
int bdxx = int.Parse(data.bdxx); int bdxx = int.Parse(data.bdxx);
uavm.groupId = bdxx; uavm.groupId = bdxx;
if (bdxx != -1)
{
uavm.isGroup = true;
uavm.SetGroupTips(bdxx);
}
} }
} }
@ -472,12 +467,15 @@ public class GameManager : MonoSingleton<GameManager>
{ {
device.GetComponent<EquipmentCommon>().isPlayer = true; device.GetComponent<EquipmentCommon>().isPlayer = true;
} }
if (device.GetComponent<UnmannedAerialVehicleManage>()) if (uavm)
{ {
device.GetComponent<UnmannedAerialVehicleManage>().SetTipsColor(); uavm.SetTipsColor();
DroneViewDisplay.Instance.CreateUI(device.GetComponent<UnmannedAerialVehicleManage>(), false); DroneViewDisplay.Instance.CreateUI(uavm, false);
} }
FormationManager.Instance.WhenSpawn();
} }
private void OnGetRoomUsers(string obj) private void OnGetRoomUsers(string obj)

View File

@ -858,26 +858,31 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
IEnumerator WeaponitemoneDataAddition() IEnumerator WeaponitemoneDataAddition()
{ {
yield return new WaitForSeconds(0.01f); yield return new WaitForSeconds(0.01f);
for (int i = 0; i < unmannedAerialVehicles.Count; i++)
UnmannedAerialVehicle uav = unmannedAerialVehicles[0];
if (uav != null)
{ {
UnmannedAerialVehicle uav = unmannedAerialVehicles[i]; uav.unmannedAerialVehicleManage = this;
if (uav != null) uav.batteryLife = batteryLife;
uav.classificationWindResistance = classificationWindResistance;
uav.maximumFlyingSpeed = maximumFlyingSpeed;
uav.RCS = RCS;
uav.satellitePositioningFrequency = satellitePositioningFrequency;
uav.dataLinkCommunicationFrequency = dataLinkCommunicationFrequency;
uav.electronicReconnaissanceCapability = electronicReconnaissanceCapability;
uav.opticalReconnaissanceCapability = opticalReconnaissanceCapability;
uav.wrjModel = wrjModel;
if (uav.tips != null)
uav.tips.text = wrjModel.ToString();
if (groupId > -1)
{ {
uav.unmannedAerialVehicleManage = this; isGroup = true;
uav.batteryLife = batteryLife; SetGroupTips(groupId);
uav.classificationWindResistance = classificationWindResistance;
uav.maximumFlyingSpeed = maximumFlyingSpeed;
uav.RCS = RCS;
uav.satellitePositioningFrequency = satellitePositioningFrequency;
uav.dataLinkCommunicationFrequency = dataLinkCommunicationFrequency;
uav.electronicReconnaissanceCapability = electronicReconnaissanceCapability;
uav.opticalReconnaissanceCapability = opticalReconnaissanceCapability;
uav.wrjModel = wrjModel;
if (uav.tips != null)
uav.tips.text = wrjModel.ToString();
WRJName = wrjModel.ToString();
} }
Debug.Log($"++:badxx ==={groupId}");
WRJName = wrjModel.ToString();
} }
} }
#endregion #endregion