using AppUI.Bluetooth; using AppUI.Config; using AppUI.Util.Group; using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; namespace AppUI.View.Home.SettingsView { public class BowsSettingsView : MonoBehaviour { //ScreenDistance 相关 [SerializeField] TMP_Text screenSizeText; [SerializeField] TMP_Text distanceText; [SerializeField] TMP_InputField inputSize; //BoxLevel 相关 [SerializeField] BtnGroupSelector arrowWeightGroup; [SerializeField] BtnGroupSelector trainModeGroup; [SerializeField] BtnGroupSelector shootLevelGroup; [SerializeField] BtnGroupSelector bowAndArrowGroup; private void OnEnable() { //弓箭重量 InitArrowWeight(); //射击水平 InitShootLevel(); //训练模式 InitTrainMode(); //场景里面的弓箭手臂显示 InitBowAndArrow(); } void Start() { InitForRotateConvert(); } void SetScreenSize(float v) { string vStr = v.ToString("#0"); screenSizeText.text = vStr + "Inch"; } void SetScreenDistance(float v) { string vStr = v.ToString("#0.00"); distanceText.text = vStr + "M"; } void InitForRotateConvert() { UnityAction onEndEdit_inputSize = (string str) => { inputSize.SetTextWithoutNotify(""); float v = (float)System.Math.Round(double.Parse(str), 2); if (v < 1 || v > 120) { PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("输入值不在常规范围内")); return; } SetScreenSize(v); //save UserSettings.ins.bowRotateConvert.screenSize = v; UserSettings.ins.Save(); SetScreenDistance(UserSettings.ins.bowRotateConvert.GetAdviseScreenDistance()); }; inputSize.onEndEdit.AddListener(onEndEdit_inputSize); SetScreenSize(UserSettings.ins.bowRotateConvert.screenSize); SetScreenDistance(UserSettings.ins.bowRotateConvert.GetAdviseScreenDistance()); } void InitArrowWeight() { int index = System.Array.IndexOf( GlobalConfig.ArrowWeights, UserSettings.ins.actualArrowWeight); if (index < 0) index = 0; string[] texts = System.Array.ConvertAll( GlobalConfig.ArrowWeights, x => x.ToString()); arrowWeightGroup.Init( texts, index, (selectIndex) => { AudioMgr.ins.PlayBtn(); UserSettings.ins.actualArrowWeight = GlobalConfig.ArrowWeights[selectIndex]; UserSettings.ins.Save(); SmartBowDeviceHub.ins?.SyncArrowWeights(); }); } void InitTrainMode() { int index = UserSettings.ins.trainMode ? 0 : 1; trainModeGroup.Init( GlobalConfig.ButtonStrs, index, (selectIndex) => { AudioMgr.ins.PlayBtn(); UserSettings.ins.trainMode = selectIndex == 0; UserSettings.ins.Save(); }); } void InitShootLevel() { int index = UserSettings.ins.shootLevel; shootLevelGroup.Init( GlobalConfig.ShootLevelStrs, index, (selectIndex) => { AudioMgr.ins.PlayBtn(); UserSettings.ins.shootLevel = GlobalConfig.ShootLevels[selectIndex]; UserSettings.ins.Save(); }); } void InitBowAndArrow() { bowAndArrowGroup.Init( GlobalConfig.ButtonStrs, UserSettings.ins.openBowAndArrow ? 0 : 1, (selectIndex) => { AudioMgr.ins.PlayBtn(); UserSettings.ins.openBowAndArrow = selectIndex == 0; UserSettings.ins.Save(); //如果打开图标并且存在 hideInfraredBowAndArrow key时候,设置为0 if (UserSettings.ins.openBowAndArrow && PlayerPrefs.HasKey("hideInfraredBowAndArrow") && PlayerPrefs.GetInt("hideInfraredBowAndArrow") == 2 //armbow 设置 hideInfraredBowAndArrow = 2 状态下 操作面板才会 解开 红外的openBowAndArrow ) { PlayerPrefs.SetInt("hideInfraredBowAndArrow", 0); } }); } } }