更新ToggleController

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UIFramework;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using static PerformanceAdjusting;
using System.Linq;

public class ToggleController
{
    private SignalEnum _functionId = 0;
    private List<Toggle> _toggles;
    private List<Text> _texts;
    Action<int, List<Text>> _handle;
    private int _lastIndex = 0;
    private bool _rebound = false;

    public ToggleController(SignalEnum funcid, List<Toggle> toggles, List<Text> texts, Action<int, List<Text>> handle)
    {
        _functionId = funcid;
        _toggles = toggles;
        _texts = texts;
        _handle = handle;

        for (int i = 0; i < _toggles.Count; i++)
        {
            int index = i;
            _toggles[i].onValueChanged.AddListener((bool isOn) =>
            {
                if (isOn && !_rebound)
                {
                    // 发送消息
                    SuperSportNative.SetInt((int)_functionId, PerformanceDataCenter.toggleMapping[_functionId][(ToggleID)index]);
                    // 切换元素状态 文本字体颜色
                    _handle(index, _texts);
                    ToggleRebound(index, PerformanceDataCenter.toggleMapping[_functionId][(ToggleID)index]);
                }
            });
        }

        GetCurrentIndex();
    }

    private void ToggleRebound(int index, int value)
    {
        float timeCount = 0;
        DOTween.To(() => timeCount, a => timeCount = a, 1, 2).OnComplete(() =>
        {
            // 根据_functionId向底层获取当前值,与toggle选择时设置的值作对比
            int receive = 20;
            if (receive == value)
            {
                Debug.Log("设置成功");
                _lastIndex = index;
            }
            else
            {
                Debug.Log("设置失败,按钮回弹");
                _rebound = true;
                _toggles[_lastIndex].isOn = true;
                _handle(_lastIndex, _texts);
                _rebound = false;
            }
        });
    }

    private void GetCurrentIndex()
    {
        _rebound = true;
        // 根据_functionId向底层获取当前值,根据dictionary的值找键,设置当前toggle选中情况
        int index = (int)PerformanceDataCenter.toggleMapping[_functionId].FirstOrDefault().Key;
        index = 1;
        _lastIndex = index;
        _toggles[index].isOn = true;
        _handle(_lastIndex, _texts);
        _rebound = false;
    }
}