public GameObject GetClosestObjectInList(List <GameObject> targetList, GameObject target, BaseTool.ToolMode mode) { float closestDistance = -1.0f; GameObject closestObject = null; if (targetList != null && target != null) { foreach (GameObject obj in targetList) { if (obj != null) { float dist = Vector3.Distance(obj.transform.position, target.transform.position); if (dist < closestDistance || closestDistance < 0) { BaseAttachment attach = obj.GetComponent <BaseAttachment>(); if (attach != null) { if (attach.respondsToToolMode(mode)) { closestDistance = dist; closestObject = obj; } } } } } } return(closestObject); }
/* * Check if we're inside an object */ protected void CheckForObjectCollision() { m_heldObject = HydraController.Instance.HandTarget(m_hand, ProximityType.INSTRUMENT_INTERIOR, m_mode); if (m_heldObject != null) { BaseAttachment attach = m_heldObject.GetComponent <BaseAttachment>(); if (attach != null) { if (attach.respondsToToolMode(m_mode)) { //m_gestureState = GestureState.INTERIOR; m_attachment = attach; m_toolHandState = BaseTool.HandState.HOLDING; m_attachment.SetToolMode(m_mode); m_attachment.SetActiveHand(m_hand); if (mode == ToolMode.IDLE) { m_attachment.StartHover(); } } } } }