unity 按钮回弹根据新接到的信号设置

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);
    }
}

}

相关推荐
蔗理苦10 分钟前
2024-12-24 NO1. XR Interaction ToolKit 环境配置
unity·quest3·xr toolkit
花生糖@12 分钟前
Android XR 应用程序开发 | 从 Unity 6 开发准备到应用程序构建的步骤
android·unity·xr·android xr
向宇it42 分钟前
【从零开始入门unity游戏开发之——unity篇02】unity6基础入门——软件下载安装、Unity Hub配置、安装unity编辑器、许可证管理
开发语言·unity·c#·编辑器·游戏引擎
虾球xz1 小时前
游戏引擎学习第55天
学习·游戏引擎
yngsqq1 小时前
一键打断线(根据相交点打断)——CAD c# 二次开发
windows·microsoft·c#
TENET信条2 小时前
day53 第十一章:图论part04
开发语言·c#·图论
虾球xz3 小时前
游戏引擎学习第58天
学习·游戏引擎
anlog3 小时前
C#在自定义事件里传递数据
开发语言·c#·自定义事件
ue星空5 小时前
虚幻引擎结构之UWorld
游戏引擎·虚幻
ue星空5 小时前
虚幻引擎结构之ULevel
游戏引擎·虚幻