|
|
@@ -12,6 +12,7 @@ public class KeyBoardSelector : MonoBehaviour
|
|
|
EventSystem _eventSystem;
|
|
|
PointerEventData _pointerEventData;
|
|
|
public bool doing = false;
|
|
|
+ private float _lastAutoSetFirstBtnTime;
|
|
|
public static KeyBoardSelector ins;
|
|
|
|
|
|
void Start()
|
|
|
@@ -21,13 +22,36 @@ public class KeyBoardSelector : MonoBehaviour
|
|
|
_pointerEventData = new PointerEventData(_eventSystem);
|
|
|
gameObject.AddComponent<KeyBoardInterface>();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
void Update()
|
|
|
{
|
|
|
if (doing)
|
|
|
{
|
|
|
RefreshLastSelectBtn();
|
|
|
- if (!IsLastBtnValid()) Quit();
|
|
|
+ if (SB_EventSystem.ins.simulateMouseIsAwaked)
|
|
|
+ {
|
|
|
+ if (!IsBtnCanReach(_lastSelectBtn)) Quit();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!IsLastBtnValid()) Quit();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (Time.realtimeSinceStartup - _lastAutoSetFirstBtnTime > 0.2)
|
|
|
+ {
|
|
|
+ _lastAutoSetFirstBtnTime = Time.realtimeSinceStartup;
|
|
|
+ RefreshLastSelectBtn();
|
|
|
+ if (SB_EventSystem.ins.simulateMouseIsAwaked)
|
|
|
+ {
|
|
|
+ if (!IsBtnCanReach(_lastSelectBtn)) SetFirstSelectBtn();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!IsLastBtnValid()) SetFirstSelectBtn();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -67,6 +91,20 @@ public class KeyBoardSelector : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void SetFirstSelectBtn()
|
|
|
+ {
|
|
|
+ doing = true;
|
|
|
+ RefreshLastSelectBtn();
|
|
|
+ UpdateSelectables();
|
|
|
+ if (_selectables.Count > 0)
|
|
|
+ {
|
|
|
+ Button nextOne = KeyBoardNavigation.Next(_selectables[0], 1, true);
|
|
|
+ if (nextOne == null) return;
|
|
|
+ _lastSelectBtn = nextOne;
|
|
|
+ SB_EventSystem.ins.mouseConfirm.SetSelectable(_lastSelectBtn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
void UpdateSelectables()
|
|
|
{
|
|
|
_selectables.Clear();
|
|
|
@@ -100,6 +138,19 @@ public class KeyBoardSelector : MonoBehaviour
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ bool IsBtnCanReach(Button btn)
|
|
|
+ {
|
|
|
+ if (!btn || !btn.interactable || !btn.gameObject || !btn.gameObject.activeInHierarchy) return false;
|
|
|
+ List<RaycastResult> raycastResults = new List<RaycastResult>();
|
|
|
+ _pointerEventData.position = JCUnityLib.RectTransformUtils.GetPositionByPivot(btn.transform as RectTransform, Vector2.one * 0.5f);
|
|
|
+ _eventSystem.RaycastAll(_pointerEventData, raycastResults);
|
|
|
+ if (raycastResults.Count == 0) return false;
|
|
|
+ RaycastResult rs = raycastResults[0];
|
|
|
+ if (!rs.gameObject) return false;
|
|
|
+ Button rayHitBtn = rs.gameObject.GetComponentInParent<Button>();
|
|
|
+ return btn == rayHitBtn;
|
|
|
+ }
|
|
|
+
|
|
|
void RefreshLastSelectBtn()
|
|
|
{
|
|
|
if (SB_EventSystem.ins.mouseConfirm._targetSelectable) _lastSelectBtn = SB_EventSystem.ins.mouseConfirm._targetSelectable.GetComponent<Button>();
|