/// <summary> Remove an object from this dropzone and restore its original settings. </summary> /// <param name="objectIndex"></param> public void RemoveObject(int objectIndex) { //SenseGlove_Debugger.Log("The script wishes to remove " + objectIndex); if (objectIndex >= 0 && objectIndex < this.objectsInside.Count) { SenseGlove_Debugger.Log("removing " + this.objectsInside[objectIndex].name + " from the DropZone!"); SenseGlove_Grabable obj = this.objectsInside[objectIndex]; SenseGlove_Debugger.Log("RBProps.lengh = " + RBprops.Count); if (obj.GetComponent <Rigidbody>() != null && RBprops[objectIndex] != null) { //if it is currently picked up, we assign the previous properties to its grabscript, which will then apply them once it lets go. SenseGlove_Debugger.Log("It has a physicsBody"); if (obj.IsGrabbed()) { obj.SetOriginalParent(this.originalParent[objectIndex]); obj.SetRBProps(this.RBprops[objectIndex][0], this.RBprops[objectIndex][1]); } else { obj.transform.parent = this.originalParent[objectIndex]; obj.physicsBody.useGravity = this.RBprops[objectIndex][0]; obj.physicsBody.isKinematic = this.RBprops[objectIndex][1]; } } this.objectsInside.RemoveAt(objectIndex); SenseGlove_Debugger.Log("Removed it from ObjectsInside!"); this.RBprops.RemoveAt(objectIndex); this.originalParent.RemoveAt(objectIndex); obj.SetInteractable(true); //now the function can also be used to force removal of the object. this.OnObjectRemoved(obj); } }
/// <summary> Add an object to this DropZone, and apply the desired settings. </summary> /// <param name="obj"></param> public void AddObject(SenseGlove_Grabable obj) { SenseGlove_Debugger.Log("Adding " + obj.name + " to the DropZone!"); // remember original parent if (obj.IsGrabbed()) { this.originalParent.Add(obj.GetOriginalParent()); } else { this.originalParent.Add(obj.transform.parent); } bool[] props = null; if (this.snapToMe && (this.takeFromHand || !obj.IsGrabbed())) { obj.EndInteraction(); Transform zoneParent = this.snapTarget; if (zoneParent == null) { zoneParent = this.gameObject.transform; } obj.gameObject.transform.parent = zoneParent; obj.gameObject.transform.localPosition = Vector3.zero; obj.gameObject.transform.localRotation = Quaternion.identity; Rigidbody RB = obj.physicsBody; if (RB != null) { if (obj.IsGrabbed()) { props = obj.GetRBProps(); } else { props = new bool[2] { RB.useGravity, RB.isKinematic }; } RB.useGravity = false; RB.isKinematic = true; } } this.RBprops.Add(props); this.objectsInside.Add(obj); obj.SetInteractable(!this.disableInteration); //enable / disable interactions. this.OnObjectDetected(obj); }
/// <summary> Restore properties back to their original state(s). </summary> /// <param name="grabable"></param> public void RestoreProperties(SenseGlove_Grabable grabable) { if (!grabable.IsInteracting()) { grabable.SetInteractable(this.wasInteractable); grabable.pickupReference.transform.parent = this.oldParent; if (grabable.physicsBody != null) { grabable.physicsBody.useGravity = this.usedGravity; grabable.physicsBody.isKinematic = this.wasKinematic; } } this.BreakJoint(); }
/// <summary> Called when an Object is detected and its event is called. End interation if needed, then snap it </summary> /// <param name="detectedObject"></param> protected override void CallObjectDetect(SenseGlove_Grabable detectedObject) { if (this.disablesInteraction) { detectedObject.SetInteractable(false); } if (this.takesFromHand) { detectedObject.EndInteraction(); } if (!detectedObject.IsInteracting()) { this.AttachObject(detectedObject); } else //we still are interacting, meaning we did not disable nor take from the hand. { detectedObject.InteractionEnded += Grabable_InteractionEnded; //not subscribed to untill this object is released. } base.CallObjectDetect(detectedObject); }