using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using System.Linq; namespace SmartBow { public class SettingsView : JCUnityLib.ViewBase, MenuBackInterface { [SerializeField] Transform panelLeftContent; [SerializeField] Transform BtnNewUserObj; [SerializeField] Text GameVersionText; void Start() { PersistenHandler.ins?.menuBackCtr.views.Add(this); //ShowBoxSound(true); switch (CommonConfig.OP) { case OperatingPlatform.A: if (CommonConfig.bInfraredApp) { //隐藏弓到屏幕的距离 Dictionary actionMapInfrared= new Dictionary { { "BtnSound", null }, { "BtnLanguage", null }, { "BtnNewUser", null }, { "BtnLevel", null }, { "BtnUserAgreement", null }, { "BtnPrivacyPolicy", null }, { "BtnAboutUs", null } }; SortChildObjects(actionMapInfrared); } else { Dictionary actionMapA = new Dictionary { { "BtnSound", null }, { "BtnLanguage", null }, { "BtnNewUser", null }, { "BtnScreenDistance", null },//弓到屏幕的距离 { "BtnLevel", null }, { "BtnUserAgreement", null }, { "BtnPrivacyPolicy", null }, { "BtnAboutUs", null } }; SortChildObjects(actionMapA); } break; case OperatingPlatform.B: // 定义排序字典 Dictionary actionMapB = new Dictionary { { "BtnSound", null }, { "BtnLanguage", null }, { "BtnLevel", null }, { "BtnUserSettings", null }, { "BtnBackStageManagement", null }, { "BtnAboutUs", null } }; SortChildObjects(actionMapB); break; case OperatingPlatform.C: //隐藏弓到屏幕的距离 Dictionary actionMapInfraredC = new Dictionary { { "BtnSound", null }, { "BtnLanguage", null }, { "BtnNewUser", null }, { "BtnLevel", null }, { "BtnUserAgreement", null }, { "BtnPrivacyPolicy", null }, { "BtnAboutUs", null } }; SortChildObjects(actionMapInfraredC); break; } } void SortChildObjects(Dictionary actionMap) { // 查找子对象并按名称填充 actionMap foreach (Transform child in panelLeftContent) { if (actionMap.ContainsKey(child.name)) { actionMap[child.name] = child; } else { // 如果子对象不在 actionMap 中,则隐藏它 child.gameObject.SetActive(false); } } // 获取按字典定义顺序的子对象列表(过滤掉未找到的对象) var sortedChildren = actionMap.Values.Where(child => child != null).ToList(); // 重新排列子对象 for (int i = 0; i < sortedChildren.Count; i++) { sortedChildren[i].SetSiblingIndex(i); } } void OnDestroy() { PersistenHandler.ins?.menuBackCtr.views.Remove(this); } public bool OnMenuBack() { ViewManager2.HideView(ViewManager2.Path_SettingsView); return true; } //模拟点击新手教程按钮 public void OnClick_BtnNewUser() { this.OnClick_PanelLeftItem(BtnNewUserObj.transform); } public void OnClick_PanelLeftItem(Transform target) { foreach (Transform item in panelLeftContent) { if (item.name == "BtnSignOut") continue; if (item == target) { item.Find("Text").GetComponent().fontStyle = FontStyle.Bold; item.Find("Text").GetComponent().color = Color.white; bool oldActive = item.Find("LightMask").gameObject.activeSelf; item.Find("LightMask").gameObject.SetActive(true); if (!oldActive) { AudioMgr.ins.PlayBtn(); ShowBox(item.name); } } else { item.Find("Text").GetComponent().fontStyle = FontStyle.Normal; item.Find("Text").GetComponent().color = Color.gray; item.Find("LightMask").gameObject.SetActive(false); } } } void ShowBox(string itemName) { // 定义所有 ShowBox 方法,并将初始状态设为 false var actionMap = new Dictionary> { { "BtnSound", ShowBoxSound }, { "BtnLevel", ShowBoxLevel }, { "BtnNewUser", ShowBoxNewUser }, { "BtnUserSettings", ShowBoxUserSettings }, { "BtnBackStageManagement",ShowBackStageManagement}, { "BtnLanguage", ShowBoxLanguage }, { "BtnUserAgreement", ShowBoxUserAgreement }, { "BtnPrivacyPolicy", ShowBoxPrivacyPolicy }, { "BtnAboutUs", ShowBoxAboutUs } }; // 如果不是红外应用,则包括 BtnScreenDistance if (!CommonConfig.bInfraredApp) { actionMap["BtnScreenDistance"] = ShowBoxScreenDistance; } // 先将所有状态设为 false foreach (var action in actionMap.Values) { action(false); } // 将指定的 itemName 对应的按钮设为 true if (actionMap.TryGetValue(itemName, out var selectedAction)) { selectedAction(true); } } //void ShowBox(string itemName) //{ // ShowBoxSound(itemName == "BtnSound"); // ShowBoxLevel(itemName == "BtnLevel"); // ShowBoxNewUser(itemName == "BtnNewUser"); // ShowBoxUserSettings(itemName == "BtnUserSettings"); // if (!CommonConfig.bInfraredApp)ShowBoxScreenDistance(itemName == "BtnScreenDistance"); // ShowBoxLanguage(itemName == "BtnLanguage"); // ShowBoxUserAgreement(itemName == "BtnUserAgreement"); // ShowBoxPrivacyPolicy(itemName == "BtnPrivacyPolicy"); // ShowBoxAboutUs(itemName == "BtnAboutUs"); //} public void ShowBoxUserSettings(bool show) { transform.Find("PanelContent/BoxUserSettings").gameObject.SetActive(show); } public void ShowBackStageManagement(bool show) { transform.Find("PanelContent/BoxBackStageManagement").gameObject.SetActive(show); } public void ShowBoxSound(bool show) { transform.Find("PanelContent/BoxSound").gameObject.SetActive(show); } void ShowBoxLevel(bool show) { transform.Find("PanelContent/BoxLevel").gameObject.SetActive(show); } void ShowBoxNewUser(bool show) { transform.Find("PanelContent/BoxNewUser").gameObject.SetActive(show); } void ShowBoxScreenDistance(bool show) { transform.Find("PanelContent/BoxScreenDistance").gameObject.SetActive(show); } void ShowBoxLanguage(bool show) { transform.Find("PanelContent/BoxLanguage").gameObject.SetActive(show); } void ShowBoxUserAgreement(bool show) { transform.Find("PanelContent/BoxUserAgreement").gameObject.SetActive(show); } void ShowBoxPrivacyPolicy(bool show) { transform.Find("PanelContent/BoxPrivacyPolicy").gameObject.SetActive(show); } void ShowBoxAboutUs(bool show) { transform.Find("PanelContent/BoxAboutUs").gameObject.SetActive(show); GameVersionText.text = "V" + Application.version; } public void ShowModalConfirmSignOut(bool show) { transform.Find("ModalConfirmSignOut").gameObject.SetActive(show); } public void OnClick_QuitGame() { AudioMgr.ins.PlayBtn(); Application.Quit(); } public void OnClick_SignOut() { AudioMgr.ins.PlayBtn(); ShowModalConfirmSignOut(true); } public void OnClick_Back() { AudioMgr.ins.PlayBtn(); ViewManager2.HideView(ViewManager2.Path_SettingsView); } } }