示例#1
0
    void OnGUI()
    {
        if (Event.current.type == EventType.repaint)
        {
            // make sure we have pointerlistener to get the rect from
            if (m_pointerlistener == null)
            {
                m_pointerlistener = GetComponent <PointerListener>();
                if (m_pointerlistener == null)
                {
                    return;
                }
            }
            // choose style
            GUIStyle style = GUI.skin.button;
            if (!m_useUnityDefaultGUISkin)
            {
                style = m_GUIStyle;
            }
            // render the button
            Rect rect = m_pointerlistener.ActualScreenRect;
            style.Draw(rect, (m_currentState == State.Hover || m_currentState == State.Click), m_currentState == State.Click, false, false);

            // render the hotspot animation
            if (m_currentState == State.Hover && m_hotSpotTextures != null && m_hotSpotTextures.Length > 0)
            {
                float hotSpotTime = Time.realtimeSinceStartup - m_lastHoverTime;
                if (hotSpotTime >= 0 && hotSpotTime <= m_hotspotDelay)
                {
                    int index = (int)((hotSpotTime / m_hotspotDelay) * m_hotSpotTextures.Length);
                    GUI.DrawTexture(rect, m_hotSpotTextures[index]);
                }
            }
        }
    }
示例#2
0
    static public PointerListener Get(Component com)
    {
        PointerListener listener = com.GetComponent <PointerListener>();

        if (listener == null)
        {
            listener = com.gameObject.AddComponent <PointerListener>();
        }
        return(listener);
    }
示例#3
0
    static public PointerListener Get(Transform trans)
    {
        PointerListener listener = trans.GetComponent <PointerListener>();

        if (listener == null)
        {
            listener = trans.gameObject.AddComponent <PointerListener>();
        }
        return(listener);
    }
示例#4
0
    static public PointerListener Get(GameObject go)
    {
        PointerListener listener = go.GetComponent <PointerListener>();

        if (listener == null)
        {
            listener = go.AddComponent <PointerListener>();
        }
        return(listener);
    }
示例#5
0
    static public PointerListener Get(GameObject go, object data)
    {
        PointerListener listener = go.GetComponent <PointerListener>();

        if (listener == null)
        {
            listener = go.AddComponent <PointerListener>();
        }
        listener.data = data;
        return(listener);
    }
示例#6
0
    // render the button
    void OnGUI()
    {
        if (Event.current.type == EventType.repaint)
        {
            // make sure we have PointerListener to get the rect from
            if (m_pointerlistener == null)
            {
                m_pointerlistener = GetComponent <PointerListener>();
                if (m_pointerlistener == null)
                {
                    return;
                }
            }

            // choose style
            GUIStyle style = GUI.skin.button;
            if (!m_useUnityDefaultGUISkin)
            {
                style = m_GUIStyle;
            }
            // render the button
            style.Draw(m_pointerlistener.ActualScreenRect, m_currentState == State.Hover, m_currentState == State.Click, false, false);
        }
    }