public EmuTouchControl GetSelectedTouchControl()
        {
            Vector3 mousePosition = Input.mousePosition;

            for (int i = 0; i < m_touches.Length; ++i)
            {
                EmuTouchControl touch = m_touches[i];
                if (touch != null)
                {
                    RectTransform rt = touch.GetComponent <RectTransform>();
                    if (rt != null)
                    {
                        float radius   = Mathf.Min(rt.rect.width, rt.rect.height) / 2;
                        float distance = (mousePosition - rt.position).magnitude;
                        if (distance < radius)
                        {
                            return(touch);
                        }
                    }
                }
            }
            return(null);
        }
        private void Update()
        {
            if (Editor.ActiveWindow == null)
            {
                return;
            }

            for (int i = 0; i < m_touches.Length; ++i)
            {
                if (m_touches[i] != null && m_touches[i].IsUp)
                {
                    Destroy(m_touches[i].gameObject);
                    m_touches[i] = null;
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                if (m_selectedTouch != null)
                {
                    m_selectedTouch.Released();
                }

                m_selectedTouch = null;
                return;
            }

            if (!Editor.ActiveWindow.IsPointerOver)
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                EmuTouchControl touch = GetSelectedTouchControl();
                if (touch == null)
                {
                    int touchIndex = -1;
                    for (int i = 0; i < m_touches.Length; ++i)
                    {
                        if (m_touches[i] == null)
                        {
                            touchIndex = i;
                            break;
                        }
                    }

                    if (touchIndex >= 0)
                    {
                        touch = Instantiate(m_touchPrefab, Editor.Input.GetPointerXY(0), Quaternion.identity);
                        touch.transform.SetParent(transform, true);
                        touch.Index           = touchIndex;
                        m_touches[touchIndex] = touch;
                    }

                    if (touch != null)
                    {
                        touch.IsDown    = true;
                        touch.IsPressed = true;
                    }
                }


                m_selectedTouch = touch;
                if (m_selectedTouch != null)
                {
                    ShowTooltip();
                    m_selectedTouch.Pressed();
                }
            }
            else
            {
                if (m_selectedTouch != null)
                {
                    m_selectedTouch.IsDown = false;
                }
            }

            if (m_selectedTouch != null)
            {
                m_selectedTouch.transform.position = Input.mousePosition;
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                HideTooltip();

                for (int i = 0; i < m_touches.Length; ++i)
                {
                    if (m_touches[i] != null)
                    {
                        m_touches[i].IsDown    = false;
                        m_touches[i].IsPressed = false;
                        m_touches[i].IsUp      = true;
                    }
                }
            }
        }