public void UpdateBoxSelection(Vector3 s1, Vector3 s2, SelectionCriteria selectionCriteria = null) { for (int i = 0; i < selectionListeners.Count; i++) { var selectionListener = selectionListeners[i]; var selectable = selectionListener.selectable; if (selectionCriteria != null && SelectionCriteria.isValidSelection(selectionCriteria, selectable)) { Vector3 p = Camera.main.WorldToScreenPoint(selectable.transform.position); Vector2 s1p = Vector2.Min(s1, s2); Vector2 s2p = Vector2.Max(s1, s2); bool selected = s1p.x <= p.x && p.x <= s2p.x && s1p.y <= p.y && p.y <= s2p.y; // update and notify only selection changes if (selected) { Select(selectable); // no need to check selectable again } else { Deselect(selectable); } } else { // not valid selection } } }
public void Select(Selectable selectable, SelectionCriteria selectionCriteria = null) { if (!selectable.isSelected && SelectionCriteria.isValidSelection(selectionCriteria, selectable)) { selectable.Select(); } }