| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /* 设备界面 */
- public class DeviceView : JCUnityLib.ViewBase, MenuBackInterface
- {
- GameObject bowOptions;
- [SerializeField] List<Button> smartArcheryButtons;
- [SerializeField] List<Sprite> smartArcheryBg;
- public static DeviceView ins;
- public Action action_OnClickGyr;
- public Action action_OnClickMag;
- void Start()
- {
- ins = this;
- PersistenHandler.ins?.menuBackCtr.views.Add(this);
- for (int i = 0; i < smartArcheryButtons.Count; i++)
- {
- int temp = i;
- smartArcheryButtons[i].onClick.AddListener(()=>{
- AudioMgr.ins.PlayBtn();
- OnChangeSmartArcheryButton(temp);
- });
- }
- bowOptions = this.transform.Find("ItemInfo/BowOptions").gameObject;
- //初始化弓的校准按钮
- Button[] bowOptionBtns = bowOptions.GetComponentsInChildren<Button>();
- for (int i = 0; i < bowOptionBtns.Length; i++)
- {
- int optionID = i;
- bowOptionBtns[i].onClick.AddListener(delegate() {
- AudioMgr.ins.PlayBtn();
- switch (optionID)
- {
- case 0:
- DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
- action_OnClickGyr?.Invoke();
- break;
- case 1:
- DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
- action_OnClickMag?.Invoke();
- break;
- }
- });
- }
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- PersistenHandler.ins?.menuBackCtr.views.Remove(this);
- }
- void Update()
- {
- }
- public bool OnMenuBack() {
- ViewMgr.Instance.DestroyView<DeviceView>();
- return true;
- }
- public void OnClick_Back() {
- AudioMgr.ins.PlayBtn();
- ViewMgr.Instance.DestroyView<DeviceView>();
- }
- void OnChangeSmartArcheryButton(int index) {
- //Debug.Log("OnChangeSmartArcheryButton按钮:" + index);
- bool _selected = false;
- for (int i = 0; i < smartArcheryButtons.Count; i++)
- {
- Button _button = smartArcheryButtons[i];
- Color32 _white;
- Color32 _buttonBg;
- if (index == i)
- {
- _white = new Color32(255, 255, 255, 255);
- //_buttonBg = new Color32(16, 194, 198, 255);
- _selected = true;
- _button.GetComponent<Image>().sprite = smartArcheryBg[1];
- }
- else {
- _white = new Color32(59, 59, 59, 255);
- //_buttonBg = new Color32(255, 255, 255, 255);
- _button.GetComponent<Image>().sprite = smartArcheryBg[0];
- }
- _button.transform.Find("icon").GetComponent<Image>().color = _white;
- _button.transform.Find("title").GetComponent<Text>().color = _white;
- _button.transform.Find("arrow").GetComponent<Image>().color = _white;
- }
- if (_selected)
- {
- //进入选中的页面
- AudioMgr.ins.PlayBtn();
- ViewMgr.Instance.ShowView<SmartArcheryView>();
- }
- }
- //暂时先更新一个
- public void RenderBattery(int deviceID, int value)
- {
- //smartArcheryButtons[0].GetComponent<DeviceView_ItemShow>().RenderBattery(deviceID,value);
- }
- }
|