コード例 #1
0
    public bool TrySetThrowableObject(BaseGrabbable grabbable, InteractionSourcePose poseInfo)
    {
        if (grabbable == null)
        {
            return(false);
        }

        if (!grabbable.GetComponent <BaseThrowable>())
        {
            return(false);
        }

        if (!grabbable.GetComponent <Rigidbody>())
        {
            return(false);
        }

        Rigidbody rb = grabbable.GetComponent <Rigidbody>();

        Debug.Log("name of our rb.center of mass ========= " + rb.name);
        ControllerReleaseData controlReleaseData = grabbable.GetComponent <Rigidbody>().GetThrowReleasedVelocityAndAngularVelocity(rb.centerOfMass, poseInfo);

        //grabbable.GetComponent<BaseThrowable>().LatestControllerThrowVelocity = vel;
        //grabbable.GetComponent<BaseThrowable>().LatestControllerThrowAngularVelocity = vel;

        grabbable.GetComponent <BaseThrowable>().LatestControllerThrowVelocity        = controlReleaseData.Velocity;
        grabbable.GetComponent <BaseThrowable>().LatestControllerThrowAngularVelocity = controlReleaseData.AngleVelocity;
        return(true);
    }
コード例 #2
0
 protected virtual void OffhandGrabbed(BaseGrabbable grabbable)
 {
     if (_grabbedObj == grabbable)
     {
         GrabbableRelease(Vector3.zero, Vector3.zero);
     }
 }
コード例 #3
0
    void OnTriggerExit(Collider otherCollider)
    {
        BaseGrabbable grabbable = otherCollider.GetComponent <BaseGrabbable>() ??
                                  otherCollider.GetComponentInParent <BaseGrabbable>();

        if (grabbable == null)
        {
            return;
        }

        // Remove the grabbable
        int  refCount = 0;
        bool found    = _grabCandidates.TryGetValue(grabbable, out refCount);

        if (!found)
        {
            return;
        }

        if (refCount > 1)
        {
            _grabCandidates[grabbable] = refCount - 1;
        }
        else
        {
            _grabCandidates.Remove(grabbable);
        }
    }
コード例 #4
0
 /// <summary>
 /// Adds a grabbable object to the list of available objects
 /// </summary>
 /// <param name="availableObject"></param>
 protected void AddContact(BaseGrabbable availableObject)
 {
     if (!contactObjects.Contains(availableObject))
     {
         contactObjects.Add(availableObject);
         availableObject.AddContact(this);
     }
 }
コード例 #5
0
    private void Awake()
    {
        if (grabbable == null)
        {
            grabbable = GetComponent <BaseGrabbable>();
        }

        grabbable.OnContactStateChange += InvokeTouchEvent;
        grabbable.OnGrabStateChange    += InvokeGrabEvent;
    }
コード例 #6
0
    /// <summary>
    /// Removes a grabbable object from the list of available objects
    /// </summary>
    /// <param name="availableObject"></param>

    protected void RemoveContact(BaseGrabbable availableObject)
    {
        contactObjects.Remove(availableObject);
        availableObject.RemoveContact(this);

        if (contactObjects.Contains(availableObject))
        {
            // What's supposed to happen here?
        }
    }
コード例 #7
0
    private IEnumerator ThrowDelay(Vector3 vel, Vector3 angVel, BaseGrabbable grabbable)
    {
        yield return(null);

        GetComponent <Rigidbody>().velocity        = vel * ThrowMultiplier;
        GetComponent <Rigidbody>().angularVelocity = angVel;
        if (ZeroGravityThrow)
        {
            grabbable.GetComponent <Rigidbody>().useGravity = false;
        }
    }
コード例 #8
0
 private void InvokeGrabEvent(BaseGrabbable baseGrab)
 {
     if (baseGrab.ContactState == GrabStateEnum.Inactive)
     {
         OnUnGrab.Invoke();
     }
     else
     {
         OnGrab.Invoke();
     }
 }
コード例 #9
0
 public virtual void DoGrab(BaseGrabbable obj)
 {
     if (obj.TryGrabWith(this))
     {
         this.grabbedObjects.Add(obj);
         Debug.LogWarning("[" + name + "] " + "TryGrabWith Succeeded. Grabbable: " + obj.name);
     }
     else
     {
         Debug.LogWarning("[" + name + "] " + "TryGrabWith failed! Grabbable: " + obj.name);
     }
 }
コード例 #10
0
    public void ForceRelease(BaseGrabbable grabbable)
    {
        bool canRelease = (
            (_grabbedObj != null) &&
            (_grabbedObj == grabbable)
            );

        if (canRelease)
        {
            GrabEnd();
        }
    }
コード例 #11
0
    protected override void OnEnable()
    {
        base.OnEnable();

#if UNITY_WSA && UNITY_2017_2_OR_NEWER
        InteractionManager.InteractionSourceUpdated += GetTouchPadPosition;
#endif

        if (baseGrabbable == null)
        {
            baseGrabbable = GetComponent <BaseGrabbable>();
        }
    }
コード例 #12
0
    private void Awake()
    {
        if (_grabbable == null)
        {
            _grabbable = GetComponent <BaseGrabbable>();
        }
        if (_ai == null)
        {
            _ai = GetComponent <AI>();
        }

        _grabbable.OnContactStateChange += ChangeAnimationState;
        _grabbable.OnGrabStateChange    += ChangeAnimationState;
    }
コード例 #13
0
    public override void Throw(BaseGrabbable grabbable)
    {
        base.Throw(grabbable);
        //Vector3 vel = grabbable.GetAverageVelocity();
        Vector3 vel    = LatestControllerThrowVelocity;
        Vector3 angVel = LatestControllerThrowAngularVelocity;

        GetComponent <Rigidbody>().velocity        = vel * ThrowMultiplier;
        GetComponent <Rigidbody>().angularVelocity = angVel;
        if (ZeroGravityThrow)
        {
            grabbable.GetComponent <Rigidbody>().useGravity = false;
        }
    }
コード例 #14
0
 public override bool CanTransferOwnershipTo(BaseGrabbable ownerGrab, BaseGrabber otherGrabber)
 {
     if (!Unpluggable && IsAttached)
     {
         return(false);
     }
     else
     {
         if (Attached != null)
         {
             Detach();
         }
         return(base.CanTransferOwnershipTo(ownerGrab, otherGrabber));
     }
 }
コード例 #15
0
ファイル: GrabbableColor.cs プロジェクト: firemansamm/jengavr
    private void Awake()
    {
        if (grabbable == null)
        {
            grabbable = GetComponent <BaseGrabbable>();
        }

        if (targetRenderer == null)
        {
            targetRenderer = gameObject.GetComponentInChildren <MeshRenderer>();
        }

        originalColor = targetRenderer.material.color;
        grabbable.OnContactStateChange += RefreshColor;
        grabbable.OnGrabStateChange    += RefreshColor;
    }
コード例 #16
0
    void OnTriggerEnter(Collider otherCollider)
    {
        // Get the grab trigger
        BaseGrabbable grabbable = otherCollider.GetComponent <BaseGrabbable>() ??
                                  otherCollider.GetComponentInParent <BaseGrabbable>();

        if (grabbable == null)
        {
            return;
        }

        // Add the grabbable
        int refCount = 0;

        _grabCandidates.TryGetValue(grabbable, out refCount);
        _grabCandidates[grabbable] = refCount + 1;
    }
コード例 #17
0
        protected virtual bool ExecuteGrab(ConnectableAttachment attachment)
        {
            BaseGrabbable closestAvailable = attachment;

            if (closestAvailable.TryGrabWith(this))
            {
                if (IsAttached)
                {
                    Detach();
                }
                grabbedObjects.Add(closestAvailable);
                DisableCollisions(attachment);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #18
0
ファイル: GrabbableColor.cs プロジェクト: firemansamm/jengavr
    private void RefreshColor(BaseGrabbable baseGrab)
    {
        Color finalColor = originalColor;

        switch (baseGrab.ContactState)
        {
        case GrabStateEnum.Inactive:
            break;

        case GrabStateEnum.Multi:
            finalColor = colorOnContactMulti;
            break;

        case GrabStateEnum.Single:
            finalColor = colorOnContactSingle;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        switch (baseGrab.GrabState)
        {
        case GrabStateEnum.Inactive:
            break;

        case GrabStateEnum.Multi:
            finalColor = colorOnGrabMulti;
            break;

        case GrabStateEnum.Single:
            finalColor = colorOnGrabSingle;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        targetRenderer.material.color = finalColor;
    }
コード例 #19
0
    private void ChangeAnimationState(BaseGrabbable baseGrab)
    {
        switch (baseGrab.ContactState)
        {
        case GrabStateEnum.Inactive:
            _ai.pointed = false;
            break;

        case GrabStateEnum.Multi:
            _ai.pointed = true;
            break;

        case GrabStateEnum.Single:
            _ai.pointed = true;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        switch (baseGrab.GrabState)
        {
        case GrabStateEnum.Inactive:
            _ai.grabbed = false;
            break;

        case GrabStateEnum.Multi:
            _ai.grabbed = true;
            break;

        case GrabStateEnum.Single:
            _ai.grabbed = true;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
コード例 #20
0
    /// <summary>
    /// If the correct grabbing button is pressed, we add to grabbedObjects.
    /// </summary>
    protected virtual void GrabStart()
    {
        // Clean out the list of available objects list
        for (int i = contactObjects.Count - 1; i >= 0; i--)
        {
            if ((contactObjects[i] == null || !contactObjects[i].isActiveAndEnabled) && !grabbedObjects.Contains(contactObjects[i]))
            {
                contactObjects.RemoveAt(i);
            }
        }

        // If there are any left after pruning
        if (contactObjects.Count > 0)
        {
            // Sort by distance and try to grab the closest
            SortAvailable();
            BaseGrabbable closestAvailable = contactObjects[0];
            if (closestAvailable.TryGrabWith(this))
            {
                grabbedObjects.Add(contactObjects[0]);
            }
        }
    }
コード例 #21
0
    protected virtual void OnTriggerExit(Collider other)
    {
        Debug.Log("Exited trigger with " + other.name);
        if (((1 << other.gameObject.layer) & grabbableLayers.value) == 0)
        {
            return;
        }

        BaseGrabbable bg = other.GetComponent <BaseGrabbable>();

        if (bg == null && other.attachedRigidbody != null)
        {
            bg = other.attachedRigidbody.GetComponent <BaseGrabbable>();
        }

        if (bg == null)
        {
            return;
        }

        Debug.Log("Removing contact");

        RemoveContact(bg);
    }
コード例 #22
0
    protected virtual void GrabBegin()
    {
        float         closestMagSq             = float.MaxValue;
        BaseGrabbable closestGrabbable         = null;
        Collider      closestGrabbableCollider = null;

        // Iterate grab candidates and find the closest grabbable candidate
        foreach (BaseGrabbable grabbable in _grabCandidates.Keys)
        {
            bool canGrab = !(grabbable.isGrabbed && !grabbable.allowOffhandGrab);
            if (!canGrab)
            {
                continue;
            }

            for (int j = 0; j < grabbable.grabPoints.Length; ++j)
            {
                Collider grabbableCollider = grabbable.grabPoints[j];
                // Store the closest grabbable
                Vector3 closestPointOnBounds = grabbableCollider.ClosestPointOnBounds(gripTransform.position);
                float   grabbableMagSq       = (gripTransform.position - closestPointOnBounds).sqrMagnitude;
                if (grabbableMagSq < closestMagSq)
                {
                    closestMagSq             = grabbableMagSq;
                    closestGrabbable         = grabbable;
                    closestGrabbableCollider = grabbableCollider;
                }
            }
        }

        // Disable grab volumes to prevent overlaps
        GrabVolumeEnable(false);

        if (closestGrabbable != null)
        {
            if (closestGrabbable.isGrabbed)
            {
                closestGrabbable.grabbedBy.OffhandGrabbed(closestGrabbable);
            }

            _grabbedObj = closestGrabbable;
            _grabbedObj.GrabBegin(this, closestGrabbableCollider);

            _lastPos = transform.position;
            _lastRot = transform.rotation;

            // Set up offsets for grabbed object desired position relative to hand.
            if (_grabbedObj.snapPosition)
            {
                _grabbedObjectPosOff = gripTransform.localPosition;
                if (_grabbedObj.snapOffset)
                {
                    Vector3 snapOffset = _grabbedObj.snapOffset.position;
                    if (m_controller == OVRInput.Controller.LTouch)
                    {
                        snapOffset.x = -snapOffset.x;
                    }
                    _grabbedObjectPosOff += snapOffset;
                }
            }
            else
            {
                Vector3 relPos = _grabbedObj.transform.position - transform.position;
                relPos = Quaternion.Inverse(transform.rotation) * relPos;
                _grabbedObjectPosOff = relPos;
            }

            if (_grabbedObj.snapOrientation)
            {
                _grabbedObjectRotOff = gripTransform.localRotation;
                if (_grabbedObj.snapOffset)
                {
                    _grabbedObjectRotOff = _grabbedObj.snapOffset.rotation * _grabbedObjectRotOff;
                }
            }
            else
            {
                Quaternion relOri = Quaternion.Inverse(transform.rotation) * _grabbedObj.transform.rotation;
                _grabbedObjectRotOff = relOri;
            }

            MoveGrabbedObject(_lastPos, _lastRot);
        }
    }
コード例 #23
0
 /// <summary>
 /// Attempts to transfer ownership of grabbable object to another grabber
 /// Can override to 'lock' objects to a grabber, if desired
 /// </summary>
 /// <param name="ownerGrab"></param>
 /// <param name="otherGrabber"></param>
 /// <returns></returns>
 public virtual bool CanTransferOwnershipTo(BaseGrabbable ownerGrab, BaseGrabber otherGrabber)
 {
     Debug.Log("Transferring ownership of " + ownerGrab.name + " to grabber " + otherGrabber.name);
     grabbedObjects.Remove(ownerGrab);
     return(true);
 }
コード例 #24
0
 protected virtual void Awake()
 {
     grabbable = GetComponent <BaseGrabbable>();
 }
コード例 #25
0
 protected void GrabbableRelease(Vector3 linearVelocity, Vector3 angularVelocity)
 {
     _grabbedObj.GrabEnd(linearVelocity, angularVelocity);
     _grabbedObj = null;
 }
コード例 #26
0
 public bool IsGrabbing(BaseGrabbable grabbable)
 {
     return(grabbedObjects.Contains(grabbable));
 }
コード例 #27
0
 /// <summary>
 /// throw behaviour should be over ridden in a non-abstract class
 /// </summary>
 /// <param name="grabber"></param>
 public virtual void Throw(BaseGrabbable grabber)
 {
     Debug.Log("Throwing..");
     thrown = true;
 }