Ejemplo 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;
 }
Ejemplo n.º 2
0
        protected override void StartGrab(BaseGrabber grabber)
        {
            base.StartGrab(grabber);

            transform.SetParent(GrabberPrimary.transform);
            gameObject.GetComponent <Rigidbody>().isKinematic = true;
        }
Ejemplo 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);
        }
Ejemplo 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;
     }
 }
Ejemplo n.º 5
0
 protected override void AttachToGrabber(BaseGrabber grabber)
 {
     GetComponent <Rigidbody>().isKinematic = true;
     if (!activeGrabbers.Contains(grabber))
     {
         activeGrabbers.Add(grabber);
     }
 }
Ejemplo n.º 6
0
        protected override void DetachFromGrabber(BaseGrabber grabber)
        {
            if (_rigidbody == null)
            {
                _rigidbody = GetComponent <Rigidbody>();
            }

            _rigidbody.isKinematic = false;
            _rigidbody.useGravity  = true;
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo 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);
        }
Ejemplo 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));
            }
        }
Ejemplo 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));
            }
        }
Ejemplo 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;
        }
Ejemplo 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;
        }
Ejemplo 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;
        }
Ejemplo 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);
        }
Ejemplo 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);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Removes a grabber object from the list of available grabbers
 /// </summary>
 public void RemoveContact(BaseGrabber availableObject)
 {
     availableGrabbers.Remove(availableObject);
 }
Ejemplo n.º 17
0
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     base.DetachFromGrabber(grabber);
     rb.useGravity = true;
 }
Ejemplo n.º 18
0
 protected override void AttachToGrabber(BaseGrabber grabber)
 {
     base.AttachToGrabber(grabber);
     rb.useGravity = false;
 }
Ejemplo n.º 19
0
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     GetComponent <Rigidbody>().isKinematic = false;
     GetComponent <Rigidbody>().useGravity  = true;
 }
Ejemplo 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
 }
Ejemplo 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);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Adds a grabber object to the list of available grabbers
 /// </summary>
 public void AddContact(BaseGrabber availableObject)
 {
     availableGrabbers.Add(availableObject);
 }
Ejemplo 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
        }
Ejemplo n.º 24
0
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     Debug.Log("Detaching form grabber");
 }