コード例 #1
0
    public bool Selecte()
    {
        RaycastHit2D hit = Physics2D.Raycast(cam.GetMouseWorldPosition(), Vector2.zero, 1, selectionLayer);

        //Check if pointer is not over UI, if is return false
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return(false);
        }

        //Check if rayCast hit gameObject with Editable component
        if (hit.collider != null && hit.collider.TryGetComponent(out Selecetable output))
        {
            if (Selected == output)
            {
                return(false);
            }
            if (IsObjectSelected())
            {
                Diselecte();
            }
            Selected = output;
            selected?.Invoke();
            Selected.selected?.Invoke();
            return(true);
        }

        if ((diselectionMode == DiselectionMode.Empty || diselectionMode == DiselectionMode.Both) && IsObjectSelected())
        {
            Diselecte();
        }
        return(false);
    }
コード例 #2
0
 public void SetSelection(Selecetable objectToSelect)
 {
     if (objectToSelect != null)
     {
         Selected = objectToSelect;
         Selected.selected?.Invoke();
         selected?.Invoke();
     }
 }
コード例 #3
0
    public void Diselecte()
    {
        if (Selected == null)
        {
            return;
        }

        diselected?.Invoke();
        Selected.diselected?.Invoke();
        Selected = null;
    }