Esempio n. 1
0
 /// <summary>
 /// The ResetAction method is used to reset the secondary action when the Interactable Object is no longer grabbed by a secondary Interact Grab.
 /// </summary>
 public virtual void ResetAction()
 {
     grabbedObject             = null;
     primaryGrabbingObject     = null;
     secondaryGrabbingObject   = null;
     primaryInitialGrabPoint   = null;
     secondaryInitialGrabPoint = null;
     initialised = false;
 }
Esempio n. 2
0
 /// <summary>
 /// The Initalise method is used to set up the state of the secondary action when the Interactable Object is initially grabbed by a secondary Interact Grab.
 /// </summary>
 /// <param name="currentGrabbdObject">The Interactable Object script for the object currently being grabbed by the primary grabbing object.</param>
 /// <param name="currentPrimaryGrabbingObject">The Interact Grab script for the object that is associated with the primary grabbing object.</param>
 /// <param name="currentSecondaryGrabbingObject">The Interact Grab script for the object that is associated with the secondary grabbing object.</param>
 /// <param name="primaryGrabPoint">The point on the Interactable Object where the primary Interact Grab initially grabbed the Interactable Object.</param>
 /// <param name="secondaryGrabPoint">The point on the Interactable Object where the secondary Interact Grab initially grabbed the Interactable Object.</param>
 public virtual void Initialise(InteractableObject currentGrabbdObject, Grab_Interact currentPrimaryGrabbingObject, Grab_Interact currentSecondaryGrabbingObject, Transform primaryGrabPoint, Transform secondaryGrabPoint)
 {
     grabbedObject             = currentGrabbdObject;
     primaryGrabbingObject     = currentPrimaryGrabbingObject;
     secondaryGrabbingObject   = currentSecondaryGrabbingObject;
     primaryInitialGrabPoint   = primaryGrabPoint;
     secondaryInitialGrabPoint = secondaryGrabPoint;
     initialised = true;
 }
Esempio n. 3
0
    protected virtual void AddTrackPoint(GameObject currentGrabbingObject)
    {
        Grab_Interact grabScript      = currentGrabbingObject.GetComponentInChildren <Grab_Interact>();
        Transform     controllerPoint = ((grabScript && grabScript.controllerAttachPoint) ? grabScript.controllerAttachPoint.transform : currentGrabbingObject.transform);

        //grabAttachMechanicScript是抓取的那个controller的script
        if (grabAttachMechanicScript != null)
        {
            trackPoint = grabAttachMechanicScript.CreateTrackPoint(controllerPoint, gameObject, currentGrabbingObject, ref customTrackPoint);
        }
    }
Esempio n. 4
0
    /// <summary>
    /// The StopTouching method is called automatically when the Interactable Object has stopped being touched.
    /// </summary>
    /// <param name="previousTouchingObject">The interacting object that was previously touching this Interactable Object.</param>
    public virtual void StopTouching(Grab_Interact previousTouchingObject = null)
    {
        Debug.Log("88|66");
        GameObject previousTouchingGameObject = (previousTouchingObject != null ? previousTouchingObject.gameObject : null);

        if (previousTouchingGameObject != null && touchingObjects.Remove(previousTouchingGameObject))
        {
            ResetUseState(previousTouchingGameObject);
            OnInteractableObjectUntouched(SetInteractableObjectEvent(previousTouchingGameObject));
        }
    }
Esempio n. 5
0
 /// <summary>
 /// 强制释放抓取的物体
 /// </summary>
 protected virtual void ForceReleaseGrab()
 {
     if (grabbedObjectScript)
     {
         GameObject grabbingObject = grabbedObjectScript.GetGrabbingObject();
         if (grabbingObject != null)
         {
             Grab_Interact grabbingObjectScript = grabbingObject.GetComponentInChildren <Grab_Interact>();
             if (grabbingObjectScript != null)
             {
                 grabbingObjectScript.ForceRelease();
             }
         }
     }
 }
Esempio n. 6
0
    /// <summary>
    /// The StartTouching method is called automatically when the Interactable Object is touched initially.
    /// </summary>
    /// <param name="currentTouchingObject">The interacting object that is currently touching this Interactable Object.</param>
    public virtual void StartTouching(Grab_Interact currentTouchingObject = null)
    {
        Debug.Log("Wow|Qaq");
        GameObject currentTouchingGameObject = (currentTouchingObject != null ? currentTouchingObject.gameObject : null);

        if (currentTouchingGameObject != null)
        {
            IgnoreColliders(currentTouchingGameObject);
            if (touchingObjects.Add(currentTouchingGameObject))
            {
                ToggleEnableState(true);
                OnInteractableObjectTouched(SetInteractableObjectEvent(currentTouchingGameObject));
            }
        }
    }
Esempio n. 7
0
    public virtual void Grabbed(Grab_Interact currentGrabbingObject = null)
    {
        GameObject currentGrabbingGameObject = (currentGrabbingObject != null ? currentGrabbingObject.gameObject : null);

        ToggleEnableState(true);
        if (!IsGrabbed() || IsSwappable())
        {
            PrimaryControllerGrab(currentGrabbingGameObject);
        }
        else
        {
            SecondaryControllerGrab(currentGrabbingGameObject);
        }
        OnInteractableObjectGrabbed(SetInteractableObjectEvent(currentGrabbingGameObject));
    }
Esempio n. 8
0
    /// <summary>
    /// 停止抓取物体
    /// </summary>
    protected virtual void StopGrabbingInteractions()
    {
        GameObject grabbingObject = GetGrabbingObject();

        if (grabbingObject != null && (grabbingObject.activeInHierarchy || forceDisabled))
        {
            Grab_Interact grabbingObjectScript = grabbingObject.GetComponentInChildren <Grab_Interact>();
            if (grabbingObjectScript != null && grabbingObjectScript != null)
            {
                grabbingObjectScript.ForceStopTouching();
                grabbingObjectScript.ForceRelease();
                forcedDropped = true;
            }
        }
    }
Esempio n. 9
0
    public virtual void Ungrabbed(Grab_Interact previousGrabbingObject = null)
    {
        GameObject previousGrabbingGameObject = (previousGrabbingObject != null ? previousGrabbingObject.gameObject : null);
        GameObject secondaryGrabbingObject    = GetSecondaryGrabbingObject();

        if (secondaryGrabbingObject == null || secondaryGrabbingObject != previousGrabbingGameObject)
        {
            SecondaryControllerUngrab(secondaryGrabbingObject);
            PrimaryControllerUngrab(previousGrabbingGameObject, secondaryGrabbingObject);
        }
        else
        {
            SecondaryControllerUngrab(previousGrabbingGameObject);
        }
        OnInteractableObjectUngrabbed(SetInteractableObjectEvent(previousGrabbingGameObject));
    }
Esempio n. 10
0
 protected virtual void ThrowReleasedObject(Rigidbody objectRigidbody)
 {
     if (grabbedObjectScript != null)
     {
         //Grab_Interact grabbingObjectScript = ControllerMsg.TouchingHandObject.GetComponentInChildren<Grab_Interact>();
         Grab_Interact grabbingObjectScript = ControllerMsg.GrabbingHandObject.GetComponent <Grab_Interact>();
         if (grabbingObjectScript != null)
         {
             //这里暂时用抓取后的controller
             //Transform origin = ControllerMsg.primaryGrabHandObject.transform;
             //获取其速度
             //grabbingObjectScript.transform.localScale = new Vector3(0.02f,0.02f,0.02f);
             Vector3 velocity = grabbingObjectScript.GetControllerVelocity();
             //tx.text += "速度为" + velocity.ToString();
             //Debug.Log("直接调用速度估计: " + grabbingObjectScript.GetComponent<VelocityEstimator>().GetVelocityEstimate());
             //Debug.Log("物体名称: " + grabbingObjectScript.gameObject.name);
             Vector3 angularVelocity = grabbingObjectScript.GetControllerAngularVelocity();
             float   grabbingObjectThrowMultiplier = grabbingObjectScript.throwMultiplier;
             //暴力实现速度限制
             if (velocity.x > 3)
             {
                 velocity.x = 3;
             }
             if (velocity.x < -3)
             {
                 velocity.x = 3;
             }
             if (velocity.y > 3)
             {
                 velocity.y = 3;
             }
             if (velocity.y < -3)
             {
                 velocity.y = 3;
             }
             if (velocity.z > 3)
             {
                 velocity.z = 3;
             }
             if (velocity.z < -3)
             {
                 velocity.z = 3;
             }
             //if(origin != null)
             //{
             //    objectRigidbody.velocity = origin.TransformVector(velocity) * (grabbingObjectThrowMultiplier * throwMultiplier);
             //    objectRigidbody.angularVelocity = origin.TransformDirection(angularVelocity);
             //}else
             {//直接用计算出的速度附加
                 objectRigidbody.velocity        = velocity * (grabbingObjectThrowMultiplier * throwMultiplier);
                 objectRigidbody.angularVelocity = angularVelocity;
             }
             //if (throwVelocityWithAttachDistance)
             //{
             //    Collider rigidbodyCollider = objectRigidbody.GetComponentInChildren<Collider>();
             //    if (rigidbodyCollider != null)
             //    {
             //        Vector3 collisionCenter = rigidbodyCollider.bounds.center;
             //        objectRigidbody.velocity = objectRigidbody.GetPointVelocity(collisionCenter + (collisionCenter - transform.position));
             //    }
             //    else
             //    {
             //        objectRigidbody.velocity = objectRigidbody.GetPointVelocity(objectRigidbody.position + (objectRigidbody.position - transform.position));
             //    }
             //}
         }
     }
 }