using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; [Serializable] public class TopBarButtonInfo { public string Name; public Image Icon; public Text text; public bool selected; public DeviceMode deviceMode; public GameObject container; } public class HomeView_TopBarView : MonoBehaviour { public List topBarButtonInfos; public UnityEngine.Events.UnityEvent onChangeTypeEvent; string _saveKey = "DeviceModeKey"; int _value = 0; int _valueDefault = 0; // Start is called before the first frame update void Start() { int deviceValue = GetDeviceModeValue(); GlobalData.MyDeviceMode = (DeviceMode)deviceValue; Debug.Log(" GlobalData.MyDeviceMode :" + GlobalData.MyDeviceMode); onChangeTypeEvent?.Invoke(GlobalData.MyDeviceMode); for (int i = 0; i < topBarButtonInfos.Count; i++) { TopBarButtonInfo topBarButtonInfo = topBarButtonInfos[i]; if (i == deviceValue) { topBarButtonInfo.Icon.color = new Color32(0, 0, 0, 255); topBarButtonInfo.text.color = new Color32(48, 57, 57, 255); } else { topBarButtonInfo.Icon.color = new Color32(255, 255, 255, 255); topBarButtonInfo.text.color = new Color32(141, 150, 151, 255); } } } public TopBarButtonInfo GetCurrentTopBarButtonInfo() { return topBarButtonInfos[(int)GlobalData.MyDeviceMode]; } // Update is called once per frame //void Update() //{ //} public void onChangeType(int index) { if (index > 0 || index < topBarButtonInfos.Count) { for (int i = 0; i < topBarButtonInfos.Count; i++) { TopBarButtonInfo topBarButtonInfo = topBarButtonInfos[i]; if (i == index) { topBarButtonInfo.Icon.color = new Color32(0, 0, 0, 255); topBarButtonInfo.text.color = new Color32(48, 57, 57, 255); } else { topBarButtonInfo.Icon.color = new Color32(255, 255, 255, 255); topBarButtonInfo.text.color = new Color32(141, 150, 151, 255); } } SetDeviceModeValue(index); GlobalData.MyDeviceMode = (DeviceMode)index; Debug.Log("Set GlobalData.MyDeviceMode :" + GlobalData.MyDeviceMode); onChangeTypeEvent?.Invoke(GlobalData.MyDeviceMode); if(HomeView.ins != null) HomeView.ins.UpdateParent(); } } public int GetDeviceModeValue() { _value = PlayerPrefs.GetInt(_saveKey, _valueDefault); return _value; } public void SetDeviceModeValue(int value) { _value = value; PlayerPrefs.SetInt(_saveKey, _value); PlayerPrefs.Save(); } }