void acceptAction(VRSimPickupObject pickupObj) { strobeColour(AcceptColor, NormalColor, 0.5f); if (AcceptSound) { AudioSource.PlayClipAtPoint(AcceptSound, transform.position); } }
/// <summary> /// Attempts to pickup an object of type VRSimPickupObject /// </summary> /// <returns>The object.</returns> public VRSimPickupObject pickupObject(VRSimHandInteraction hand) { VRSimPickupObject nearestObject = NearestObjectToHand(hand); if (nearestObject) { nearestObject.Hilight = false; } return(nearestObject); }
// Clear all the colour, state, and receivedObjects. void resetReceived() { for (int i = 0; i < m_receivedObjects.Count; i++) { VRSimPickupObject o = m_receivedObjects[i]; if (o != null) { o.returnHome(); m_receivedObjects[i] = null; } } }
protected void pickupObject() { if (m_pickupArea == null) { return; } VRSimPickupObject obj = m_pickupArea.pickupObject(this); if (obj != null) { PickupObject = obj; m_pickupObject.ParentHand = this; } else { // Nothing to pickup, so attempt picking up from the other hand. } }
public bool receiveObject(VRSimPickupObject pickupObj) { for (int i = 0; i < AcceptList.Count; i++) { if (m_receivedObjects[i] == null && AcceptList[i].Equals(pickupObj.gameObject.name)) { m_receivedObjects[i] = pickupObj; pickupObj.transform.parent = transform; acceptAction(pickupObj); return(true); } } pickupObj.returnHome(); rejectAction(); return(false); }
protected VRSimPickupObject NearestObjectToHand(VRSimHandInteraction hand) { Component[] pickupObjects = gameObject.GetComponentsInChildren <VRSimPickupObject>(); VRSimPickupObject nearest = null; float nearestMagnitude = float.MaxValue; float pickDistSquared = PickDistance * PickDistance; foreach (VRSimPickupObject obj in pickupObjects) { float magnitude = (hand.PickupPoint - obj.transform.position).sqrMagnitude; if (magnitude < nearestMagnitude && magnitude < pickDistSquared) { nearest = obj; nearestMagnitude = magnitude; } } return(nearest); }
// Check through all pickupObjects that we are the parent of, // hilight the nearest if a Hand Interaction is in the volume. void Update() { Component[] pickupObjects = gameObject.GetComponentsInChildren <VRSimPickupObject>(); if (pickupObjects == null) { return; } List <VRSimPickupObject> nearestPickupObjects = new List <VRSimPickupObject>(m_hands.Count); foreach (VRSimHandInteraction hand in m_hands) { // Skip hands with something in them. if (hand.PickupObject != null) { continue; } VRSimPickupObject nearest = NearestObjectToHand(hand); if (nearest) { nearestPickupObjects.Add(nearest); } } foreach (VRSimPickupObject obj in pickupObjects) { if (obj.Hilight == true && nearestPickupObjects.Contains(obj) == false) { obj.Hilight = false; } else if (obj.Hilight == false && nearestPickupObjects.Contains(obj)) { obj.Hilight = true; } } }