// ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUILayout.Space();
        if (Event.current.type == EventType.Repaint)
        {
            Rect lastRect = GUILayoutUtility.GetLastRect();
            areaY = lastRect.yMax;
        }

        exUIMng mng = target as exUIMng;

        if (mng.showDebugInfo && EditorApplication.isPlaying)
        {
            int areaWidth  = Screen.width - 40;
            int areaHeight = 300;

            mng.ShowDebugInfo(new Rect(10, areaY, areaWidth, areaHeight));
            GUILayoutUtility.GetRect(areaWidth, areaHeight);
            EditorGUILayout.Space();

            // NOTE: without this, we can not catch state each frame.
            Repaint();
        }
    }
Exemple #2
0
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////

    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public override bool OnEvent(exUIEvent _e)
    {
        exUIMng uimng = exUIMng.instance;

        if (_e.category == exUIEvent.Category.Mouse)
        {
            if (_e.type == exUIEvent.Type.MouseEnter)
            {
                if (hoverInSlots.Count > 0)
                {
                    OnHoverIn(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.MouseExit)
            {
                if (uimng.GetMouseFocus() == this)
                {
                    uimng.SetMouseFocus(null);
                }

                if (hoverOutSlots.Count > 0)
                {
                    OnHoverOut(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.MouseDown)
            {
                if (uimng.GetMouseFocus() == null)
                {
                    uimng.SetMouseFocus(this);
                }

                if (pressSlots.Count > 0)
                {
                    OnPress(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.MouseUp)
            {
                if (uimng.GetMouseFocus() == this)
                {
                    uimng.SetMouseFocus(null);
                }

                if (releaseSlots.Count > 0)
                {
                    OnRelease(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.MouseMove)
            {
                if (moveSlots.Count > 0)
                {
                    OnPointerMove(_e);
                    return(true);
                }
                return(false);
            }
        }
        else if (_e.category == exUIEvent.Category.Touch)
        {
            if (_e.type == exUIEvent.Type.TouchEnter)
            {
                if (hoverInSlots.Count > 0)
                {
                    OnHoverIn(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.TouchExit)
            {
                if (uimng.GetTouchFocus(_e.touchID) == this)
                {
                    uimng.SetTouchFocus(_e.touchID, null);
                }

                if (hoverOutSlots.Count > 0)
                {
                    OnHoverOut(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.TouchDown)
            {
                if (uimng.GetTouchFocus(_e.touchID) == null)
                {
                    uimng.SetTouchFocus(_e.touchID, this);
                }

                if (pressSlots.Count > 0)
                {
                    OnPress(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.TouchUp)
            {
                if (uimng.GetTouchFocus(_e.touchID) == this)
                {
                    uimng.SetTouchFocus(_e.touchID, null);
                }

                bool used = false;
                if (releaseSlots.Count > 0)
                {
                    OnRelease(_e);
                    used = true;
                }
                if (hoverOutSlots.Count > 0)
                {
                    OnHoverOut(_e);
                    used = true;
                }
                return(used);
            }
            else if (_e.type == exUIEvent.Type.TouchMove)
            {
                if (moveSlots.Count > 0)
                {
                    OnPointerMove(_e);
                    return(true);
                }
                return(false);
            }
        }

        //
        return(false);
    }
Exemple #3
0
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////

    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public override bool OnEvent(exUIEvent _e)
    {
        exUIMng uimng = exUIMng.instance;

        // ========================================================
        if (_e.category == exUIEvent.Category.Mouse)
        {
            // ========================================================

            if (_e.type == exUIEvent.Type.MouseEnter)
            {
                if (hoverInSlots.Count > 0)
                {
                    OnHoverIn(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.MouseExit)
            {
                if (uimng.GetMouseFocus() == this)
                {
                    isPressing = false;
                    uimng.SetMouseFocus(null);
                }

                if (hoverOutSlots.Count > 0)
                {
                    OnHoverOut(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.MouseDown &&
                     _e.buttons == exUIEvent.MouseButtonFlags.Left)
            {
                if (uimng.GetMouseFocus() == null)
                {
                    uimng.SetMouseFocus(this);
                    isPressing = true;

                    if (pressSlots.Count > 0)
                    {
                        OnPress(_e);
                        return(true);
                    }
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.MouseUp &&
                     _e.buttons == exUIEvent.MouseButtonFlags.Left)
            {
                bool used = false;
                if (isPressing)
                {
                    if (uimng.GetMouseFocus() == this)
                    {
                        uimng.SetMouseFocus(null);

                        if (clickSlots.Count > 0)
                        {
                            OnClick(_e);
                            used = true;
                        }
                    }
                    isPressing = false;
                }

                if (releaseSlots.Count > 0)
                {
                    OnRelease(_e);
                    used = true;
                }
                return(used);
            }
        }

        // ========================================================
        else if (_e.category == exUIEvent.Category.Touch)
        {
            // ========================================================

            if (_e.type == exUIEvent.Type.TouchEnter)
            {
                if (hoverInSlots.Count > 0)
                {
                    OnHoverIn(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.TouchExit)
            {
                if (uimng.GetTouchFocus(_e.touchID) == this)
                {
                    isPressing = false;
                    uimng.SetTouchFocus(_e.touchID, null);
                }

                if (hoverOutSlots.Count > 0)
                {
                    OnHoverOut(_e);
                    return(true);
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.TouchDown)
            {
                if (uimng.GetTouchFocus(_e.touchID) == null)
                {
                    uimng.SetTouchFocus(_e.touchID, this);
                    isPressing = true;

                    if (pressSlots.Count > 0)
                    {
                        OnPress(_e);
                        return(true);
                    }
                }
                return(false);
            }
            else if (_e.type == exUIEvent.Type.TouchUp)
            {
                bool used = false;
                if (isPressing)
                {
                    if (uimng.GetTouchFocus(_e.touchID) == this)
                    {
                        uimng.SetTouchFocus(_e.touchID, null);

                        if (clickSlots.Count > 0)
                        {
                            OnClick(_e);
                            used = true;
                        }
                    }
                    isPressing = false;
                }

                if (releaseSlots.Count > 0)
                {
                    OnRelease(_e);
                    used = true;
                }

                if (hoverOutSlots.Count > 0)
                {
                    OnHoverOut(_e);
                    used = true;
                }

                return(used);
            }
        }

        //
        return(false);
    }
Exemple #4
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public override bool OnEvent(exUIEvent _e)
    {
        exUIMng uimng = exUIMng.instance;

        // ========================================================
        if (_e.category == exUIEvent.Category.Mouse)
        {
            // ========================================================

            if (_e.type == exUIEvent.Type.MouseUp)
            {
                if (isPressing)
                {
                    if (uimng.GetMouseFocus() == this)
                    {
                        uimng.SetMouseFocus(null);
                    }
                    if (isDragging)
                    {
                        isDragging = false;

                        if (Time.time - pressTime < 0.01f)
                        {
                            velocity = Vector2.zero;
                        }
                        else
                        {
                            velocity = (pressPoint - _e.position) / (Time.time - pressTime);
                        }

                        if (scrollDirection == ScrollDirection.Vertical || contentOffset.x < minX || contentOffset.x > maxX)
                        {
                            velocity.x = 0.0f;
                        }
                        if (scrollDirection == ScrollDirection.Horizontal || contentOffset.y < minY || contentOffset.y > maxY)
                        {
                            velocity.y = 0.0f;
                        }

                        flickingX = true;
                        flickingY = true;
                    }
                    isPressing = false;
                }
                return(true);
            }
            else if (_e.type == exUIEvent.Type.MouseDown &&
                     _e.buttons == exUIEvent.MouseButtonFlags.Left)
            {
                isPressing   = true;
                scrollingToX = false;
                scrollingToY = false;
                velocity     = Vector2.zero;
                pressPoint   = _e.position;
                pressTime    = Time.time;
                return(true);
            }
            else if (_e.type == exUIEvent.Type.MouseMove &&
                     _e.buttons == exUIEvent.MouseButtonFlags.Left)
            {
                if (isDragging == false)
                {
                    if ((pressPoint - _e.position).sqrMagnitude > 1.0f)
                    {
                        pressPoint = _e.position;
                        pressTime  = Time.time;
                        isDragging = true;
                        uimng.SetMouseFocus(this);

                        if (showSliderOnDragging)
                        {
                            if (scrollDirection != ScrollDirection.Vertical)
                            {
                                StopCoroutine("FadeToHorizontal");
                                StartCoroutine("FadeToHorizontal", new FadeToParams(horizontalSlider, 1.0f, 0.3f));
                            }

                            if (scrollDirection != ScrollDirection.Horizontal)
                            {
                                StopCoroutine("FadeToVertical");
                                StartCoroutine("FadeToVertical", new FadeToParams(verticalSlider, 1.0f, 0.3f));
                            }
                        }
                    }
                }

                if (isDragging)
                {
                    float dragCoefX = 1.0f;
                    float dragCoefY = 1.0f;

                    if (contentOffset.x < minX || contentOffset.x > maxX)
                    {
                        dragCoefX = 0.4f;
                    }
                    if (contentOffset.y < minY || contentOffset.y > maxY)
                    {
                        dragCoefY = 0.4f;
                    }

                    float   newX           = -_e.delta.x * dragCoefX;
                    float   newY           = -_e.delta.y * dragCoefY;
                    Vector2 scrollDistance = Vector2.zero;

                    //
                    if (scrollDirection == ScrollDirection.Vertical)
                    {
                        newX = 0.0f;
                    }
                    else if (scrollDirection == ScrollDirection.Horizontal)
                    {
                        newY = 0.0f;
                    }

                    scrollDistance = new Vector2(newX, newY);
                    contentOffset += scrollDistance;
                    SetOffset(contentOffset);
                }

                return(true);
            }
        }

        // ========================================================
        else if (_e.category == exUIEvent.Category.Touch)
        {
            // ========================================================

            if (_e.type == exUIEvent.Type.TouchUp)
            {
                if (isPressing)
                {
                    if (uimng.GetTouchFocus(_e.touchID) == this)
                    {
                        uimng.SetTouchFocus(_e.touchID, null);
                    }
                    if (isDragging)
                    {
                        isDragging = false;

                        if (Time.time - pressTime < 0.01f)
                        {
                            velocity = Vector2.zero;
                        }
                        else
                        {
                            velocity = (pressPoint - _e.position) / (Time.time - pressTime);
                        }

                        if (scrollDirection == ScrollDirection.Vertical || contentOffset.x < minX || contentOffset.x > maxX)
                        {
                            velocity.x = 0.0f;
                        }
                        if (scrollDirection == ScrollDirection.Horizontal || contentOffset.y < minY || contentOffset.y > maxY)
                        {
                            velocity.y = 0.0f;
                        }

                        flickingX = true;
                        flickingY = true;
                    }
                    isPressing = false;
                }
                return(true);
            }
            else if (_e.type == exUIEvent.Type.TouchDown)
            {
                isPressing   = true;
                scrollingToX = false;
                scrollingToY = false;
                velocity     = Vector2.zero;
                pressPoint   = _e.position;
                pressTime    = Time.time;
                return(true);
            }
            else if (_e.type == exUIEvent.Type.TouchMove)
            {
                if (isDragging == false)
                {
                    if ((pressPoint - _e.position).sqrMagnitude > 1.0f)
                    {
                        pressPoint = _e.position;
                        pressTime  = Time.time;
                        isDragging = true;
                        uimng.SetTouchFocus(_e.touchID, this);

                        if (showSliderOnDragging)
                        {
                            if (scrollDirection != ScrollDirection.Vertical)
                            {
                                StopCoroutine("FadeToHorizontal");
                                StartCoroutine("FadeToHorizontal", new FadeToParams(horizontalSlider, 1.0f, 0.3f));
                            }

                            if (scrollDirection != ScrollDirection.Horizontal)
                            {
                                StopCoroutine("FadeToVertical");
                                StartCoroutine("FadeToVertical", new FadeToParams(verticalSlider, 1.0f, 0.3f));
                            }
                        }
                    }
                }

                if (isDragging)
                {
                    float dragCoefX = 1.0f;
                    float dragCoefY = 1.0f;

                    if (contentOffset.x < minX || contentOffset.x > maxX)
                    {
                        dragCoefX = 0.4f;
                    }
                    if (contentOffset.y < minY || contentOffset.y > maxY)
                    {
                        dragCoefY = 0.4f;
                    }

                    float   newX           = -_e.delta.x * dragCoefX;
                    float   newY           = -_e.delta.y * dragCoefY;
                    Vector2 scrollDistance = Vector2.zero;

                    //
                    if (scrollDirection == ScrollDirection.Vertical)
                    {
                        newX = 0.0f;
                    }
                    else if (scrollDirection == ScrollDirection.Horizontal)
                    {
                        newY = 0.0f;
                    }

                    scrollDistance = new Vector2(newX, newY);
                    contentOffset += scrollDistance;
                    SetOffset(contentOffset);
                }

                return(true);
            }
        }

        return(false);
    }