public bool CanClick(String buttonName) { var pointerDataBacup = CurrentPointerData; recordExecuteEvent.SkipSendTouch = true; var selectedGameObjectBacup = EventSystem.current.currentSelectedGameObject; var founds = FindGameObject(buttonName).Where(gOb => gOb.ExitHander <Selectable>()).ToArray(); if (founds.Length > 1) { Debug.LogError(founds.Length + " Button found with name " + buttonName); } else if (founds.Length == 0) { return(false); } var target = founds[0]; var rectTransform = target.transform as RectTransform; Vector3 min = rectTransform.TransformPoint((rectTransform.rect.min + rectTransform.rect.max) / 2); var min2D = RectTransformUtility.WorldToScreenPoint(Camera.main, min); var inputModule = Object.FindObjectOfType <StandaloneInputModule>(); CurrentPointerData = new PointerData() { position = min2D }; CurrentPointerData.TouchDown(); CurrentPointerData.TouchUp(); didProcessThisFrame = false; inputModule.Process(); CurrentPointerData.RevertTouchDown(); CurrentPointerData.RevertTouchUp(); var clickGameObject = CurrentPointerData.SelectGameObject; CurrentPointerData = pointerDataBacup; recordExecuteEvent.SkipSendTouch = false; EventSystem.current.SetSelectedGameObject(selectedGameObjectBacup); return(clickGameObject == target); }
private IEnumerator ClickObject(String name) { while (CurrentPointerData != null) { yield return(null); } var founds = FindGameObject(name).Where(gOb => gOb.ExitHander <Selectable>()).ToArray(); if (founds.Length > 1) { Debug.LogError(founds.Length + " Object found with name " + name); } else if (founds.Length == 0) { throw new Exception("Object " + name + " not found!"); } var target = founds[0]; var rectTransform = target.transform as RectTransform; Vector3 min = rectTransform.TransformPoint((rectTransform.rect.min + rectTransform.rect.max) / 2); var min2D = RectTransformUtility.WorldToScreenPoint(Camera.main, min); CurrentPointerData = new PointerData() { position = min2D }; TouchDown(); StartCoroutine(DelayRevertTouchDown()); yield return(null); CurrentPointerData.TouchUp(); yield return(null); var clickGameObject = CurrentPointerData.SelectGameObject; CurrentPointerData = null; if (clickGameObject != target) { throw new Exception("Cannot select " + name + " - found :" + clickGameObject); } CurrentPointerData = null; }
private void TouchUp() { CurrentPointerData.TouchUp(); }