protected virtual void OnInteractBegin(SG_GrabScript grabScript, bool fromExternal) { if (InteractionBegun != null) { InteractionBegun(this, new SG_InteractArgs(grabScript, fromExternal)); } }
protected virtual void OnInteractEnd(SG_GrabScript grabScript, bool fromExternal) { if (InteractionEnded != null) { InteractionEnded(this, new SG_InteractArgs(grabScript, fromExternal)); } }
//-------------------------------------------------------------------------------------------- // Interaction Methods #region InteractionMethods /// <summary> Begin the interaction with this Interactable </summary> /// <param name="grabScript"></param> protected override bool InteractionBegin(SG_GrabScript grabScript, bool fromExternal = false) { //SenseGlove_Debugger.Log("Grabbing Lever"); if (this.isInteractable || fromExternal) { if (!this.IsInteracting() && this.physicsBody != null) { //SenseGlove_Debugger.Log("Stored Kinematic variables"); this.usedGravity = this.physicsBody.useGravity; this.wasKinematic = this.physicsBody.isKinematic; } this._grabScript = grabScript; this.grabReference = grabScript.grabReference; this.StopPhysicsBody(); float currentHingeAngle = this.GetHingeAngle(); float refAngle = this.GetHingeAngle(this.grabReference.transform.position); this.offsetAngle = currentHingeAngle - refAngle; //SenseGlove_Debugger.Log("The hinge's angle is currently " + currentHingeAngle + ", The grabreference is @" + refAngle + ". D = " + (this.offsetAngle)); if (this.physicsBody) { this.physicsBody.useGravity = false; this.physicsBody.isKinematic = true; } return(true); } return(false); }
//--------------------------------------------------------------------------------------------------------------------------------------- // Class Methods #region ClassMethods /// <summary> Called when a new SG_GrabScript engages in an interaction with this Drawer </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> protected override bool InteractionBegin(SG_GrabScript grabScript, bool fromExternal = false) { //SenseGlove_Debugger.Log("Handle.BeginInteraction"); if (!InteractingWith(grabScript)) //never interact twice with the same grabscript before EndInteraction is called. { this.grabReference = grabScript.grabReference; this._grabScript = grabScript; //Quaternion.Inverse(QT) * (vT - vO); this.grabOffset = Quaternion.Inverse(this.grabReference.transform.rotation) * (this.grabReference.transform.position - this.transform.position); //Quaternion.Inverse(QT) * (Qo); //this.grabRotation = Quaternion.Inverse(this.grabReference.transform.rotation) * this.transform.rotation; /* * if (this.physicsBody) * { * this.wasKinematic = this.physicsBody.isKinematic; * this.usedGravity = this.physicsBody.useGravity; * * this.physicsBody.useGravity = false; * this.physicsBody.isKinematic = true; * this.physicsBody.velocity = new Vector3(0, 0, 0); * this.physicsBody.angularVelocity = new Vector3(0, 0, 0); * } */ return(true); } return(false); }
/// <summary> Called when a SG_GrabScript no longer wishes to interact with this grabable. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> protected override bool InteractionEnd(SG_GrabScript grabScript, bool fromExternal = false) { //SenseGlove_Debugger.Log("End Interaction, fromExternal = " + fromExternal); if (this.InteractingWith(grabScript) || fromExternal) { if (this.IsInteracting()) { //break every possible instance that could connect this interactable to the grabscript. if (this.pickupReference != null) { this.pickupReference.parent = this.originalParent; } this.BreakJoint(); if (this.physicsBody != null) { this.physicsBody.useGravity = this.usedGravity; this.physicsBody.isKinematic = this.wasKinematic; if (grabScript != null) { this.physicsBody.velocity = grabScript.GetVelocity(); this.physicsBody.angularVelocity = grabScript.GetAngularVelocity(); } } } this._grabScript = null; this.grabReference = null; return(true); } return(false); }
/// <summary> Called when a SG_GrabScript ends the interaction with this drawer. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> protected override bool InteractionEnd(SG_GrabScript grabScript, bool fromExternal = false) { //SenseGlove_Debugger.Log("Handle.EndInteraction"); if (InteractingWith(grabScript)) //only do the proper endInteraction if the EndInteraction comes from the script currently holding it. { if (grabScript != null) { //if we're not being held by this same grabscript a.k.a. we've been passed on to another one... /* * if (this.physicsBody != null) * { * this.physicsBody.useGravity = this.usedGravity; * this.physicsBody.isKinematic = this.wasKinematic; * this.physicsBody.velocity = grabScript.GetVelocity(); * //this.physicsBody.angularVelocity = ??? * } */ } ; this.grabReference = null; this._grabScript = null; return(true); } return(false); }
/// <summary> End the interaction of this script. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> /// <returns></returns> protected override bool InteractionEnd(SG_GrabScript grabScript, bool fromExternal) { if (this._grabScript != null && GameObject.ReferenceEquals(grabScript.gameObject, _grabScript.gameObject)) { this._grabScript = null; //grabScript reference can only be removed by the GrabScript that is currently holding it. } return(true); }
/// <summary> /// Check if this Interactable is (already) interacting with a specified grabscript. /// </summary> /// <param name="grabScript"></param> /// <returns></returns> public virtual bool InteractingWith(SG_GrabScript grabScript) { if (grabScript != null && this._grabScript != null) { return(GameObject.ReferenceEquals(grabScript, this._grabScript)); } return(false); }
/// <summary> /// Pass the EndInteraction on to all connected SenseGlove_Interactables. /// </summary> /// <param name="grabScript"></param> protected override bool InteractionEnd(SG_GrabScript grabScript, bool fromExternal = false) { if (this.isInteractable) { for (int i = 0; i < this.connectedTo.Count; i++) { this.connectedTo[i].EndInteraction(grabScript, true); } return(true); } return(false); }
/// <summary> Start an interaction between this dial and a sense glove. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> protected override bool InteractionBegin(SG_GrabScript grabScript, bool fromExternal = false) { if (!InteractingWith(grabScript)) //never interact twice with the same grabscript before EndInteraction is called. { this._grabScript = grabScript; this._grabReference = grabScript.grabReference.transform; this.rotOffset = Quaternion.Inverse(this._grabReference.transform.rotation) * this.hingePoint.rotation; this.anglOffset = this.GetAngle(); return(true); } return(false); }
/// <summary> Link relevant scripts to this trackedHand, if they have not been assinged yet. </summary> protected void CheckForScripts() { //if (this.hardware == null) { this.hardware = this.gameObject.GetComponent<SG_HapticGlove>(); } if (this.handModel == null) { this.handModel = this.GetComponentInChildren <SG_HandModelInfo>(); } if (this.grabScript == null) { this.grabScript = this.GetComponentInChildren <SG_GrabScript>(); } if (this.feedbackScript == null) { this.feedbackScript = this.GetComponentInChildren <SG_HandFeedback>(); } if (this.handAnimation == null) { this.handAnimation = this.GetComponentInChildren <SG_HandAnimator>(); } if (this.gestureLayer == null) { this.gestureLayer = this.GetComponentInChildren <SG_GestureLayer>(); } if (this.statusIndicator == null) { this.statusIndicator = this.GetComponentInChildren <SG_HandStateIndicator>(); } //Since both RB and PhysicsTrackingLayers have the same component, assing whichever one we haven't done yet. if (this.rigidBodyLayer == null || this.physicsTrackingLayer == null) { SG_HandRigidBodies[] components = this.GetComponentsInChildren <SG_HandRigidBodies>(); for (int i = 0; i < components.Length; i++) { if (this.rigidBodyLayer == null && //we don't yet have a RigidBody Layer (this.physicsTrackingLayer == null || !GameObject.ReferenceEquals(this.physicsTrackingLayer.gameObject, components[i].gameObject))) { rigidBodyLayer = components[i]; } if (this.physicsTrackingLayer == null && //we don't yet have a RigidBody Layer (this.rigidBodyLayer == null || !GameObject.ReferenceEquals(this.rigidBodyLayer.gameObject, components[i].gameObject))) { physicsTrackingLayer = components[i]; } } } }
/// <summary> (Manually) End the interaction with this GrabScript </summary> /// <param name="fromExternal"></param> /// <param name="grabScript"></param> public bool EndInteraction(SG_GrabScript grabScript, bool fromExternal = false) { if (this.IsInteracting()) { bool ended = this.InteractionEnd(grabScript, fromExternal); if (ended) { if (fromExternal && grabScript != null) { //this may not have come from the grabscript. So we need to notify it as well that the object is released. grabScript.EndInteraction(this, false); } this.OnInteractEnd(grabScript, fromExternal); this.originalDist = 0; return(true); } } return(false); }
/// <summary> Ends the interaction between the grabscript and this hinge </summary> /// <param name="grabScript"></param> protected override bool InteractionEnd(SG_GrabScript grabScript, bool fromExternal = false) { if (this.IsInteracting()) { //break every possible instance that could connect this interactable to the grabscript. if (this.physicsBody != null) { //SenseGlove_Debugger.Log("Re-Applied kinematics"); this.physicsBody.useGravity = this.usedGravity; this.physicsBody.isKinematic = this.wasKinematic; this.StopPhysicsBody(); if (grabScript != null) { this.physicsBody.velocity = grabScript.GetVelocity(); } } } this._grabScript = null; this.grabReference = null; return(true); }
/// <summary> Begin the interaction between this object and a GrabScript. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> public bool BeginInteraction(SG_GrabScript grabScript, bool fromExternal = false) { if (grabScript != null) { if (this.isInteractable || fromExternal) //interactions only possible through these parameters. { bool begun = this.InteractionBegin(grabScript, fromExternal); if (begun) { this.originalDist = (grabScript.grabReference.transform.position - this.transform.position).magnitude; this.OnInteractBegin(grabScript, fromExternal); return(true); } } } else { SG_Debugger.LogError("ERROR: You are attempting to start an interaction with " + this.name + " with grabscript set to NULL"); } return(false); }
//-------------------------------------------------------------------------------------------------------------------------- // Class methods #region ClassMethods /// <summary> Called when a SG_GrabScript initiates an interaction with this grabable. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> protected override bool InteractionBegin(SG_GrabScript grabScript, bool fromExternal = false) { if (this.isInteractable) //never interact twice with the same grabscript before EndInteraction is called. { // SenseGlove_Debugger.Log("Begin Interaction with " + grabScript.name); bool alreadyBeingHeld = this.IsInteracting(); //if the object was actually grabbed. if (!alreadyBeingHeld || (alreadyBeingHeld && this.canTransfer)) { //todo release? if (GrabScript != null) { this.GrabScript.EndInteraction(this, false); } this.grabReference = grabScript.grabReference; this._grabScript = grabScript; this.originalDist = (grabScript.grabReference.transform.position - this.pickupReference.transform.position).magnitude; if (this.attachMethod != AttachType.Default) { if (this.attachMethod != AttachType.Default) { if (this.attachMethod == AttachType.SnapToAnchor) { this.SnapMeTo(grabScript.grabAnchor.transform, grabScript.TrackedHand.TracksRightHand); } //other attachmethods. } } //Apply proper pickup if (this.pickupMethod == GrabType.Parent) { this.pickupReference.parent = grabScript.grabReference.transform; } else if (this.pickupMethod == GrabType.Follow) { //Quaternion.Inverse(QT) * (vT - vO); this.grabOffset = Quaternion.Inverse(this.grabReference.transform.rotation) * (this.grabReference.transform.position - this.pickupReference.position); //Quaternion.Inverse(QT) * (Qo); this.grabRotation = Quaternion.Inverse(this.grabReference.transform.rotation) * this.pickupReference.rotation; } else if (this.pickupMethod == GrabType.FixedJoint) { this.ConnectJoint(grabScript.grabAnchor); } //apply physicsBody settings. if (this.physicsBody) { this.physicsBody.velocity = new Vector3(0, 0, 0); this.physicsBody.angularVelocity = new Vector3(0, 0, 0); if (this.pickupMethod != GrabType.FixedJoint) { this.physicsBody.useGravity = false; this.physicsBody.isKinematic = true; } } return(true); } } return(false); }
public SG_InteractArgs(SG_GrabScript script, bool fromExternal) { GrabScript = script; Forced = fromExternal; }
/// <summary> Called when the Interaction ends on this Interactable. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> /// <returns>True if the interaction has been ended.</returns> protected abstract bool InteractionEnd(SG_GrabScript grabScript, bool fromExternal);
/// <summary> End an interaction between this dial and a Sense Glove. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> protected override bool InteractionEnd(SG_GrabScript grabScript, bool fromExternal = false) { this._grabScript = null; this._grabReference = null; return(true); }
/// <summary> Let this script known it is being interacted with. </summary> /// <param name="grabScript"></param> /// <param name="fromExternal"></param> /// <returns></returns> protected override bool InteractionBegin(SG_GrabScript grabScript, bool fromExternal) { this._grabScript = grabScript; return(true); }