2026-05-11 08:39:33 +08:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Kill.Managers;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
namespace Kill.UI.Pages
|
|
|
|
|
{
|
|
|
|
|
public class HomePageDevicePage : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public GameObject devicePrefab;
|
2026-05-18 08:42:33 +08:00
|
|
|
public GameObject typePrefab;
|
|
|
|
|
private string[] typeKey = new string[] { "100148", "100149" };
|
|
|
|
|
private string[] typeStr=new string[2];
|
2026-05-11 08:39:33 +08:00
|
|
|
public Transform deviceParent;
|
|
|
|
|
private List<GameObject> deviceList;
|
2026-05-18 08:42:33 +08:00
|
|
|
private List<GameObject> typeList;
|
2026-05-11 08:39:33 +08:00
|
|
|
private DeviceInfo lastSelectedDevice;
|
|
|
|
|
private DeviceInfo selectedDevice;
|
2026-05-18 08:42:33 +08:00
|
|
|
public Text selectedDeviceName;
|
2026-05-11 08:39:33 +08:00
|
|
|
public void InitDeviceList(List<DeviceInfo> ownedDevices, List<DeviceInfo> sharedDevices, DeviceInfo selectedDevice)
|
|
|
|
|
{
|
2026-05-18 08:42:33 +08:00
|
|
|
selectedDeviceName.text=selectedDevice.device_name;
|
|
|
|
|
typeStr[0]=LanguageManager.Instance.GetLanguage(typeKey[0]);
|
|
|
|
|
typeStr[1]=LanguageManager.Instance.GetLanguage(typeKey[1]);
|
2026-05-11 08:39:33 +08:00
|
|
|
lastSelectedDevice = selectedDevice;
|
|
|
|
|
this.selectedDevice = selectedDevice;
|
|
|
|
|
devicePrefab.SetActive(false);
|
2026-05-18 08:42:33 +08:00
|
|
|
typePrefab.SetActive(false);
|
2026-05-11 08:39:33 +08:00
|
|
|
if (deviceList != null && deviceList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in deviceList)
|
|
|
|
|
{
|
|
|
|
|
Destroy(item);
|
|
|
|
|
}
|
|
|
|
|
deviceList.Clear();
|
|
|
|
|
}
|
2026-05-18 08:42:33 +08:00
|
|
|
if (typeList != null && typeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in typeList)
|
|
|
|
|
{
|
|
|
|
|
Destroy(item);
|
|
|
|
|
}
|
|
|
|
|
typeList.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 08:39:33 +08:00
|
|
|
deviceList = new List<GameObject>();
|
2026-05-18 08:42:33 +08:00
|
|
|
typeList=new List<GameObject>();
|
|
|
|
|
if(ownedDevices!=null&&ownedDevices.Count>0)
|
|
|
|
|
{
|
|
|
|
|
Text type=Instantiate(typePrefab, deviceParent).GetComponent<Text>();
|
|
|
|
|
type.text=typeStr[0].Replace("{0}",ownedDevices.Count.ToString());
|
|
|
|
|
type.gameObject.SetActive(true);
|
|
|
|
|
typeList.Add(type.gameObject);
|
|
|
|
|
}
|
2026-05-11 08:39:33 +08:00
|
|
|
foreach (var device in ownedDevices)
|
|
|
|
|
{
|
|
|
|
|
var deviceItem = Instantiate(devicePrefab, deviceParent);
|
|
|
|
|
deviceItem.SetActive(true);
|
|
|
|
|
deviceItem.GetComponent<HomePageDeviceItem>().InitDeviceItem(device);
|
|
|
|
|
deviceList.Add(deviceItem);
|
|
|
|
|
deviceItem.gameObject.SetActive(true);
|
|
|
|
|
deviceItem.GetComponent<Button>().onClick.AddListener(() =>
|
|
|
|
|
{
|
|
|
|
|
OnClickDeviceItem(deviceItem);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-05-18 08:42:33 +08:00
|
|
|
if(sharedDevices!=null&&sharedDevices.Count>0)
|
|
|
|
|
{
|
|
|
|
|
Text type=Instantiate(typePrefab, deviceParent).GetComponent<Text>();
|
|
|
|
|
type.text=typeStr[1].Replace("{0}",sharedDevices.Count.ToString());
|
|
|
|
|
type.gameObject.SetActive(true);
|
|
|
|
|
typeList.Add(type.gameObject);
|
|
|
|
|
}
|
2026-05-11 08:39:33 +08:00
|
|
|
foreach (var device in sharedDevices)
|
|
|
|
|
{
|
|
|
|
|
var deviceItem = Instantiate(devicePrefab, deviceParent);
|
|
|
|
|
deviceItem.SetActive(true);
|
|
|
|
|
deviceItem.GetComponent<HomePageDeviceItem>().InitDeviceItem(device);
|
|
|
|
|
deviceList.Add(deviceItem);
|
|
|
|
|
deviceItem.gameObject.SetActive(true);
|
|
|
|
|
deviceItem.GetComponent<Button>().onClick.AddListener(() =>
|
|
|
|
|
{
|
|
|
|
|
OnClickDeviceItem(deviceItem);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (selectedDevice != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var deviceItem in deviceList)
|
|
|
|
|
{
|
|
|
|
|
if (deviceItem.GetComponent<HomePageDeviceItem>().deviceInfo.device_sn == selectedDevice.device_sn)
|
|
|
|
|
{
|
|
|
|
|
deviceItem.GetComponent<HomePageDeviceItem>().SetSelectedState(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnClickDeviceItem(GameObject deviceItem)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in deviceList)
|
|
|
|
|
{
|
|
|
|
|
item.GetComponent<HomePageDeviceItem>().SetSelectedState(item == deviceItem);
|
|
|
|
|
}
|
|
|
|
|
selectedDevice = deviceItem.GetComponent<HomePageDeviceItem>().deviceInfo;
|
2026-05-18 08:42:33 +08:00
|
|
|
selectedDeviceName.text=selectedDevice.device_name;
|
2026-05-11 08:39:33 +08:00
|
|
|
}
|
|
|
|
|
public void AddNewDevice()
|
|
|
|
|
{
|
|
|
|
|
UIManager.Instance.OpenPage(UIManager.PageName.connectDevicePage);
|
|
|
|
|
}
|
|
|
|
|
public void ClosePage()
|
|
|
|
|
{
|
|
|
|
|
if(lastSelectedDevice==selectedDevice)
|
|
|
|
|
{
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DataManager.Instance.SavaSelectedDeviceMac(selectedDevice.device_sn);
|
|
|
|
|
UIManager.Instance.OpenPage(UIManager.PageName.homePage,null,true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|