using System.Collections;
using System.Collections.Generic;
using TMPro;
using UIFramework;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using System;
public class Navigation : MonoBehaviour
{
// 驾驶调节 座椅调节
[SerializeField]
private Button DriveSet;
// 声浪调节
[SerializeField]
private Button SoundwaveSet;
// 性能调节
[SerializeField]
private Button PerformanceSet;
[SerializeField]
private TextMeshProUGUI PerformanceSettxt;
// 空调按钮
[SerializeField]
private Button AirConditionSet;
// 空调值
[SerializeField]
private TextMeshProUGUI AirConditionText;
// 空调开启文本
[SerializeField]
private TextMeshProUGUI AirSwitchText;
//空调按钮开关状态
private bool AirSwitchStatus;
//存储空调的开关值
private int AirSwitchValue;
//存储空调的值
private string AirSaveValue;
// 前窗除雾
[SerializeField]
private Button FrontWindowSet;
[SerializeField]
private TextMeshProUGUI FrontWindowtxt;
[SerializeField]
private Image FrontWindowimg;
[SerializeField]
private Sprite FrontWindowSelect;
[SerializeField]
private Sprite FrontWindowUnselect;
private bool isFrontWindowshow;
private int FrontWindowlastvalue;
// 后窗除雾
[SerializeField]
private Button BackWindowSet;
[SerializeField]
private TextMeshProUGUI BackWindowtxt;
[SerializeField]
private Image BackWindowimg;
[SerializeField]
private Sprite BackWindowSelect;
[SerializeField]
private Sprite BackWindowUnselect;
private bool isBackWindowshow;
private int BackWindowlastvalue;
//遮盖性能调节按钮,特别模式下此按钮正常显示但是点击不响应
[SerializeField]
private GameObject _objPerformancemask;
private static readonly string TAG = "Navigation";
// Start is called before the first frame update
void Start()
{
DataCenter.RaceModeSave.Subscribe(i =>
{
switch (i)
{
case 1:
_objPerformancemask.SetActive(false);
break;
case 2:
_objPerformancemask.SetActive(true);
break;
case 3:
_objPerformancemask.SetActive(false);
break;
case 4:
_objPerformancemask.SetActive(true);
break;
default:
break;
}
}).AddTo(this);
//点击驾驶调节按钮
DriveSet.onClick.AddListener(() =>
{
Log.I(TAG, "DriveSet Button Clicked!");
AliOSJSNI.CafCallJS("clickRightSeat");
});
//点击声浪调节按钮
SoundwaveSet.onClick.AddListener(() =>
{
Log.I(TAG, "SoundwaveSet Button Clicked!");
UIRoot.Get<PanelC_Main>().ShowMonophonicWaveRegulation(true);
});
//点击性能调节按钮
PerformanceSet.onClick.AddListener(() =>
{
Log.I(TAG, "PerformanceSet Button Clicked!");
UIRoot.Get<PanelC_Main>().ShowPerformanceAdjusting(true);
});
//当前空调温度的开关 0:关 1:开
DataCenter.AirTempSwitch.Subscribe(f =>
{
Log.I(TAG, "AirTempSwitch value: " + f);
if (f == 1)
{
AirSwitchStatus = true;
OnAirSwitchStatus(AirSwitchStatus);
}
else if (f == 0)
{
AirSwitchStatus = false;
OnAirSwitchStatus(AirSwitchStatus);
}
AirSwitchValue = f;
}).AddTo(this);
//点击空调按钮
AirConditionSet.onClick.AddListener(() =>
{
Log.I(TAG, "AirConditionSet Button Clicked!");
if (AirSwitchStatus)
{
Log.I(TAG, "Open Air!");
OnAirSwitchStatus(!AirSwitchStatus);
SuperSportNative.SetInt((int)SignalEnum.AirSwitch, 1);
Rebound(AirSwitchValue, AirSwitchStatus, 1, OnAirSwitchStatus, AirSwitchStatus);
}
else
{
Log.I(TAG, "Close Air!");
OnAirSwitchStatus(!AirSwitchStatus);
SuperSportNative.SetInt((int)SignalEnum.AirSwitch, 0);
Rebound(AirSwitchValue, AirSwitchStatus, 0, OnAirSwitchStatus, AirSwitchStatus);
}
});
//当前空调温度值显示
DataCenter.AirconditionTemperature.Subscribe(f =>
{
Log.I(TAG, "AirconditionTemperature value: " + f);
//小于等于18显示18 大于等于32
if (f <= 18)
{
AirConditionText.text = "Lo";
}
else if (f >= 32)
{
AirConditionText.text = "Hi";
}
else
{
AirConditionText.text = f.ToString() + "°";
}
AirSaveValue = AirConditionText.text;
}).AddTo(this);
// 前窗除雾设置为选中状态 ctrl.ac.front_defrost 2 关闭 1开启
DataCenter.FrontWindow.Subscribe(f =>
{
Log.I(TAG, "FrontWindow select value: " + f);
if (f == 1)
{
isFrontWindowshow = true;
OnClickFrontWindow(isFrontWindowshow);
}
else if (f == 2)
{
isFrontWindowshow = false;
OnClickFrontWindow(isFrontWindowshow);
}
FrontWindowlastvalue = f;
}).AddTo(this);
// 前窗除雾设置按钮
FrontWindowSet.onClick.AddListener(delegate ()
{
Log.I(TAG, "FrontWindowSet Button Clicked!");
if (isFrontWindowshow)
{
Log.I(TAG, "Open FrontWindow!");
OnClickFrontWindow(!isFrontWindowshow);
SuperSportNative.SetInt((int)SignalEnum.FrontWindow, 1);
Rebound(FrontWindowlastvalue, isFrontWindowshow, 1, OnClickFrontWindow, isFrontWindowshow);
}
else
{
Log.I(TAG, "Close FrontWindow!");
OnClickFrontWindow(!isFrontWindowshow);
SuperSportNative.SetInt((int)SignalEnum.FrontWindow, 2);
Rebound(FrontWindowlastvalue, isFrontWindowshow, 2, OnClickFrontWindow, isFrontWindowshow);
}
});
// 后窗除雾设置为选中状态 ctrl.ac.rear_defrost 0: 关闭 1 开启
DataCenter.BackWindow.Subscribe(f =>
{
Log.I(TAG, "BackWindow select value: " + f);
if (f == 1)
{
isBackWindowshow = true;
OnClickBackWindow(isBackWindowshow);
}
else if (f == 0)
{
isBackWindowshow = false;
OnClickBackWindow(isBackWindowshow);
}
BackWindowlastvalue = f;
}).AddTo(this);
// 后窗除雾设置按钮
BackWindowSet.onClick.AddListener(() =>
{
Log.I(TAG, "FrontWindowSet Button Clicked!");
if (isBackWindowshow)
{
OnClickBackWindow(!isBackWindowshow);
SuperSportNative.SetInt((int)SignalEnum.BackWindow, 1);
Rebound(BackWindowlastvalue, isBackWindowshow, 1, OnClickBackWindow, isBackWindowshow);
}
else
{
OnClickBackWindow(!isBackWindowshow);
SuperSportNative.SetInt((int)SignalEnum.BackWindow, 0);
Rebound(BackWindowlastvalue, isBackWindowshow, 0, OnClickBackWindow, isBackWindowshow);
}
});
DataCenter.Page.Subscribe(f =>
{
if (DataCenter.Page.Value == (int)Pages.Home)
{
PerformanceSet.enabled = false;
}
else
{
PerformanceSet.enabled = true;
}
}).AddTo(this);
}
/// <summary>
/// 空调开 高亮 空调关 置灰
/// </summary>
/// <param name="isSwitch"></param>
private void OnAirSwitchStatus(bool isSwitch)
{
if (isSwitch)
{
Log.I(TAG, "isSwitch value: " + isSwitch);
AirConditionText.color = new Color32(255, 255, 255, 255);
AirSwitchText.color = new Color32(255, 255, 255, 255);
}
else
{
Log.I(TAG, "isSwitch value: " + isSwitch);
AirConditionText.color = new Color32(255, 255, 255, 102);
AirSwitchText.color = new Color32(255, 255, 255, 102);
AirConditionText.text = AirSaveValue;
}
}
/// <summary>
/// 前窗 选中高亮
/// </summary>
/// <param name="issel">是否选中</param>
private void OnClickFrontWindow(bool issel)
{
if (issel)
{
FrontWindowimg.sprite = FrontWindowSelect;
FrontWindowtxt.color = new Color32(255, 141, 69, 255);
}
else
{
FrontWindowimg.sprite = FrontWindowUnselect;
FrontWindowtxt.color = new Color32(255, 255, 255, 255);
}
}
/// <summary>
/// 后窗 选中高亮
/// </summary>
/// <param name="issel">是否选中</param>
private void OnClickBackWindow(bool issel)
{
if (issel)
{
BackWindowimg.sprite = BackWindowSelect;
BackWindowtxt.color = new Color32(255, 141, 69, 255);
}
else
{
BackWindowimg.sprite = BackWindowUnselect;
BackWindowtxt.color = new Color32(255, 255, 255, 255);
}
}
private int _lastIndex = 0;
public void Rebound(int lastvalue, bool issel, int value, Action<bool> actionclick, bool selstatus)
{
float timeCount = 0;
DOTween.To(() => timeCount, a => timeCount = a, 1, 2).OnComplete(() =>
{
// 根据_functionId向底层获取当前值,与选择时设置的值作对比
Log.I(TAG, "按钮2秒回弹value select value: " + value);
if (lastvalue == value)
{
Log.I(TAG, "设置成功");
actionclick(issel);
Log.I(TAG, "设置成功FrontWindowlastvalue select value: " + selstatus);
}
else
{
Log.I(TAG, "设置失败,按钮回弹");
actionclick(!issel);
selstatus = !selstatus;
Log.I(TAG, "设置失败FrontWindowlastvalue select value: " + !selstatus);
}
});
}
private void Update()
{
if (DataCenter.isdisable)
{
PerformanceSet.interactable = true;
PerformanceSettxt.color = new Color32(255, 255, 255, 255);
}
else
{
PerformanceSet.interactable = false;
PerformanceSettxt.color = new Color32(255, 255, 255, 128);
}
}
}