110 lines
3.0 KiB
C#
110 lines
3.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PostureController : MonoBehaviour
|
|
{
|
|
public List<EquipmentCommon> redObjs = new List<EquipmentCommon>();
|
|
public List<EquipmentCommon> blueObjs = new List<EquipmentCommon>();
|
|
private DeviceManager deviceManager;
|
|
public Transform redContanier;
|
|
public Transform blueContanier;
|
|
public DeviceBtnItem deviceBtnItem;
|
|
public RawImage redShowImage;
|
|
public RawImage blueShowImage;
|
|
private DroneViewDisplay droneViewDisplay;
|
|
// Start is called before the first frame update
|
|
void Awake()
|
|
{
|
|
deviceManager = DeviceManager.Instance;
|
|
droneViewDisplay = DroneViewDisplay.Instance;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
GetSceneInfo();
|
|
}
|
|
|
|
private void GetSceneInfo()
|
|
{
|
|
redObjs = deviceManager.devices.Where(x => x != null && x.gameObject.layer == 11).ToList();
|
|
blueObjs = deviceManager.devices.Where(x => x != null && x.gameObject.layer == 12).ToList();
|
|
if (redContanier.childCount > 0)
|
|
{
|
|
for (int i = 0; i < redContanier.childCount; i++)
|
|
{
|
|
Destroy(redContanier.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
if (blueContanier.childCount > 0)
|
|
{
|
|
for (int i = 0; i < blueContanier.childCount; i++)
|
|
{
|
|
Destroy(blueContanier.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
for (int i = 0; i < redObjs.Count; i++)
|
|
{
|
|
CreatDeviceItem(redContanier, redObjs[i].name, redObjs[i].deviceID, 0);
|
|
redObjs[i].onDeviceDelete += RemoveItem;
|
|
}
|
|
for (int i = 0; i < blueObjs.Count; i++)
|
|
{
|
|
CreatDeviceItem(blueContanier, blueObjs[i].name, blueObjs[i].deviceID, 1);
|
|
blueObjs[i].onDeviceDelete += RemoveItem;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 实时更新设备列表
|
|
/// </summary>
|
|
|
|
public void RemoveItem(string id)
|
|
{
|
|
for (int i = 0; i < redObjs.Count; i++)
|
|
{
|
|
if (redObjs[i].deviceID == id)
|
|
{
|
|
redObjs.Remove(redObjs[i]);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CreatDeviceItem(Transform contanier, string objName, string id, int redOrBlue)
|
|
{
|
|
DeviceBtnItem obj = Instantiate(deviceBtnItem, contanier);
|
|
obj.SetInfo(id, objName);
|
|
obj.selfBtn.onClick.AddListener(() =>
|
|
{
|
|
OnDeviceBtn(id, redOrBlue);
|
|
});
|
|
|
|
}
|
|
|
|
private void OnDeviceBtn(string id, int redOrBlue)
|
|
{
|
|
if (droneViewDisplay.renderTextureTo(id) == null) return;
|
|
if (string.IsNullOrEmpty(id)) return;
|
|
if (redOrBlue == 0)
|
|
{
|
|
RenderTexture t = droneViewDisplay.renderTextureTo(id);
|
|
redShowImage.texture = t;
|
|
}
|
|
else
|
|
{
|
|
blueShowImage.texture = droneViewDisplay.renderTextureTo(id);
|
|
|
|
}
|
|
Debug.Log(id);
|
|
}
|
|
}
|