|
@@ -6,146 +6,95 @@ using UnityEngine.EventSystems;
|
|
|
|
|
|
|
|
public class GameMenuView : MonoBehaviour
|
|
public class GameMenuView : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
- [SerializeField] GameObject funcView;
|
|
|
|
|
- Button[] funcItemButtons;
|
|
|
|
|
- [SerializeField] Text keyCodeText;
|
|
|
|
|
-
|
|
|
|
|
- void Awake()
|
|
|
|
|
- {
|
|
|
|
|
- funcItemButtons = funcView.transform.Find("Items").GetComponentsInChildren<Button>();
|
|
|
|
|
- for (int i = 0; i < funcItemButtons.Length; i++)
|
|
|
|
|
- {
|
|
|
|
|
- int id = i;
|
|
|
|
|
- funcItemButtons[i].onClick.AddListener(delegate() {
|
|
|
|
|
- SelectItem(id, true);
|
|
|
|
|
- ConfirmItem(id);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ public Button[] funcItemButtons;
|
|
|
|
|
+ private int funcItemButtonIndex = -1;
|
|
|
|
|
+ void UpdateFuncItemButtonIndex(int deltaValue) {
|
|
|
|
|
+ if (funcItemButtonIndex == -1) funcItemButtonIndex = 0;
|
|
|
|
|
+ funcItemButtonIndex += deltaValue;
|
|
|
|
|
+ while (funcItemButtonIndex < 0) {
|
|
|
|
|
+ funcItemButtonIndex += funcItemButtons.Length;
|
|
|
}
|
|
}
|
|
|
- SelectItem(0, true);
|
|
|
|
|
|
|
+ funcItemButtonIndex %= funcItemButtons.Length;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
void Update()
|
|
|
{
|
|
{
|
|
|
if (Input.GetKeyDown(KeyCode.UpArrow))
|
|
if (Input.GetKeyDown(KeyCode.UpArrow))
|
|
|
{
|
|
{
|
|
|
- SelectItem(-1);
|
|
|
|
|
|
|
+ UpdateFuncItemButtonIndex(-1);
|
|
|
|
|
+ SetSelectable(funcItemButtons[funcItemButtonIndex]);
|
|
|
AudioMgr.ins.PlayBtn();
|
|
AudioMgr.ins.PlayBtn();
|
|
|
}
|
|
}
|
|
|
if (Input.GetKeyDown(KeyCode.DownArrow))
|
|
if (Input.GetKeyDown(KeyCode.DownArrow))
|
|
|
{
|
|
{
|
|
|
- SelectItem(+1);
|
|
|
|
|
|
|
+ UpdateFuncItemButtonIndex(1);
|
|
|
|
|
+ SetSelectable(funcItemButtons[funcItemButtonIndex]);
|
|
|
AudioMgr.ins.PlayBtn();
|
|
AudioMgr.ins.PlayBtn();
|
|
|
}
|
|
}
|
|
|
if (Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetKeyDown(KeyCode.Return))
|
|
if (Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetKeyDown(KeyCode.Return))
|
|
|
{
|
|
{
|
|
|
- if (funcView.activeSelf) {
|
|
|
|
|
- ConfirmItem(funcItemIndex);
|
|
|
|
|
- }
|
|
|
|
|
- if (recordItemIns && recordItemOkBtn.interactable) {
|
|
|
|
|
- recordItemOkBtn.onClick.Invoke();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (funcItemButtonIndex == -1) DuckHunter.TextSmartBowTip.Show("尚未选择按钮");
|
|
|
|
|
+ else OnClikc_Confirm();
|
|
|
}
|
|
}
|
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
|
{
|
|
{
|
|
|
- if (recordItemIns && recordItemBackBtn.interactable) {
|
|
|
|
|
- recordItemBackBtn.onClick.Invoke();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ funcItemButtonIndex = -1;
|
|
|
|
|
+ ResumeTarget();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void OnGUI()
|
|
|
|
|
- {
|
|
|
|
|
- if (Input.anyKeyDown)
|
|
|
|
|
- {
|
|
|
|
|
- Event e = Event.current;
|
|
|
|
|
- if (e.isKey)
|
|
|
|
|
- {
|
|
|
|
|
- keyCodeText.text = string.Format("按下的键值:[{0}]", e.character);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ #region 选项功能
|
|
|
|
|
+ Selectable _targetSelectable;
|
|
|
|
|
+ Vector3 _targetlocalScale;
|
|
|
|
|
+ Color _targetColor;
|
|
|
|
|
+ Selectable.Transition _btnTransition;
|
|
|
|
|
|
|
|
- void ShowFuncView(bool active)
|
|
|
|
|
- {
|
|
|
|
|
- funcView.SetActive(active);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ void SetSelectable(Selectable selectable) {
|
|
|
|
|
+ if (!selectable) return;
|
|
|
|
|
+ if (selectable == _targetSelectable) return;
|
|
|
|
|
|
|
|
- int funcItemIndex = 0;
|
|
|
|
|
|
|
+ ResumeTarget();
|
|
|
|
|
|
|
|
- void SelectItem(int deltaIndex, bool isFixed = false)
|
|
|
|
|
- {
|
|
|
|
|
- if (!funcView.activeSelf) return;
|
|
|
|
|
- funcItemIndex += deltaIndex;
|
|
|
|
|
- if (funcItemIndex < 0) {
|
|
|
|
|
- funcItemIndex = funcItemButtons.Length - 1;
|
|
|
|
|
- } else if (funcItemIndex >= funcItemButtons.Length) {
|
|
|
|
|
- funcItemIndex = 0;
|
|
|
|
|
- }
|
|
|
|
|
- if (isFixed) funcItemIndex = deltaIndex;
|
|
|
|
|
- for (int i = 0; i < funcItemButtons.Length; i++) {
|
|
|
|
|
- funcItemButtons[i].GetComponentInChildren<Image>().color = i == funcItemIndex ? Color.yellow : Color.white;
|
|
|
|
|
- Text ttt = funcItemButtons[i].GetComponentInChildren<Text>();
|
|
|
|
|
- if (ttt) ttt.color = i == funcItemIndex ? Color.yellow : Color.white;
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Button btn = selectable.GetComponent<Button>();
|
|
|
|
|
+ if (!btn) return;
|
|
|
|
|
+ if (!btn.interactable) return;
|
|
|
|
|
|
|
|
|
|
+ _targetSelectable = selectable;
|
|
|
|
|
|
|
|
- void ConfirmItem(int id)
|
|
|
|
|
- {
|
|
|
|
|
- if (!funcView.activeSelf) return;
|
|
|
|
|
- AudioMgr.ins.PlayBtn();
|
|
|
|
|
- switch (id)
|
|
|
|
|
- {
|
|
|
|
|
- case 1:
|
|
|
|
|
- // ShowFuncView(false);
|
|
|
|
|
- // GameObject v1 = DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
|
|
|
|
|
- // RecordItem(v1);
|
|
|
|
|
- break;
|
|
|
|
|
- case 2:
|
|
|
|
|
- // ShowFuncView(false);
|
|
|
|
|
- // GameObject v2 = DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
|
|
|
|
|
- // RecordItem(v2);
|
|
|
|
|
- break;
|
|
|
|
|
- case 3:
|
|
|
|
|
- // AutoResetView.DoIdentity();
|
|
|
|
|
- break;
|
|
|
|
|
- case 4:
|
|
|
|
|
- // if (LoginMgr.myUserInfo.arrowAccValue == 16) {
|
|
|
|
|
- // LoginMgr.myUserInfo.arrowAccValue = 64;
|
|
|
|
|
- // } else {
|
|
|
|
|
- // LoginMgr.myUserInfo.arrowAccValue = 16;
|
|
|
|
|
- // }
|
|
|
|
|
- // LoginMgr.myUserInfo.Save();
|
|
|
|
|
- // RenderArrowAcc();
|
|
|
|
|
- break;
|
|
|
|
|
- case 0:
|
|
|
|
|
- Application.Quit();
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ RectTransform rtf = _targetSelectable.transform as RectTransform;
|
|
|
|
|
+ _btnTransition = btn.transition;
|
|
|
|
|
+ if (btn.transition == Selectable.Transition.ColorTint) { //变色和放大
|
|
|
|
|
+ _targetlocalScale = rtf.localScale;
|
|
|
|
|
+ rtf.localScale = rtf.localScale * 1.2f;
|
|
|
|
|
+ _targetColor = _targetSelectable.targetGraphic.color;
|
|
|
|
|
+ var newcolor = _targetSelectable.targetGraphic.color;
|
|
|
|
|
+ newcolor.a = 0.4f;
|
|
|
|
|
+ _targetSelectable.targetGraphic.color = newcolor;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // public void RenderArrowAcc()
|
|
|
|
|
- // {
|
|
|
|
|
- // funcItemButtons[4].GetComponentInChildren<Text>().text = LoginMgr.myUserInfo.arrowAccValue + "G使用中";
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- GameObject recordItemIns;
|
|
|
|
|
- Button recordItemOkBtn;
|
|
|
|
|
- Button recordItemBackBtn;
|
|
|
|
|
-
|
|
|
|
|
- void RecordItem(GameObject itemIns)
|
|
|
|
|
- {
|
|
|
|
|
- // ClearRecordItem();
|
|
|
|
|
- // recordItemIns = itemIns;
|
|
|
|
|
- // (recordItemOkBtn, recordItemBackBtn) = itemIns.GetComponent<DeviceCalibrateView>().GetInterfaceBtns();
|
|
|
|
|
- // recordItemBackBtn.onClick.AddListener(delegate() {
|
|
|
|
|
- // ShowFuncView(true);
|
|
|
|
|
- // });
|
|
|
|
|
|
|
+ void ResumeTarget()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_targetSelectable) {
|
|
|
|
|
+ if (_btnTransition == Selectable.Transition.ColorTint) {
|
|
|
|
|
+ _targetSelectable.transform.localScale = _targetlocalScale;
|
|
|
|
|
+ _targetSelectable.targetGraphic.color = _targetColor;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- void ClearRecordItem()
|
|
|
|
|
|
|
+ void OnClikc_Confirm()
|
|
|
{
|
|
{
|
|
|
- if (recordItemIns) Destroy(recordItemIns);
|
|
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_targetSelectable && _targetSelectable.interactable) {
|
|
|
|
|
+ Button btn = _targetSelectable.GetComponent<Button>();
|
|
|
|
|
+ btn.onClick.Invoke();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (System.Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ Debug.LogError(e.Message);
|
|
|
|
|
+ Debug.LogError(e.StackTrace);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ #endregion
|
|
|
}
|
|
}
|