protected void EndDrag() { selectionImage.enabled = false; RaycastHit hit = RaycastToGround(); dragEndPos = hit.point; if (dragStartPos != null && dragEndPos != null) { Vector3 midPoint = (dragStartPos + dragEndPos) / 2; Vector3 extents = new Vector3(Mathf.Abs((dragStartPos - midPoint).x), 100, Mathf.Abs((dragStartPos - midPoint).z)); Collider[] objectsHoveredOver = Physics.OverlapBox(midPoint, extents); foreach (Collider c in objectsHoveredOver) { SelectableComponent selectableComponent = c.GetComponent <SelectableComponent>(); if (selectableComponent != null) { selectedObjects.Add(selectableComponent); selectableComponent.GetComponent <MyObject>().OnGameObjectDisabled += Deselect; selectableComponent.Select(); } } } }
void Update() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { GameObject objectHit = hit.transform.gameObject; SelectableComponent selectableComponent = objectHit.GetComponent <SelectableComponent>(); if (selectableComponent == null) { return; } if (selectableComponent.Select()) { selectableComponent.gameObject.GetComponent <ColorLerpComponent>().Activate(); } } }
public void Select(SelectableComponent selectableComponent) { _selected.Add(selectableComponent); selectableComponent.Select(); }