| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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<TopBarButtonInfo> topBarButtonInfos;
- public UnityEngine.Events.UnityEvent<DeviceMode> 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();
- }
- }
|