unity 选择图片点击确定保存,取消则不保存

时间:2024-12-24 18:20:10

RespString respString = SuperSportNative.getPersistentData(DataCenter.sound, false);
int len = respString.len;
string str = respString.buff;
int soundNum = 2;
Log.I(TAG, “len value:” + len + " str: " + str);
if (str.IsNullOrEmpty())
{
//初始情况下设置声浪为2
if (SuperSportNative.SwitchSoundWave(2))
{
// SuperSportNative.setPersistentData(DataCenter.sound, “2”, false);
DataCenter.savesoundvalue.Value = 2;
}
else
{
DataCenter.savesoundvalue.Value = 0;
}

        }
        else
        {
            if (int.TryParse(str, out soundNum))
            {
                if (soundNum == 0)
                {
                    //关闭声浪直接执行
                    SuperSportNative.SwitchSoundWave(soundNum);
                    DataCenter.savesoundvalue.Value = soundNum;
                    return;
                }
                // 声浪不为0的时候,需要判断能否打开声浪;声浪过热的时候,返回false
                if (SuperSportNative.SwitchSoundWave(soundNum))
                {
                    DataCenter.savesoundvalue.Value = soundNum;
                }
                else
                {
                    // 声浪打不开就能设置关闭
                    DataCenter.savesoundvalue.Value = 0;
                }

            }
        }

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UIFramework;
using System;
using UniRx;
public class MonophonicWaveRegulation : MonoBehaviour
{
// 声浪调节
[SerializeField]
private GameObject m_SoundWaveRegulation;
// 声浪调节 V8引擎
[SerializeField]
private Button Engine;
Vector3 vectorSoundWaveRegulation = new Vector3(-135f, -22f, 0f);
// 声浪调节 关
[SerializeField]
private Button Close;
Vector3 vectorClose = new Vector3(139f, -22f, 0f);
// 声浪调节 弹窗其他区域点击关闭弹窗
[SerializeField]
private Button MaskClose;
// 声浪调节 选中框
[SerializeField]
private Image Img_PitchOn;
Vector3 vectorPitchOnStart = new Vector3(-135f, -22f, 0f);

private PitchOn _currentlySelected = PitchOn.PitchEngine;

private PitchOn _savelySelected = PitchOn.PitchEngine;

private bool isClick = false;
enum PitchOn
{
    PitchEngine,
    PitchInductance,
    PitchClose
}

private static readonly string TAG = "SoundWaveRegulation";

private void Start()
{
    DataCenter.savesoundvalue.Subscribe(i =>
    {
        Log.I(TAG, "savesoundvalue value:" + i);
        if (DataCenter.savesoundvalue.Value == 2)
        {
            Img_PitchOn.transform.localPosition = vectorSoundWaveRegulation;
        }
        else
        {
            Img_PitchOn.transform.localPosition = vectorClose;
        }
    }).AddTo(this);

    //点击电感声浪按钮
    Engine.onClick.AddListener(() =>
    {
        Log.I(TAG, "Engine Button Clicked!");
        CancelInvoke("CloseWave");
        //Img_PitchOn.transform.localPosition = vectorSoundWaveRegulation;
        if (SuperSportNative.SwitchSoundWave(2))
        {
            DataCenter.savesoundvalue.Value = 2;
            SuperSportNative.setPersistentData(DataCenter.sound, "2", false);
            // 数据埋点
            DataTrackHelper.SetupDataTrackPoint("track_master_soundwave_settings","","","inductance");
        }
        else
        {
            Img_PitchOn.transform.localPosition = vectorSoundWaveRegulation;
            // 延迟1s执行按钮回弹
            Invoke("CloseWave", 1f);
        }

    });
    //点击关按钮  只是声浪的一种模式 不保存则数据无效  保存则静音
    Close.onClick.AddListener(() =>
    {
        Log.I(TAG, "Close Button Clicked!");
        //Img_PitchOn.transform.localPosition = vectorClose;
        SuperSportNative.SwitchSoundWave(0);
        DataCenter.savesoundvalue.Value = 0;
        SuperSportNative.setPersistentData(DataCenter.sound, "0", false);
        // 数据埋点
        DataTrackHelper.SetupDataTrackPoint("track_master_soundwave_settings", "","", "off");
    });
    //点击弹窗以外区域关闭当前弹窗 不保存数据
    MaskClose.onClick.AddListener(() =>
    {
        Log.I(TAG, "MaskClose Button Clicked!");
        m_SoundWaveRegulation.SetActive(false);
    });
}

private void CloseWave()
{
    DataCenter.savesoundvalue.Value = 0;
    Img_PitchOn.transform.localPosition = vectorClose;
}

}