public void UpdatePotentiallyGrabbableSet() { RaycastHit[] hits; // TODO : modify this so it raycasts to all fingers Vector3 rayDir = (_fingers[0].transform.position - transform.position).normalized; hits = Physics.RaycastAll(transform.position, rayDir); HandyObjectList tempList = new HandyObjectList(); for (int i = 0; i < hits.Length; i++) { var hit = hits[i]; var hgo = hit.transform.gameObject.GetComponent <HandyGripObject>(); if (hgo) { var hi = new HandyHitInfo(hit.distance, hit.collider.contactOffset); tempList.AddRecord(hgo, hi); } } if (_objectList.IsEmpty()) { for (int i = 0; i < tempList.objectsWithinGrasp.Count; i++) { _objectList.AddRecord(tempList.GetObject(i), tempList.GetHitInfo(i)); } } else { for (int i = _objectList.objectsWithinGrasp.Count - 1; i >= 0; i--) { if (!tempList.objectsWithinGrasp.Contains(_objectList.objectsWithinGrasp[i])) { _objectList.RemoveRecord(i); } else { var tObjectRef = tempList.objectsWithinGrasp.IndexOf(_objectList.objectsWithinGrasp[i]); _objectList.hitInfos[i].UpdateHitInfo(tempList.hitInfos[tObjectRef].distanceFromFinger, tempList.hitInfos[tObjectRef].contactOffset); } } } }
public void AddRecord(HandyGripObject hgo, HandyHitInfo hhi) { objectsWithinGrasp.Add(hgo); hitInfos.Add(hhi); }