6 using System.Collections.Generic;
9 namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
27 return activeGrabbers.Count > 0 ? activeGrabbers[activeGrabbers.Count - 1] : null;
35 return activeGrabbers.ToArray();
39 public Vector3 GrabPoint
43 return grabSpot != null ? grabSpot.position : transform.position;
54 if (activeGrabbers.Count > 1)
70 if (availableGrabbers.Count > 1)
72 else if (availableGrabbers.Count > 0)
83 protected HashSet<BaseGrabber> availableGrabbers =
new HashSet<BaseGrabber>();
89 protected List<BaseGrabber> activeGrabbers =
new List<BaseGrabber>();
100 private Vector3 velocity;
101 private Vector3 averageVelocity;
102 private Vector3 previousVel;
114 if (GrabberPrimary.CanTransferOwnershipTo(
this, grabber))
117 activeGrabbers.Remove(primary);
118 DetachFromGrabber(primary);
129 throw new ArgumentOutOfRangeException();
142 availableGrabbers.Add(availableObject);
150 availableGrabbers.Remove(availableObject);
169 Debug.Log(
"Start grab");
172 Debug.Log(
"State is inactive");
174 activeGrabbers.Add(grabber);
175 StartCoroutine(StayGrab());
179 Debug.Log(
"State is not inactive");
181 activeGrabbers.Add(grabber);
185 AttachToGrabber(grabber);
186 if (OnGrabbed != null)
205 for (
int i = activeGrabbers.Count - 1; i >= 0; i--)
207 if (activeGrabbers[i] == null || !activeGrabbers[i].IsGrabbing(
this))
209 Debug.Log(
"no longer being grabbed by active grabber");
210 if (activeGrabbers[i] != null)
212 DetachFromGrabber(activeGrabbers[i]);
215 activeGrabbers.RemoveAt(i);
229 if (OnReleased != null)
248 if (prevGrabState != GrabState && OnGrabStateChange != null)
250 Debug.Log(
"Calling on grab change in grabbable");
251 OnGrabStateChange(
this);
254 if (prevContactState != ContactState && OnContactStateChange != null)
256 Debug.Log(
"Calling on contact change in grabbable");
257 OnContactStateChange(
this);
260 prevGrabState = GrabState;
261 prevContactState = ContactState;