137 lines
4.2 KiB
C#
137 lines
4.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
[Serializable]
|
|
public class FormationInfo
|
|
{
|
|
public int groupName;
|
|
public List<UnmannedAerialVehicleManage> uavms = new List<UnmannedAerialVehicleManage>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编队控制脚本
|
|
/// </summary>
|
|
public class FormationManager : MonoSingleton<FormationManager>
|
|
{
|
|
public Button startFormationBtn;
|
|
public Button submitFormationBtn;
|
|
public bool isStartFormation;
|
|
public List<FormationInfo> formationInfos = new List<FormationInfo>();
|
|
public FormationInfo formationInfo;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
startFormationBtn.onClick.AddListener(OnStartFormation);
|
|
submitFormationBtn.onClick.AddListener(OnSubmit);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (isStartFormation)
|
|
{
|
|
if (Input.GetKey(KeyCode.LeftControl) && Input.GetMouseButtonDown(0))
|
|
{
|
|
if (EventSystem.current.IsPointerOverGameObject()) return;
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hitInfo;
|
|
if (Physics.Raycast(ray, out hitInfo, 1000))
|
|
{
|
|
if (hitInfo.collider.gameObject.tag == "WRJ")
|
|
{
|
|
UnmannedAerialVehicleManage uavmTemp = hitInfo.collider.gameObject.GetComponent<UnmannedAerialVehicleManage>();
|
|
if (uavmTemp != null && !uavmTemp.isGroup)
|
|
{
|
|
if (!formationInfo.uavms.Contains(uavmTemp))
|
|
{
|
|
uavmTemp.isGroup = true;
|
|
uavmTemp.groupId = formationInfo.groupName;
|
|
formationInfo.uavms.Add(uavmTemp);
|
|
}
|
|
}
|
|
Debug.Log("拾取");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置组中得无人机所有航线
|
|
/// </summary>
|
|
public void SetUAVMGroupAirRoute(int uavmGroupID, Vector3 pos)
|
|
{
|
|
List<UnmannedAerialVehicleManage> uavms = new List<UnmannedAerialVehicleManage>();
|
|
for (int i = 0; i < formationInfos.Count; i++)
|
|
{
|
|
int indexI = i;
|
|
if (formationInfos[indexI].groupName == uavmGroupID)
|
|
{
|
|
uavms = formationInfos[indexI].uavms;
|
|
}
|
|
}
|
|
for (int j = 0; j < uavms.Count; j++)
|
|
{
|
|
uavms[j].positions.Enqueue(pos);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 清除组内所有无人机得航线
|
|
/// </summary>
|
|
/// <param name="uavmGroupID"></param>
|
|
public void RemoveUAMGroupAirRoute(int uavmGroupID)
|
|
{
|
|
List<UnmannedAerialVehicleManage> uavms = new List<UnmannedAerialVehicleManage>();
|
|
for (int i = 0; i < formationInfos.Count; i++)
|
|
{
|
|
int indexI = i;
|
|
if (formationInfos[indexI].groupName == uavmGroupID)
|
|
{
|
|
uavms = formationInfos[indexI].uavms;
|
|
}
|
|
}
|
|
for (int j = 0; j < uavms.Count; j++)
|
|
{
|
|
uavms[j].positions.Clear();
|
|
}
|
|
}
|
|
|
|
public void SetAirRouteObj(int uavmGroupID, GameObject _airRoute)
|
|
{
|
|
List<UnmannedAerialVehicleManage> uavms = new List<UnmannedAerialVehicleManage>();
|
|
for (int i = 0; i < formationInfos.Count; i++)
|
|
{
|
|
int indexI = i;
|
|
if (formationInfos[indexI].groupName == uavmGroupID)
|
|
{
|
|
uavms = formationInfos[indexI].uavms;
|
|
}
|
|
}
|
|
for (int j = 0; j < uavms.Count; j++)
|
|
{
|
|
if (!uavms[j].airRoute)
|
|
{
|
|
uavms[j].airRoute = _airRoute;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnStartFormation()
|
|
{
|
|
isStartFormation = true;
|
|
formationInfo = new FormationInfo();
|
|
formationInfo.groupName = formationInfos.Count;
|
|
}
|
|
|
|
public void OnSubmit()
|
|
{
|
|
isStartFormation = false;
|
|
if (!formationInfos.Contains(formationInfo))
|
|
formationInfos.Add(formationInfo);
|
|
}
|
|
}
|