public override void Ungrab(LocalInfo grabberInfo)
        {
            // base.Ungrab(grabberInfo);

            //Only if the grabber was grabbing this object
            if (grabbers.Contains(grabberInfo))
            {
                grabbers.Remove(grabberInfo);

                //If there are no more objects grabbing, then restore the PhysicsTransform script and possibly destroy
                if (grabbers.Count <= 0)
                {
                    OnCompletelyUngrabbed?.Invoke(this, grabberInfo);
                }

                OnUngrabbed?.Invoke(this, grabberInfo);
                //If there are no more objects grabbing, then restore the PhysicsTransform script and possibly destroy
                if (grabbers.Count <= 0)
                {
                    RestoreValues();
                    if (createdSelf)
                    {
                        GameObject.Destroy(_physicsObject);
                        createdSelf = false;
                    }
                }
            }
        }
Пример #2
0
        public override void Grab(LocalInfo grabberInfo)
        {
            base.Grab(grabberInfo);

            if (!grabbers.Exists(grabber => grabber.info == grabberInfo.info))
            {
                //Add physics transform if doesn't already exist and store it's values (important for when it does exist)
                if (PhysicsObject == null)
                {
                    _physicsObject = gameObject.AddComponent <PhysicsTransform>();
                    createdSelf    = true;
                }

                //Only store values if this is the first time being grabbed
                if (grabbers.Count <= 0)
                {
                    StoreValues();
                }

                //Set the values of the physics transform so that it is ready for grabbage
                PhysicsObject.follow = null;
                PhysicsObject.parent = null;
                PhysicsObject.anchorPositionPercent = 0;
                PhysicsObject.anchorRotationPercent = 0;
                PhysicsObject.counteractGravity     = true;
                PhysicsObject.maxForce = grabberInfo.maxForce;
                PhysicsObject.position = transform.position;
                PhysicsObject.rotation = transform.rotation;
                PhysicsObject.enabled  = true;
            }
        }
Пример #3
0
        public virtual LocalInfo CreateLocalInfo(Grabber.GrabInfo grabInfo, float maxForce)
        {
            var localInfo = new LocalInfo()
            {
                info          = grabInfo,
                localPosition = grabInfo.parent.InverseTransformPoint(transform.position),
                localRotation = grabInfo.parent.InverseTransformRotation(transform.rotation),
                maxForce      = maxForce
            };

            return(localInfo);
        }
Пример #4
0
        public virtual void Ungrab(LocalInfo grabberInfo)
        {
            //Only if the grabber was grabbing this object
            if (grabbers.Contains(grabberInfo))
            {
                grabbers.Remove(grabberInfo);

                //If there are no more objects grabbing, then restore the PhysicsTransform script and possibly destroy
                if (grabbers.Count <= 0)
                {
                    OnCompletelyUngrabbed?.Invoke(this, grabberInfo);
                }

                OnUngrabbed?.Invoke(this, grabberInfo);
            }
        }
Пример #5
0
        public virtual void Grab(LocalInfo grabberInfo)
        {
            if (!grabbers.Exists(grabber => grabber.info == grabberInfo.info))
            {
                //Only store values if this is the first time being grabbed
                if (grabbers.Count <= 0)
                {
                    OnFirstGrab?.Invoke(this, grabberInfo);
                }

                //Add current grabber as parent
                grabbers.Add(grabberInfo);

                OnGrabbed?.Invoke(this, grabberInfo);
            }
        }
Пример #6
0
        public virtual bool GetLocalInfo(Grabber.GrabInfo grabInfo, out LocalInfo localInfo)
        {
            var  matches            = grabbers.Where(grabber => grabber.info == grabInfo);
            bool isCurrentlyGrabber = matches.Count() > 0;

            if (isCurrentlyGrabber)
            {
                localInfo = matches.First();
            }
            else
            {
                localInfo = default;
            }

            return(isCurrentlyGrabber);
        }