private void HitTest() { if (m_rectTransform.sizeDelta.magnitude < 5f) { return; } Vector3 center = (m_startMousePosition + m_mouse.VirtualMousePosition) / 2; center.z = 0.0f; Bounds selectionBounds = new Bounds(center, m_rectTransform.sizeDelta); Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(m_viewport.Camera); HashSet <GameObject> selection = new HashSet <GameObject>(); Collider[] colliders = FindObjectsOfType <Collider>(); FilteringArgs args = new FilteringArgs(); for (int i = 0; i < colliders.Length; ++i) { Collider c = colliders[i]; Bounds bounds = c.bounds; GameObject go = c.gameObject; TrySelect(ref selectionBounds, selection, args, ref bounds, go, frustumPlanes); } if (Selected != null) { Selected(this, new BoxSelectEventArgs(selection.ToArray())); } }
private void OnBoxSelectionFiltering(object sender, FilteringArgs e) { GameObject go = e.Object; Voxel voxel = go.GetComponentInParent <Voxel>(); if (voxel == null || !VoxelData.IsControllableUnit(voxel.Type) || voxel.Owner != PlayerIndex) { e.Cancel = true; } }
private void TrySelect(ref Bounds selectionBounds, HashSet <GameObject> selection, FilteringArgs args, ref Bounds bounds, GameObject go, Plane[] frustumPlanes) { bool select; if (m_method == BoxSelectionMethod.LooseFitting) { select = LooseFitting(ref selectionBounds, ref bounds); } else if (m_method == BoxSelectionMethod.BoundsCenter) { select = BoundsCenter(ref selectionBounds, ref bounds); } else { select = TransformCenter(ref selectionBounds, go.transform); } if (!GeometryUtility.TestPlanesAABB(frustumPlanes, bounds)) { select = false; } if (select) { if (!selection.Contains(go)) { if (Filtering != null) { args.Object = go; Filtering(this, args); if (!args.Cancel) { selection.Add(go); } args.Reset(); } else { selection.Add(go); } } } }