コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        public void BadAttach(ConnectableAttachment attachment, bool otherAlreadyNotified = false)
        {
            if (OnBadAttach != null)
            {
                OnBadAttach.Invoke(this, attachment);
            }

            if (!otherAlreadyNotified && attachment != null)
            {
                attachment.BadAttach(this, true);
            }
        }
コード例 #3
0
        public void AttachSuccess(ConnectableAttachment attachment, bool otherAlreadyNotified = false)
        {
            if (OnAttachSuccess != null)
            {
                OnAttachSuccess.Invoke(this, attachment);
            }

            if (!otherAlreadyNotified && attachment != null)
            {
                attachment.AttachSuccess(this, true);
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public virtual bool CompatibleAttachment(ConnectableAttachment attachment)
 {
     return(true);
 }
コード例 #7
0
 protected void EnableCollisions(ConnectableAttachment attachment)
 {
     UnityEngine.Physics.IgnoreCollision(attachment.gameObject.GetComponent <Collider>(), this.gameObject.GetComponent <Collider>(), false);
 }