Ejemplo n.º 1
0
 /// <summary>
 /// 由cell派发消息
 /// </summary>
 /// <param name="buttonId"></param>
 /// <param name="cell"></param>
 public void NotifyEvent(string eventName, UICell cell, bool flag = true)
 {
     if (eventName.Equals(UICell.ClickCellEvent))
     {
         _curSelectIndex = cell.index;
     }
     gameObject.BroadcastMessage("OnBroadcastSelectIndex", _curSelectIndex, SendMessageOptions.DontRequireReceiver);
     onCellEvent.Invoke(eventName, cell, flag);
 }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit))
                {
                    Selectable selectable = hit.transform.gameObject.GetComponent <Selectable>();

                    if (selectable != null)
                    {//Clicked Selectable
                        Cell selectedCell = selectable.GetComponent <Cell>();
                        if (selectedCell != null)
                        {//Clicked on a cell
                            SelectedCellEvent.Invoke(selectedCell);
                            SelectNewObject(null);
                        }
                        else
                        {
                            SelectNewObject(selectable);
                        }
                    }
                    else
                    {//Clicked on something but not a selectable... ??
                    }
                }
                else
                {//Clicked on "nothing"
                    ClickedNothingEvent.Invoke();
                    SelectNewObject(null);
                }
            }
            else
            {//Clicked a UI element
                ClickedUIEvent.Invoke();
            }
        }

        MoveSelector();
    }