private void OnHover(GameObject gameObject) { _hoveredObject = gameObject; if (null == gameObject) { _hoverBoxGO.gameObject.SetActive(false); } else { _hoverBoxGO.SetActive(true); var boxCollider = _hoveredObject.gameObject.GetComponent<Collider>() as BoxCollider; if (null == boxCollider) { // The top-level go does not have a box collider => compute bounds recursively. var bounds = UtilUnity.CalculateBounds(_hoveredObject); if (bounds.HasValue) { _hoverBoxGO.transform.position = bounds.Value.center; _hoverBoxGO.transform.rotation = Quaternion.identity; _hoverBox.Size = bounds.Value.size; } } else { // The top-level has a box collider => use that as input for our hoverbox definition. _hoverBoxGO.transform.position = _hoveredObject.gameObject.transform.TransformPoint(boxCollider.center); _hoverBoxGO.transform.rotation = _hoveredObject.gameObject.transform.rotation; _hoverBox.Size = boxCollider.size; } } }
private void OnSelect(GameObject gameObject) { // Remove bounding boxes from current selection. foreach (var box in _selectBoxes) { UtilUnity.Destroy(box.gameObject); } _selectBoxes.Clear(); // Update selection. if (_addToSelection) { if (null != gameObject) { if (_selectedObjects.Contains(gameObject)) { _selectedObjects.Remove(gameObject); } else { _selectedObjects.Add(gameObject); } } } else { _selectedObjects.Clear(); if (null != gameObject) { _selectedObjects.Add(gameObject); } } // Add bounding boxes for current selection. foreach (var selectedObject in _selectedObjects) { var selectedObjectBoundingBoxGO = new GameObject("SelectedObjectBoundingBox"); var selectedObjectBoundingBox = selectedObjectBoundingBoxGO.AddComponent<LineRendererBox>(); selectedObjectBoundingBox.Color = m_application.SelectionColor; selectedObjectBoundingBoxGO.SetActive(true); selectedObjectBoundingBoxGO.transform.SetParent(selectedObject.transform, false); var bounds = UtilUnity.CalculateBounds(selectedObject); if (bounds.HasValue) { selectedObjectBoundingBoxGO.transform.position = bounds.Value.center; selectedObjectBoundingBox.Size = selectedObject.transform.InverseTransformVector(bounds.Value.size); } _selectBoxes.Add(selectedObjectBoundingBox); } bool autoShowPropertiesOnSingleObjectSelected = false; if (autoShowPropertiesOnSingleObjectSelected) { ShowProperties(); } }