protected void OnTriggerEnter(Collider other) { CollidersInRange.Add(other); bool needsExit = false; if (CollidersNeedingReEntry.TryGetValue(other, out needsExit) && needsExit) { return; } if (!AutomaticAttach) { return; } GameObject otherObj = other.gameObject; ConnectableAttachment attachment = otherObj.GetComponent <ConnectableAttachment>(); if (attachment != null) { if (!IsAttached || Unpluggable) { TryAttach(attachment); } } }
public void BadAttach(ConnectableAttachment attachment, bool otherAlreadyNotified = false) { if (OnBadAttach != null) { OnBadAttach.Invoke(this, attachment); } if (!otherAlreadyNotified && attachment != null) { attachment.BadAttach(this, true); } }
public void AttachSuccess(ConnectableAttachment attachment, bool otherAlreadyNotified = false) { if (OnAttachSuccess != null) { OnAttachSuccess.Invoke(this, attachment); } if (!otherAlreadyNotified && attachment != null) { attachment.AttachSuccess(this, true); } }
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); } }
public virtual bool TryAttach(ConnectableAttachment attach) { if (attach != null) { AttachAttempt(attach); if (CompatibleAttachment(attach)) { if (ExecuteGrab(attach)) { Attached = attach; AttachSuccess(attach); return(true); } } else { BadAttach(attach); } } Debug.Log("[" + name + "] " + "Attachment failed."); return(false); }
public virtual bool CompatibleAttachment(ConnectableAttachment attachment) { return(true); }
protected void EnableCollisions(ConnectableAttachment attachment) { UnityEngine.Physics.IgnoreCollision(attachment.gameObject.GetComponent <Collider>(), this.gameObject.GetComponent <Collider>(), false); }