2026-05-18 08:42:33 +08:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Kill.Bluetooth;
|
|
|
|
|
using Kill.Bluetooth.Protocol;
|
|
|
|
|
using Kill.Core;
|
|
|
|
|
using Kill.Managers;
|
|
|
|
|
using Kill.UI.Components;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System;
|
|
|
|
|
using Unity.VisualScripting;
|
|
|
|
|
namespace Kill.UI.Pages
|
|
|
|
|
{
|
|
|
|
|
public class RGBlightSetting : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Switch onSwitch;
|
|
|
|
|
public ColorPicker colorPicker;
|
|
|
|
|
public MutiSelectPage mode;
|
|
|
|
|
private List<string> modeKeyList { get; set; } = new List<string> { "100167", "100168", "100169" };
|
|
|
|
|
private List<string> modestrList = new List<string>();
|
|
|
|
|
RGBControl setting;
|
|
|
|
|
Action<RGBControl> callback;
|
|
|
|
|
public void Init(Action<RGBControl> callback,RGBControl setting)
|
|
|
|
|
{
|
|
|
|
|
this.callback=callback;
|
|
|
|
|
this.setting=setting;
|
|
|
|
|
InitLanguageText();
|
|
|
|
|
//ReadLightSettings();
|
|
|
|
|
UpdateUI();
|
|
|
|
|
UIManager.Instance.RegisterBackAction(Back);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化语言文本
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitLanguageText()
|
|
|
|
|
{
|
|
|
|
|
modestrList.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var key in modeKeyList)
|
|
|
|
|
{
|
|
|
|
|
modestrList.Add(LanguageManager.Instance.GetLanguage(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取RGB设置
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ReadLightSettings()
|
|
|
|
|
{
|
2026-06-17 15:42:55 +08:00
|
|
|
if (DataManager.Instance.hasWifi && !DataManager.Instance.hasBluetooth)
|
|
|
|
|
{
|
|
|
|
|
var config = DataManager.Instance.deviceConfig;
|
|
|
|
|
this.setting = new RGBControl();
|
|
|
|
|
setting.Enable = config?.rgb_enable ?? false;
|
|
|
|
|
setting.SetColor(new Color((config?.rgb_red ?? 0) / 255f, (config?.rgb_green ?? 0) / 255f, (config?.rgb_blue ?? 0) / 255f));
|
|
|
|
|
setting.Effect = DeviceConfig.ParseServerEnum(config?.rgb_effect, RGBEffectMode.Blinking);
|
|
|
|
|
UpdateUI();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-05-18 08:42:33 +08:00
|
|
|
|
|
|
|
|
// 显示Loading
|
|
|
|
|
LoadingUI.Show();
|
|
|
|
|
|
|
|
|
|
// 读取rgb
|
|
|
|
|
BLECommunicationManager.Instance.ReadRGBControl((setting) =>
|
|
|
|
|
{
|
|
|
|
|
Loom.QueueOnMainThread(() =>
|
|
|
|
|
{
|
|
|
|
|
this.setting = setting;
|
|
|
|
|
UpdateUI();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-06-17 15:42:55 +08:00
|
|
|
private async void SetRGBSetting()
|
2026-05-18 08:42:33 +08:00
|
|
|
{
|
2026-06-17 15:42:55 +08:00
|
|
|
if (DataManager.Instance.hasWifi && !DataManager.Instance.hasBluetooth)
|
|
|
|
|
{
|
|
|
|
|
LoadingUI.Show();
|
|
|
|
|
bool success = await HomePageCtrl.Instance.SendBleCommandByWifiAsync(
|
|
|
|
|
BLEConstants.CMD_RGB_CONTROL, setting.ToBytes());
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
SyncRGBConfig();
|
|
|
|
|
UpdateUI();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ReadLightSettings();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 08:42:33 +08:00
|
|
|
LoadingUI.Show();
|
|
|
|
|
BLECommunicationManager.Instance.WriteRGBControl(setting, (success) =>
|
|
|
|
|
{
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
2026-06-17 15:42:55 +08:00
|
|
|
SyncRGBConfig();
|
2026-05-18 08:42:33 +08:00
|
|
|
UpdateUI();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ReadLightSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-17 15:42:55 +08:00
|
|
|
|
|
|
|
|
private void SyncRGBConfig()
|
|
|
|
|
{
|
|
|
|
|
var config = DataManager.Instance.deviceConfig;
|
|
|
|
|
config.rgb_enable = setting.Enable;
|
|
|
|
|
config.rgb_red = (byte)(setting.GetColor().r * 255);
|
|
|
|
|
config.rgb_green = (byte)(setting.GetColor().g * 255);
|
|
|
|
|
config.rgb_blue = (byte)(setting.GetColor().b * 255);
|
|
|
|
|
config.rgb_effect = DeviceConfig.ToServerString(setting.Effect);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 08:42:33 +08:00
|
|
|
public Image lightColor;
|
|
|
|
|
public Text modeValue;
|
|
|
|
|
private void UpdateUI()
|
|
|
|
|
{
|
|
|
|
|
onSwitch.Init(setting.Enable,ClickSwitch);
|
|
|
|
|
lightColor.color=setting.GetColor();
|
|
|
|
|
modeValue.text=modestrList[(int)setting.Effect];
|
|
|
|
|
LoadingUI.Hide();
|
|
|
|
|
UIManager.Instance.RegisterBackAction(Back);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClickSwitch(bool ison)
|
|
|
|
|
{
|
|
|
|
|
setting.Enable=ison;
|
|
|
|
|
SetRGBSetting();
|
|
|
|
|
}
|
|
|
|
|
public void ClickColor()
|
|
|
|
|
{
|
|
|
|
|
ColorPicker p=Instantiate(colorPicker.gameObject,transform).GetComponent<ColorPicker>();
|
|
|
|
|
p.Init(setting.GetColor());
|
|
|
|
|
p.gameObject.SetActive(true);
|
|
|
|
|
p.OnColorSelected+=SelectColor;
|
|
|
|
|
UIManager.Instance.RegisterBackAction(p.Sure);
|
|
|
|
|
}
|
|
|
|
|
public void SelectColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
setting.SetColor(color);
|
|
|
|
|
SetRGBSetting();
|
|
|
|
|
}
|
|
|
|
|
public void ClickMode()
|
|
|
|
|
{
|
|
|
|
|
MutiSelectPage m=Instantiate(mode.gameObject,transform).GetComponent<MutiSelectPage>();
|
|
|
|
|
m.Init((int)setting.Effect,SetMode);
|
|
|
|
|
m.gameObject.SetActive(true);
|
|
|
|
|
UIManager.Instance.RegisterBackAction(m.Cancel);
|
|
|
|
|
}
|
|
|
|
|
public void SetMode(int mode)
|
|
|
|
|
{
|
|
|
|
|
setting.Effect= (RGBEffectMode)mode;
|
|
|
|
|
SetRGBSetting();
|
|
|
|
|
}
|
|
|
|
|
public void Back()
|
|
|
|
|
{
|
|
|
|
|
callback?.Invoke(setting);
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|