public bool IsWithinSelectionBounds(GameObject gameObject) { Camera camera = Camera.main; Bounds viewportBounds = MouseUtils.GetViewportBounds(camera, firstPosition, Input.mousePosition); return(viewportBounds.Contains( camera.WorldToViewportPoint(gameObject.transform.position))); }
void OnDrawGizmos() { if (drawRect) { Gizmos.color = Color.white; Camera camera = Camera.main; Bounds viewportBounds = MouseUtils.GetViewportBounds(camera, firstPosition, Input.mousePosition); Debug.Log(viewportBounds.ToString() + " Gizmo"); Gizmos.DrawWireCube(viewportBounds.center, viewportBounds.size); for (int i = 0; i < BuildingCountainer.childCount; i++) { GameObject _go = BuildingCountainer.transform.GetChild(i).gameObject; if (IsWithinSelectionBounds(_go)) { Gizmos.color = Color.blue; } else { Gizmos.color = Color.white; } Gizmos.DrawSphere(camera.WorldToViewportPoint(_go.transform.position), 0.01f); } } }