NewN_UAVPlane/Assets/Zion/Scripts/Adam/Components/PostureController.cs

74 lines
2.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>();
public DeviceManager deviceManager;
public Transform redContanier;
public Transform blueContanier;
public DeviceBtnItem deviceBtnItem;
// Start is called before the first frame update
void Awake()
{
deviceManager = DeviceManager.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++)
{
DeviceBtnItem obj = Instantiate(deviceBtnItem, redContanier);
obj.selfBtn.onClick.AddListener(() =>
{
OnDeviceBtn(obj.id);
});
}
for (int i = 0; i < blueObjs.Count; i++)
{
DeviceBtnItem obj = Instantiate(deviceBtnItem, blueContanier);
obj.selfBtn.onClick.AddListener(() =>
{
OnDeviceBtn(obj.id);
});
}
}
private void OnDeviceBtn(string id)
{
Debug.Log(id);
}
}