Exemplo n.º 1
0
 void OnEvent(MouseRaycasterEventParams i_Params)
 {
     if (i_Params.eventType == MouseRaycasterEventType.OnEnterEvent)
     {
         Debug.Log("ON ENTER : " + i_Params.position + " " + i_Params.gameObject.name);
     }
     else // OnExit
     {
         Debug.Log("ON EXIT : " + i_Params.position + " " + i_Params.gameObject.name);
     }
 }
        // BUSINESS LOGIC

        public void Update(Vector2 i_MousePosition, bool i_Valid)
        {
            if (onEvent == null)
            {
                return; // Empty listener list, we can skip this raycaster.
            }
            GameObject selectedGo = null;

            if (i_Valid)
            {
                Collider2D selectedCollider = Physics2D.OverlapCircle(i_MousePosition, 0.05f, m_LayerMask);
                if (selectedCollider != null)
                {
                    selectedGo = selectedCollider.gameObject;
                }
            }

            if (selectedGo != m_PrevSelectedGO)
            {
                if (m_PrevSelectedGO != null)
                {
                    if (onEvent != null)
                    {
                        MouseRaycasterEventParams eventParams = new MouseRaycasterEventParams(MouseRaycasterEventType.OnExitEvent, i_MousePosition, m_PrevSelectedGO);
                        onEvent(eventParams);
                    }
                }

                if (selectedGo != null)
                {
                    if (onEvent != null)
                    {
                        MouseRaycasterEventParams eventParams = new MouseRaycasterEventParams(MouseRaycasterEventType.OnEnterEvent, i_MousePosition, selectedGo);
                        onEvent(eventParams);
                    }
                }
            }

            m_PrevSelectedGO = selectedGo;
        }