コード例 #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;
 }
コード例 #2
0
ファイル: GrabbableChild.cs プロジェクト: NatNat180/rat-maze
        protected override void StartGrab(BaseGrabber grabber)
        {
            base.StartGrab(grabber);

            transform.SetParent(GrabberPrimary.transform);
            gameObject.GetComponent <Rigidbody>().isKinematic = true;
        }
コード例 #3
0
ファイル: BaseGrabbable.cs プロジェクト: hekemp/ChessXR
        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);
        }
コード例 #4
0
ファイル: GrabbableSimple.cs プロジェクト: hekemp/ChessXR
 /// <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;
     }
 }
コード例 #5
0
 protected override void AttachToGrabber(BaseGrabber grabber)
 {
     GetComponent <Rigidbody>().isKinematic = true;
     if (!activeGrabbers.Contains(grabber))
     {
         activeGrabbers.Add(grabber);
     }
 }
コード例 #6
0
ファイル: GrabbableSimple.cs プロジェクト: hekemp/ChessXR
        protected override void DetachFromGrabber(BaseGrabber grabber)
        {
            if (_rigidbody == null)
            {
                _rigidbody = GetComponent <Rigidbody>();
            }

            _rigidbody.isKinematic = false;
            _rigidbody.useGravity  = true;
        }
コード例 #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);
        }
コード例 #8
0
        protected override void DetachFromGrabber(BaseGrabber grabber)
        {
            if (_rigidbody == null)
            {
                _rigidbody = GetComponent <Rigidbody>();
            }

            _rigidbody.isKinematic = false;
            _rigidbody.useGravity  = true;
            EatEnemies.Instance.RemoveEnemyFromList(gameObject);
        }
コード例 #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));
            }
        }
コード例 #10
0
ファイル: GrabbableFixedJoint.cs プロジェクト: hekemp/ChessXR
        protected override void DetachFromGrabber(BaseGrabber grabber)
        {
            base.DetachFromGrabber(grabber);
            FixedJoint joint = GetComponent <FixedJoint>();

            if (joint != null)
            {
                joint.connectedBody = null;
                //DestroyImmediate(joint);
                StartCoroutine(DestroyJointAfterDelay(joint));
            }
        }
コード例 #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;
        }
コード例 #12
0
ファイル: GrabbableFixedJoint.cs プロジェクト: hekemp/ChessXR
        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;
        }
コード例 #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;
        }
コード例 #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);
        }
コード例 #15
0
ファイル: BaseGrabbable.cs プロジェクト: hekemp/ChessXR
        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);
            }
        }
コード例 #16
0
ファイル: BaseGrabbable.cs プロジェクト: hekemp/ChessXR
 /// <summary>
 /// Removes a grabber object from the list of available grabbers
 /// </summary>
 public void RemoveContact(BaseGrabber availableObject)
 {
     availableGrabbers.Remove(availableObject);
 }
コード例 #17
0
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     base.DetachFromGrabber(grabber);
     rb.useGravity = true;
 }
コード例 #18
0
 protected override void AttachToGrabber(BaseGrabber grabber)
 {
     base.AttachToGrabber(grabber);
     rb.useGravity = false;
 }
コード例 #19
0
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     GetComponent <Rigidbody>().isKinematic = false;
     GetComponent <Rigidbody>().useGravity  = true;
 }
コード例 #20
0
ファイル: BaseGrabbable.cs プロジェクト: hekemp/ChessXR
 protected virtual void DetachFromGrabber(BaseGrabber grabber)
 {
     // By default this does nothing
     // In most cases this will un-parent or destroy a joint
 }
コード例 #21
0
ファイル: BaseGrabber.cs プロジェクト: salfare1121/WIP01
 /// <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);
 }
コード例 #22
0
ファイル: BaseGrabbable.cs プロジェクト: hekemp/ChessXR
 /// <summary>
 /// Adds a grabber object to the list of available grabbers
 /// </summary>
 public void AddContact(BaseGrabber availableObject)
 {
     availableGrabbers.Add(availableObject);
 }
コード例 #23
0
ファイル: BaseGrabbable.cs プロジェクト: hekemp/ChessXR
        // 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
        }
コード例 #24
0
ファイル: GrabbableMultiJoint.cs プロジェクト: hekemp/ChessXR
 protected override void DetachFromGrabber(BaseGrabber grabber)
 {
     Debug.Log("Detaching form grabber");
 }