public override void DoModify(List <GrabInstance> grabInstances, MoveGrabbed move) { float desiredDistance = (move.desiredPosition - snapLocation.position).magnitude; if (desiredDistance >= maxSnapDistance) { grabInstances[0].grabbable.RemoveModifier(this); objectPreview.SetActive(true); } else { objectPreview.SetActive(false); move.desiredPosition = snapLocation.position; move.desiredRotation = snapLocation.rotation; } }
/// <summary> /// Update the GrabHandler to result in the behaviour that we want. Replace singlehand with doublehand, vice versa, tool or not, snap or not, etc. /// TODO: Create a GrabParameters object to pass here that uses the Grabber, the Grabbable and the GrabZone to determine what to do. /// </summary> /// <param name="grabInstance"></param> protected virtual void CreateGrabHandler(GrabInstance grabInstance) { if (grabInstances.Count == 0) { DestroyImmediate(moveGrabbed); moveGrabbed = null; EnableSnapPreviews(false); } else if (grabInstances.Count == 1) { // Do simple grab DestroyImmediate(moveGrabbed); if (grabInstance.grabZone.isToolGrab) { moveGrabbed = gameObject.AddComponent <MoveGrabbedSingleHand_Tool>(); moveGrabbed.Init(grabInstances[0]); } else { moveGrabbed = gameObject.AddComponent <MoveGrabbedSingleHand>(); moveGrabbed.Init(grabInstances[0]); } EnableSnapPreviews(true); } else if (grabInstances.Count == 2) { if (allowMultipleGrabs) { // Do dual-hand grab DestroyImmediate(moveGrabbed); moveGrabbed = gameObject.AddComponent <MoveGrabbedDualHand>(); moveGrabbed.Init(grabInstances[0], grabInstances[1]); EnableSnapPreviews(true); } } }
public abstract void DoModify(List <GrabInstance> grabInstances, MoveGrabbed move);