Esempio n. 1
0
 protected override void StartGrab(BaseGrabber grabber)
 {
     base.StartGrab(grabber);
     transform.SetParent(grabber.GrabHandle);
     gameObject.GetComponent <Rigidbody>().isKinematic = true;
     transform.rotation = transform.parent.rotation;
 }
Esempio n. 2
0
        protected override void StartGrab(BaseGrabber grabber)
        {
            base.StartGrab(grabber);

            transform.SetParent(GrabberPrimary.transform);
            gameObject.GetComponent <Rigidbody>().isKinematic = true;
        }
Esempio n. 3
0
        public virtual bool TryGrabWith(BaseGrabber grabber)
        {
            // TODO error checking, multi-grab checking
            if (GrabState != GrabStateEnum.Inactive)
            {
                switch (grabStyle)
                {
                case GrabStyleEnum.Exclusive:
                    // Try to transfer ownership of grabbed object
                    BaseGrabber primary = GrabberPrimary;
                    if (GrabberPrimary.CanTransferOwnershipTo(this, grabber))
                    {
                        // Remove from grabbable list and detach
                        activeGrabbers.Remove(primary);
                        DetachFromGrabber(primary);
                    }
                    else
                    {
                        // If we can't, it's a no-go
                        return(false);
                    }
                    break;

                case GrabStyleEnum.Multi:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            StartGrab(grabber);
            return(true);
        }
Esempio n. 4
0
 /// <summary>
 /// Specify the target and turn off gravity. Otherwise gravity will interfere with desired grab effect
 /// </summary>
 protected override void StartGrab(BaseGrabber grabber)
 {
     base.StartGrab(grabber);
     if (_rigidbody)
     {
         _rigidbody.useGravity = false;
     }
 }
Esempio n. 5
0
 protected override void AttachToGrabber(BaseGrabber grabber)
 {
     GetComponent <Rigidbody>().isKinematic = true;
     if (!activeGrabbers.Contains(grabber))
     {
         activeGrabbers.Add(grabber);
     }
 }
Esempio n. 6
0
        protected override void DetachFromGrabber(BaseGrabber grabber)
        {
            if (_rigidbody == null)
            {
                _rigidbody = GetComponent <Rigidbody>();
            }

            _rigidbody.isKinematic = false;
            _rigidbody.useGravity  = true;
        }
        protected override void StartGrab(BaseGrabber grabber)
        {
            base.StartGrab(grabber);
            transform.position = new Vector3(0, 0, 0);
            Debug.Log(transform.position);
            transform.SetParent(grabber.GrabHandle);

            gameObject.GetComponent <Rigidbody>().isKinematic = true;
            transform.rotation = transform.parent.rotation;
            Debug.Log(transform.position);
        }
Esempio n. 8
0
        protected override void DetachFromGrabber(BaseGrabber grabber)
        {
            if (_rigidbody == null)
            {
                _rigidbody = GetComponent <Rigidbody>();
            }

            _rigidbody.isKinematic = false;
            _rigidbody.useGravity  = true;
            EatEnemies.Instance.RemoveEnemyFromList(gameObject);
        }
Esempio n. 9
0
        protected override void DetachFromGrabber(BaseGrabber grabber)
        {
            base.DetachFromGrabber(grabber);
            SpringJoint joint = gameObject.GetComponent <SpringJoint>();

            if (joint != null)
            {
                joint.connectedBody = null;
                //Destroy(joint);
                StartCoroutine(DestroyJointAfterDelay(joint));
            }
        }
Esempio n. 10
0
        protected override void DetachFromGrabber(BaseGrabber grabber)
        {
            base.DetachFromGrabber(grabber);
            FixedJoint joint = GetComponent <FixedJoint>();

            if (joint != null)
            {
                joint.connectedBody = null;
                //DestroyImmediate(joint);
                StartCoroutine(DestroyJointAfterDelay(joint));
            }
        }
Esempio n. 11
0
        protected override void StartGrab(BaseGrabber grabber)
        {
            base.StartGrab(grabber);

            if (this.gameObject.tag == "sticky")
            {
                SendMessage("Disconnecting");
                Destroy(GetComponent <FixedJoint>());
            }

            transform.SetParent(GrabberPrimary.transform);
            gameObject.GetComponent <Rigidbody>().isKinematic = true;
        }
Esempio n. 12
0
        protected override void AttachToGrabber(BaseGrabber grabber)
        {
            base.AttachToGrabber(grabber);
            FixedJoint joint = GetComponent <FixedJoint>();

            if (joint == null)
            {
                joint = gameObject.AddComponent <FixedJoint>();
            }
            joint.connectedBody = grabber.GetComponent <Rigidbody>();
            joint.anchor        = jointAnchor;
            joint.breakForce    = breakForce;
            joint.breakTorque   = breakTorque;
        }
Esempio n. 13
0
        protected override void AttachToGrabber(BaseGrabber grabber)
        {
            base.AttachToGrabber(grabber);
            SpringJoint joint = gameObject.GetComponent <SpringJoint>();

            if (joint == null)
            {
                joint = gameObject.AddComponent <SpringJoint>();
            }
            joint.connectedBody = grabber.GetComponent <Rigidbody>();
            joint.anchor        = new Vector3(0, 0.01f, 0.01f);
            joint.tolerance     = tolerance;
            joint.breakForce    = breakForce;
            joint.breakTorque   = breakTorque;
            joint.spring        = spring;
            joint.damper        = damper;
        }
Esempio n. 14
0
        // The next two functions provide basic behaviour. Extend from this base script in order to provide more specific functionality.

        protected override void AttachToGrabber(BaseGrabber grabber)
        {
            if (_rigidbody == null)
            {
                _rigidbody = GetComponent <Rigidbody>();
            }

            _rigidbody.isKinematic = true;
            if (!activeGrabbers.Contains(grabber))
            {
                activeGrabbers.Add(grabber);
            }


            DestroyEnemyUnit destroyEnemyScript = GetComponent <DestroyEnemyUnit>();

            destroyEnemyScript.ChangeStateToDestroyed(Vector3.zero);
            EatEnemies.Instance.AddEnemyToList(gameObject);
        }
Esempio n. 15
0
        protected virtual void StartGrab(BaseGrabber grabber)
        {
            Debug.Log("Start grab");
            if (GrabState == GrabStateEnum.Inactive)
            {
                Debug.Log("State is inactive");
                // If we're not already updating our grab state, start now
                activeGrabbers.Add(grabber);
                StartCoroutine(StayGrab());
            }
            else
            {
                Debug.Log("State is not inactive");
                // Otherwise just push the grabber
                activeGrabbers.Add(grabber);
            }

            // Attach ourselves to this grabber
            AttachToGrabber(grabber);
            if (OnGrabbed != null)
            {
                OnGrabbed(this);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Removes a grabber object from the list of available grabbers
 /// </summary>
 public void RemoveContact(BaseGrabber availableObject)
 {
     availableGrabbers.Remove(availableObject);
 }
Esempio n. 17
0
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     base.DetachFromGrabber(grabber);
     rb.useGravity = true;
 }
Esempio n. 18
0
 protected override void AttachToGrabber(BaseGrabber grabber)
 {
     base.AttachToGrabber(grabber);
     rb.useGravity = false;
 }
Esempio n. 19
0
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     GetComponent <Rigidbody>().isKinematic = false;
     GetComponent <Rigidbody>().useGravity  = true;
 }
Esempio n. 20
0
 protected virtual void DetachFromGrabber(BaseGrabber grabber)
 {
     // By default this does nothing
     // In most cases this will un-parent or destroy a joint
 }
Esempio n. 21
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);
 }
Esempio n. 22
0
 /// <summary>
 /// Adds a grabber object to the list of available grabbers
 /// </summary>
 public void AddContact(BaseGrabber availableObject)
 {
     availableGrabbers.Add(availableObject);
 }
Esempio n. 23
0
        // The next three functions provide basic behavior. Extend from this base script in order to provide more specific functionality.

        protected virtual void AttachToGrabber(BaseGrabber grabber)
        {
            // By default this does nothing
            // In most cases this will parent or create a joint
        }
Esempio n. 24
0
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     Debug.Log("Detaching form grabber");
 }