//--------------------------------------------------------------------------------------------------------------------------
    // Get / Set attributes for Construction

    /// <summary> Tell the SenseGlove_Touch that is is being used by the specified SenseGlove_PhysGrab. Copy its ForceFeedbackType. </summary>
    /// <param name="parentScript"></param>
    public void SetSourceScript(SenseGlove_GrabScript parentScript)
    {
        this.grabScript = parentScript;
    }
示例#2
0
 /// <summary> End an interaction between this dial and a Sense Glove. </summary>
 /// <param name="grabScript"></param>
 /// <param name="fromExternal"></param>
 protected override bool InteractionEnd(SenseGlove_GrabScript grabScript, bool fromExternal = false)
 {
     this._grabScript    = null;
     this._grabReference = null;
     return(true);
 }
 /// <summary> (Manually) End the interaction with this GrabScript </summary>
 /// <param name="fromExternal"></param>
 /// <param name="grabScript"></param>
 public abstract void EndInteraction(SenseGlove_GrabScript grabScript, bool fromExternal = false);
示例#4
0
 public SG_InteractArgs(SenseGlove_GrabScript script, bool fromExternal)
 {
     GrabScript = script;
     Forced     = fromExternal;
 }
示例#5
0
 /// <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(SenseGlove_GrabScript grabScript, bool fromExternal);
    //--------------------------------------------------------------------------------------------------------------------------
    // Class methods

    #region ClassMethods

    /// <summary> Called when a SenseGlove_Grabscript initiates an interaction with this grabable. </summary>
    /// <param name="grabScript"></param>
    /// <param name="fromExternal"></param>
    protected override bool InteractionBegin(SenseGlove_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?
                this.grabReference = grabScript.grabReference;
                this._grabScript   = grabScript;

                this.originalDist = (grabScript.grabReference.transform.position - this.pickupReference.transform.position).magnitude;

                if (this.attachMethod != AttachType.Default && this.snapReference != null)
                {
                    if (this.attachMethod != AttachType.Default && this.snapReference != null)
                    {
                        if (this.attachMethod == AttachType.SnapToAnchor)
                        {
                            this.SnapMeTo(grabScript.grabAnchor.transform);
                        }
                        //other attachmethods.
                    }
                }


                //Apply proper pickup
                if (this.pickupMethod == GrabType.Parent)
                {
                    if (this.pickupReference.parent != null)
                    {
                        if (pickupReference.transform.parent.name == "Molekül")
                        {
                            if (GameObject.Find("Molekül").GetComponent <EditMode>().editMode == true && editMarker == false)
                            {
                                pickupReference.transform.parent.GetComponent <EditMode>().regroupAtoms(pickupReference.GetComponent <Atom>());
                                this.pickupReference.parent.parent = grabScript.grabReference.transform;
                            }
                            else if (GameObject.Find("Molekül").GetComponent <EditMode>().editMode == true && editMarker == true)
                            {
                                //Do nothing
                            }
                            else
                            {
                                this.pickupReference.parent.parent = grabScript.grabReference.transform;
                            }
                        }
                        else
                        {
                            this.pickupReference.parent = grabScript.grabReference.transform;
                        }
                    }
                    else
                    {
                        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);
    }
    //--------------------------------------------------------------------------------------------------------------------------
    // Class methods

    #region ClassMethods

    /// <summary> Called when a SenseGlove_Grabscript initiates an interaction with this grabable. </summary>
    /// <param name="grabScript"></param>
    /// <param name="fromExternal"></param>
    public override void BeginInteraction(SenseGlove_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();

            // SenseGlove_Debugger.Log("alreadyHeld = " + alreadyBeingHeld);

            if (!alreadyBeingHeld)
            {
                //always record the properties of the object in case we switch pickupTypes mid-Play for some reason.
                this.originalParent = this.pickupReference.parent;
                if (this.physicsBody)
                {
                    this.wasKinematic = this.physicsBody.isKinematic;
                    this.usedGravity  = this.physicsBody.useGravity;
                }
            }

            //if the object was actually grabbed.
            if (!alreadyBeingHeld || (alreadyBeingHeld && this.canTransfer))
            {
                //todo release?

                this.grabReference = grabScript.grabReference;
                this._grabScript   = grabScript;

                if (this.attachMethod != AttachType.Default && this.snapReference != null)
                {
                    if (this.attachMethod == AttachType.SnapToAnchor)
                    {
                        //match orientation: x axis of ref is aligned with the x axis of the glove.

                        int RL = this._grabScript.senseGlove != null && !(this._grabScript.senseGlove.GloveData().gloveSide == GloveSide.RightHand) ? 1 : -1;
                        this.pickupReference.rotation = this.grabReference.transform.rotation * Quaternion.Euler(-90 * RL, 0, 0);

                        Vector3 dRS = this.pickupReference.position - this.snapReference.position;

                        this.pickupReference.transform.position = this.grabReference.transform.position + dRS;
                    }
                }


                //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;
                    }
                }
                this.OnPickedUp();
            }
        }
    }