Exemple #1
0
        public void ProcessUnityInput(double time)
        {
            int        touchCount = UnityInput.touchCount;
            TouchState ts;

            lock (eventListMutex) {
                for (int i = 0; i < touchCount; i++)
                {
                    var touch = UnityInput.GetTouch(i);
                    int id    = touch.fingerId;
                    var pos   = new Vec2(touch.position.x, touch.position.y);

                    switch (touch.phase)
                    {
                    case UnityEngine.TouchPhase.Began:                      // new touch
                        if (touchStateDict.TryGetValue(id, out ts))
                        {
                            FinishTouch(ts, pos, time);
                        }
                        StartTouch(id, pos, time);
                        break;

                    case UnityEngine.TouchPhase.Moved:
                    case UnityEngine.TouchPhase.Stationary:
                        if (touchStateDict.TryGetValue(id, out ts))
                        {
                            UpdateTouch(ts, pos, time);
                        }
                        else
                        {
                            StartTouch(id, pos, time);
                        }
                        break;

                    case UnityEngine.TouchPhase.Ended:
                    case UnityEngine.TouchPhase.Canceled:                      // touch ended
                        if (touchStateDict.TryGetValue(id, out ts))
                        {
                            FinishTouch(ts, pos, time);
                        }
                        break;
                    }
                }

                for (int i = 0, end = keys.Length; i < end; i++)
                {
                    int key = keys[i];
                    if (UnityInput.GetKey((UnityEngine.KeyCode)key))
                    {
                        if (!keyStates[i])
                        {
                            keyStates[i] = true;
                            eventList.Add(new KeyDownEvent {
                                key = key
                            });
                        }
                    }
                    else
                    {
                        if (keyStates[i])
                        {
                            keyStates[i] = false;
                            eventList.Add(new KeyUpEvent {
                                key = key
                            });
                        }
                    }
                }

                string text = UnityInput.inputString;
                if (!string.IsNullOrEmpty(text))
                {
                    eventList.Add(new TextInputEvent {
                        text = text
                    });
                }
            }

                        #if UNITY_EDITOR
            lock (eventListMutex) {
                var pos = new Vec2(UnityInput.mousePosition.x, UnityInput.mousePosition.y);

                if (UnityInput.GetMouseButton(0))
                {
                    if (touchStateDict.TryGetValue(MouseId, out ts))
                    {
                        UpdateTouch(ts, pos, time);
                    }
                    else
                    {
                        StartTouch(MouseId, pos, time);
                    }
                }
                else
                {
                    if (touchStateDict.TryGetValue(MouseId, out ts))
                    {
                        FinishTouch(ts, pos, time);
                    }
                }
            }
                        #endif
        }