2026-05-11 08:39:33 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
2026-05-18 08:42:33 +08:00
|
|
|
|
using Kill.Bluetooth;
|
2026-05-11 08:39:33 +08:00
|
|
|
|
using Kill.Bluetooth.Protocol;
|
|
|
|
|
|
using Kill.Managers;
|
2026-05-18 08:42:33 +08:00
|
|
|
|
using Kill.UI.Components;
|
2026-05-11 08:39:33 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Kill.UI.Pages
|
|
|
|
|
|
{
|
|
|
|
|
|
public class HomePageDeviceCtrl : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设备控制按钮 开关 fov 距离 补光灯 安全 待机 扫描 消杀
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Button[] deviceCtrlButtons;
|
|
|
|
|
|
public Image deviceCtrlIcon;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设备控制图标 0:关机 1:开机
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Sprite[] deviceCtrlIconSprites;
|
|
|
|
|
|
private bool isDeviceOn = false;
|
|
|
|
|
|
public void InitDeviceControl(bool isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceCtrlIcon.sprite=deviceCtrlIconSprites[isOn?1:0];
|
|
|
|
|
|
foreach(var button in deviceCtrlButtons)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.interactable=isOn;
|
|
|
|
|
|
}
|
2026-05-18 08:42:33 +08:00
|
|
|
|
deviceCtrlButtons[0].interactable=true;
|
2026-05-11 08:39:33 +08:00
|
|
|
|
isDeviceOn=isOn;
|
2026-05-18 08:42:33 +08:00
|
|
|
|
if(!isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitFovText(0);
|
|
|
|
|
|
InitLensText(0, 0);
|
|
|
|
|
|
InitLightText(false);
|
|
|
|
|
|
InitSafeText(false);
|
|
|
|
|
|
InitWrokMode(-1);
|
|
|
|
|
|
}
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 0:未连接无值 1:有值
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Color[] valueColors;
|
|
|
|
|
|
public Text fovText;
|
|
|
|
|
|
public void InitFovText(int fov)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (fov == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
fovText.text="--";
|
|
|
|
|
|
fovText.color=valueColors[0];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
fovText.color=valueColors[1];
|
|
|
|
|
|
fovText.text=fov.ToString()+"°";
|
|
|
|
|
|
}
|
|
|
|
|
|
public Text lensText;
|
|
|
|
|
|
public void InitLensText(float lens,int unit)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(lens==0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lensText.text="--";
|
|
|
|
|
|
lensText.color=valueColors[0];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
lensText.color=valueColors[1];
|
|
|
|
|
|
if(unit==0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lensText.text=lens.ToString("F1");
|
2026-05-18 08:42:33 +08:00
|
|
|
|
lensText.text+="m";
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-06-08 08:55:10 +08:00
|
|
|
|
int lensFt=Mathf.RoundToInt((float)(lens * 3.28084));
|
2026-05-11 08:39:33 +08:00
|
|
|
|
lensText.text=lensFt.ToString();
|
2026-05-18 08:42:33 +08:00
|
|
|
|
lensText.text+="ft";
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public Image lightIcon;
|
|
|
|
|
|
public Sprite[] lightIconSprites;
|
|
|
|
|
|
public Text lightText;
|
|
|
|
|
|
public void InitLightText(bool isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
string stateStr=LanguageManager.Instance.GetLanguage(isOn?"100099":"100100");
|
|
|
|
|
|
lightText.text=stateStr;
|
|
|
|
|
|
lightIcon.sprite=lightIconSprites[isOn?1:0];
|
|
|
|
|
|
}
|
|
|
|
|
|
public Image safeIcon;
|
|
|
|
|
|
public Sprite[] safeIconSprites;
|
|
|
|
|
|
public Text safeText;
|
|
|
|
|
|
public void InitSafeText(bool isVisualOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool isOn=isVisualOn;
|
|
|
|
|
|
string stateStr=LanguageManager.Instance.GetLanguage(isOn?"100099":"100100");
|
|
|
|
|
|
safeText.text=stateStr;
|
|
|
|
|
|
safeIcon.sprite=safeIconSprites[isOn?1:0];
|
|
|
|
|
|
}
|
|
|
|
|
|
public Color[] workModeColors;
|
|
|
|
|
|
public Text[] workModeTexts;
|
|
|
|
|
|
public Image standbyIcon;
|
|
|
|
|
|
public Sprite[] standbyIconSprites;
|
|
|
|
|
|
public Button standbyButton;
|
|
|
|
|
|
|
|
|
|
|
|
public Image scanIcon;
|
|
|
|
|
|
public Sprite[] scanIconSprites;
|
|
|
|
|
|
public Button scanButton;
|
|
|
|
|
|
|
|
|
|
|
|
public Image armedIcon;
|
|
|
|
|
|
public Sprite[] armedIconSprites;
|
|
|
|
|
|
public Button armedButton;
|
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 绑定工作模式按钮点击事件(先移除避免重复绑定)
|
|
|
|
|
|
if (standbyButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
standbyButton.onClick.RemoveAllListeners();
|
|
|
|
|
|
standbyButton.onClick.AddListener(() => OnWorkModeButtonClick(0));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (scanButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
scanButton.onClick.RemoveAllListeners();
|
|
|
|
|
|
scanButton.onClick.AddListener(() => OnWorkModeButtonClick(1));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (armedButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
armedButton.onClick.RemoveAllListeners();
|
|
|
|
|
|
armedButton.onClick.AddListener(() => OnWorkModeButtonClick(2));
|
|
|
|
|
|
}
|
2026-05-18 08:42:33 +08:00
|
|
|
|
if(deviceCtrlButtons[0]!=null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceCtrlButtons[0].onClick.RemoveAllListeners();
|
|
|
|
|
|
deviceCtrlButtons[0].onClick.AddListener(() => OnLockButtonClick());
|
|
|
|
|
|
}
|
2026-05-11 08:39:33 +08:00
|
|
|
|
if(deviceCtrlButtons[1]!=null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceCtrlButtons[1].onClick.RemoveAllListeners();
|
|
|
|
|
|
deviceCtrlButtons[1].onClick.AddListener(() => OnFovSettingButtonClick());
|
|
|
|
|
|
}
|
|
|
|
|
|
if(deviceCtrlButtons[2]!=null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceCtrlButtons[2].onClick.RemoveAllListeners();
|
|
|
|
|
|
deviceCtrlButtons[2].onClick.AddListener(() => OnLensSettingButtonClick());
|
|
|
|
|
|
}
|
|
|
|
|
|
if(deviceCtrlButtons[3]!=null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceCtrlButtons[3].onClick.RemoveAllListeners();
|
|
|
|
|
|
deviceCtrlButtons[3].onClick.AddListener(() => OnLightSettingButtonClick());
|
|
|
|
|
|
}
|
|
|
|
|
|
if(deviceCtrlButtons[4]!=null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceCtrlButtons[4].onClick.RemoveAllListeners();
|
|
|
|
|
|
deviceCtrlButtons[4].onClick.AddListener(() => OnSafetySettingButtonClick());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-08 08:55:10 +08:00
|
|
|
|
public MultiAnimationPLay bowenAni;
|
2026-05-11 08:39:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// -1:未连接 0:待机 1:扫描 2:消杀
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mode"></param>
|
|
|
|
|
|
public void InitWrokMode(int mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 更新当前工作模式
|
|
|
|
|
|
currentWorkMode = mode;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var text in workModeTexts)
|
|
|
|
|
|
{
|
|
|
|
|
|
text.color = workModeColors[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
standbyIcon.sprite = standbyIconSprites[0];
|
|
|
|
|
|
scanIcon.sprite = scanIconSprites[0];
|
|
|
|
|
|
armedIcon.sprite = armedIconSprites[0];
|
2026-06-08 08:55:10 +08:00
|
|
|
|
if (mode < 0 || mode > 2)
|
2026-05-11 08:39:33 +08:00
|
|
|
|
{
|
2026-06-08 08:55:10 +08:00
|
|
|
|
bowenAni.StopAni();
|
|
|
|
|
|
return;
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
2026-06-08 08:55:10 +08:00
|
|
|
|
if (mode==0)
|
2026-05-11 08:39:33 +08:00
|
|
|
|
{
|
|
|
|
|
|
standbyIcon.sprite=standbyIconSprites[1];
|
|
|
|
|
|
workModeTexts[0].color=workModeColors[1];
|
2026-06-08 08:55:10 +08:00
|
|
|
|
bowenAni.StopAni();
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if(mode==1)
|
|
|
|
|
|
{
|
|
|
|
|
|
scanIcon.sprite=scanIconSprites[1];
|
|
|
|
|
|
workModeTexts[1].color=workModeColors[1];
|
2026-06-08 08:55:10 +08:00
|
|
|
|
bowenAni.PlayAni();
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if(mode==2)
|
|
|
|
|
|
{
|
|
|
|
|
|
armedIcon.sprite=armedIconSprites[1];
|
|
|
|
|
|
workModeTexts[2].color=workModeColors[1];
|
2026-06-08 08:55:10 +08:00
|
|
|
|
bowenAni.PlayAni();
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 当前工作模式 -1:未连接 0:待机 1:扫描 2:消杀
|
|
|
|
|
|
private int currentWorkMode = -1;
|
|
|
|
|
|
|
|
|
|
|
|
public int GetCurrentWorkMode()
|
|
|
|
|
|
{
|
|
|
|
|
|
return currentWorkMode;
|
|
|
|
|
|
}
|
2026-05-18 08:42:33 +08:00
|
|
|
|
public void OnLockButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadingUI.Show();
|
|
|
|
|
|
bool aim=!isDeviceOn;
|
|
|
|
|
|
HomePageCtrl.Instance?.SetLock(aim);
|
|
|
|
|
|
}
|
2026-05-11 08:39:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置工作模式按钮点击事件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mode">目标模式 0:待机 1:扫描 2:消杀</param>
|
|
|
|
|
|
public void OnWorkModeButtonClick(int mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 如果点击的是当前模式,不响应
|
|
|
|
|
|
if (mode == currentWorkMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log($"[HomePageDeviceCtrl] 点击的模式 {mode} 与当前模式相同,不响应");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 通知 HomePageCtrl 切换工作模式(Loading 在 SetWorkMode 中显示)
|
|
|
|
|
|
HomePageCtrl.Instance?.SetWorkMode(mode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnFovSettingButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
HomePageCtrl.Instance?.ShowFovSettingPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnLensSettingButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
HomePageCtrl.Instance?.ShowLensSettingPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnLightSettingButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
HomePageCtrl.Instance?.ShowLightSettingPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnSafetySettingButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
HomePageCtrl.Instance?.ShowSafetySettingPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|