コード例 #1
0
    public void Pickup()
    {
        // Get nearest interactable
        currentInteractable = GetNearestInteractable();

        // Null check
        if (!currentInteractable)
        {
            return;
        }

        // check if kinematic or physics based
        if (currentInteractable.GetComponent <Rigidbody>().isKinematic)
        {
            currentInteractable.transform.parent = this.transform;
        }
        else
        {
            // Position
            currentInteractable.ApplyOffset(transform);

            // Attach
            Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>();
            joint.connectedBody = targetBody;
        }
        // Set active hand
        currentInteractable.activeHand = this;
        currentInteractable.OnPickup(this);
    }
コード例 #2
0
    public void Drop()
    {
        // Null check
        if (!currentInteractable)
        {
            return;
        }

        // Method called before drop
        currentInteractable.OnDrop(this);

        // check if kinematic or physics based
        if (currentInteractable.GetComponent <Rigidbody>().isKinematic)
        {
            currentInteractable.transform.parent = null;
        }
        else
        {
            // Apply velocity
            Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>();
            targetBody.velocity        = pose.GetVelocity();
            targetBody.angularVelocity = pose.GetAngularVelocity();

            // Detach
            joint.connectedBody = null;
        }

        // Clear active hand
        currentInteractable.activeHand = null;
        currentInteractable            = null;
    }
コード例 #3
0
 public void Interact()
 {
     if (MyInteractable != null)
     {
         MyInteractable.Interact();
     }
 }
コード例 #4
0
    public void Pickup()
    {
        // Get nearest interactable
        currentInteractable = GetNearestInteractable();

        // Null check
        if (!currentInteractable)
        {
            return;
        }

        // Already held, check
        if (currentInteractable.m_ActiveHand)
        {
            currentInteractable.m_ActiveHand.Drop();
        }

        // Position
        currentInteractable.ApplyOffset(transform);

        // Attach
        Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>();

        joint.connectedBody = targetBody;

        // Set active hand
        currentInteractable.m_ActiveHand = this;
        currentInteractable.OnPickup(this);
    }
 private void OnTriggerExit(Collider other)
 {
     if (other.gameObject.GetComponent <MyInteractable>() != null)
     {
         interactable = null;
     }
 }
コード例 #6
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.tag == "Enemy" || collision.tag == "Interactable")
     {
         if (MyInteractable != null)
         {
             MyInteractable.StopInteract();
             MyInteractable = null;
         }
     }
 }
コード例 #7
0
    public void Close()
    {
        pageIndex = 0;
        pages.Clear();
        canvasGroup.alpha          = 0;
        canvasGroup.blocksRaycasts = false;
        ClearButtons();

        if (MyInteractable != null)
        {
            MyInteractable.StopInteract();
        }

        MyInteractable = null;
    }
コード例 #8
0
    private MyInteractable GetNearestInteractable()
    {
        MyInteractable nearest     = null;
        float          minDistance = float.MaxValue;
        float          distance    = 0.0f;

        foreach (MyInteractable interactable in inRangeInteractables)
        {
            distance = (interactable.transform.position - transform.position).sqrMagnitude;

            if (distance < minDistance)
            {
                minDistance = distance;
                nearest     = interactable;
            }
        }
        return(nearest);
    }
コード例 #9
0
    public void Drop()
    {
        // Null check
        if (!currentInteractable)
        {
            return;
        }

        // Method called before drop
        currentInteractable.OnDrop(this);

        // Apply velocity
        Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>();

        targetBody.velocity        = pose.GetVelocity();
        targetBody.angularVelocity = pose.GetAngularVelocity();

        // Detach
        joint.connectedBody = null;

        // Clear
        currentInteractable.m_ActiveHand = null;
        currentInteractable = null;
    }