Esempio n. 1
0
        private IEnumerator MouseInput(string goName, string fileName) // click on button
        {
            while (CurrentPointerData != null)
            {
                yield return(null);
            }

            //Debug.LogError(pointerDic.Count);

            var founds = FindGameObject(goName).ToArray();

            if (founds.Length > 1)
            {
                Debug.LogError(founds.Length + " gameobject found with name " + goName);
            }
            else if (founds.Length == 0)
            {
                throw new Exception("gameobject " + goName + " not found!");
            }

            var target        = founds[0];
            var rectTransform = target.transform as RectTransform;

            var pathFile = Path.Combine(PathFileTarget, fileName);
            var lines    = File.ReadAllLines(pathFile);

            CurrentPointerData = new PointerData();
            TouchDown();
            StartCoroutine(DelayRevertTouchDown());
            //yield return null;

            foreach (var line in lines)
            {
                var ar    = line.Split(new[] { '|' }, 3);
                var frame = int.Parse(ar[0]);
                var x     = float.Parse(ar[1]);
                var y     = float.Parse(ar[2]);
                for (int i = 0; i < frame; i++)
                {
                    yield return(null);
                }

                //Debug.LogError(pointerDic.Count);

                Vector3 min = rectTransform.TransformPoint(rectTransform.rect.min + new Vector2(x, y));
                //Vector3 max = rectTransform.TransformPoint(rectTransform.rect.max);

                var min2D = RectTransformUtility.WorldToScreenPoint(Camera.main, min);

                CurrentPointerData.position = min2D;
            }

            //Debug.LogError(targetGameObject);

            //Debug.LogError(pointerDic.Count);
            TouchUp();
            yield return(null);

            var clickGameObject = CurrentPointerData.SelectGameObject;

            CurrentPointerData = null;

            if (clickGameObject != target)
            {
                throw new Exception("Cannot select " + goName + " - found : " + clickGameObject);
            }
        }