コード例 #1
0
        /// <summary>
        /// This is typically called by the GrabAction on the SnapZone
        /// </summary>
        /// <param name="grabber"></param>
        public void GrabEquipped(Grabber grabber)
        {
            if (grabber != null)
            {
                if (HeldItem)
                {
                    // Not allowed to be removed
                    if (!CanBeRemoved())
                    {
                        return;
                    }

                    var g = HeldItem;
                    if (DuplicateItemOnGrab)
                    {
                        ReleaseAll();

                        // Position next to grabber if somewhat far away
                        if (Vector3.Distance(g.transform.position, grabber.transform.position) > 0.2f)
                        {
                            g.transform.position = grabber.transform.position;
                        }

                        // Instantiate the object before it is grabbed
                        GameObject go = Instantiate(g.gameObject, transform.position, Quaternion.identity) as GameObject;
                        if (nextBallIsGold == true)
                        {
                            go.GetComponent <Ball>().SetGoldBall(true);
                            nextBallIsGold = false;
                        }
                        else
                        {
                            go.GetComponent <Ball>().SetGoldBall(false);
                        }
                        Grabbable grab = go.GetComponent <Grabbable>();

                        // Ok to attach it to snap zone now
                        this.GrabGrabbable(grab);

                        // Finish Grabbing the desired object
                        grabber.GrabGrabbable(g);
                    }
                    else
                    {
                        ReleaseAll();

                        // Position next to grabber if somewhat far away
                        if (Vector3.Distance(g.transform.position, grabber.transform.position) > 0.2f)
                        {
                            g.transform.position = grabber.transform.position;
                        }

                        // Do grab
                        grabber.GrabGrabbable(g);
                    }
                }
            }
        }
コード例 #2
0
ファイル: AmmoDispenser.cs プロジェクト: GabeJacobs/PaperToss
        public void GrabAmmo(Grabber grabber)
        {
            if (GetAmmo() != null)
            {
                GameObject ammo = Instantiate(GetAmmo(), grabber.transform.position, grabber.transform.rotation) as GameObject;
                Grabbable  g    = ammo.GetComponent <Grabbable>();

                // Disable rings for performance
                GrabbableRingHelper grh = ammo.GetComponentInChildren <GrabbableRingHelper>();
                if (grh)
                {
                    Destroy(grh);
                    RingHelper r = ammo.GetComponentInChildren <RingHelper>();
                    Destroy(r.gameObject);
                }


                // Offset to hand
                ammo.transform.parent        = grabber.transform;
                ammo.transform.localPosition = -g.GrabPositionOffset;
                ammo.transform.parent        = null;

                grabber.GrabGrabbable(g);
            }
        }
コード例 #3
0
ファイル: DetachableLimb.cs プロジェクト: hwhea/Project-Dark
        public void DoDismemberment(Grabber grabbedBy)
        {
            if (ReplaceGrabbableWith && grabbedBy != null)
            {
                if (grabbedBy.HeldGrabbable)
                {
                    grabbedBy.HeldGrabbable.DropItem(grabbedBy, true, true);
                }

                if (ReplaceGrabbableWith)
                {
                    ReplaceGrabbableWith.SetActive(true);
                    Grabbable g = ReplaceGrabbableWith.GetComponent <Grabbable>();
                    g.transform.parent     = null;
                    g.transform.localScale = Vector3.one;
                    g.UpdateOriginalParent();

                    grabbedBy.GrabGrabbable(g);
                }
            }

            if (ShrinkBone)
            {
                ShrinkBone.localScale = Vector3.zero;
                ShrinkBone.gameObject.SetActive(false);
            }

            if (EnableOnDetach)
            {
                EnableOnDetach.SetActive(true);
            }
        }
コード例 #4
0
        public void GrabEquipped(Grabber grabber)
        {
            if (grabber != null)
            {
                if (HeldItem)
                {
                    var g = HeldItem;

                    if (DuplicateItemOnGrab)
                    {
                        ReleaseAll();

                        // Position next to grabber if somewhat far away
                        if (Vector3.Distance(g.transform.position, grabber.transform.position) > 0.2f)
                        {
                            g.transform.position = grabber.transform.position;
                        }

                        // Instantiate the object before it is grabbed
                        GameObject go   = Instantiate(g.gameObject, transform.position, Quaternion.identity) as GameObject;
                        Grabbable  grab = go.GetComponent <Grabbable>();

                        // Ok to attach it to snap zone now
                        this.GrabGrabbable(grab);

                        // Finish Grabbing the desired object
                        grabber.GrabGrabbable(g);
                    }
                    else
                    {
                        ReleaseAll();

                        // Position next to grabber if somewhat far away
                        if (Vector3.Distance(g.transform.position, grabber.transform.position) > 0.2f)
                        {
                            g.transform.position = grabber.transform.position;
                        }

                        // Do grab
                        grabber.GrabGrabbable(g);
                    }
                }
            }
        }
コード例 #5
0
        // Pull out magazine from clip area
        public void OnGrabClipArea(Grabber grabbedBy)
        {
            if (HeldMagazine != null)
            {
                // Store reference so we can eject the clip first
                Grabbable temp = HeldMagazine;

                // Make sure the magazine can be gripped
                HeldMagazine.enabled = true;

                // Eject clip into hand
                detachMagazine();

                // Now transfer grab to the grabber
                temp.enabled = true;

                grabbedBy.GrabGrabbable(temp);
            }
        }
コード例 #6
0
        public void GrabAmmo(Grabber grabber)
        {
            if (demoClips == null)
            {
                demoClips = new List <Grabbable>();
            }

            if (demoClips.Count > 0 && demoClips[0] == null)
            {
                demoClips.RemoveAt(0);
            }

            if (AmmoObject != null)
            {
                // Make room for new clip. This ensures the demo doesn't ge bogged down
                if (demoClips.Count > 4 && demoClips[0] != null && demoClips[0].transform.parent == null)
                {
                    GameObject.Destroy(demoClips[0].gameObject);
                }

                GameObject ammo = Instantiate(AmmoObject, grabber.transform.position, grabber.transform.rotation) as GameObject;
                Grabbable  g    = ammo.GetComponent <Grabbable>();

                // Disable rings for performance
                GrabbableRingHelper grh = ammo.GetComponentInChildren <GrabbableRingHelper>();
                Destroy(grh);
                RingHelper r = ammo.GetComponentInChildren <RingHelper>();
                Destroy(r.gameObject);

                // Offset to hand
                ammo.transform.parent        = grabber.transform;
                ammo.transform.localPosition = -g.GrabPositionOffset;
                ammo.transform.parent        = null;

                if (g != null)
                {
                    demoClips.Add(g);
                }

                grabber.GrabGrabbable(g);
            }
        }
コード例 #7
0
        public void GrabEquipped(Grabber grabber)
        {
            if (grabber != null)
            {
                if (HeldItem)
                {
                    var g = HeldItem;
                    ReleaseAll();

                    // Position next to grabber if somewhat faraways
                    if (Vector3.Distance(g.transform.position, grabber.transform.position) > 0.2f)
                    {
                        g.transform.position = grabber.transform.position;
                    }

                    // Do grab
                    grabber.GrabGrabbable(g);
                }
            }
        }
コード例 #8
0
ファイル: Grabbable.cs プロジェクト: hwhea/Project-Dark
        void Update()
        {
            if (remoteGrabbing)
            {
                Vector3    remoteDestination = getRemotePosition(flyingTo);
                Quaternion remoteRotation    = getRemoteRotation();


                float dist2 = Vector3.SqrMagnitude(remoteDestination - transform.position);
                float dist  = Vector3.Distance(transform.position, remoteDestination);
                // reached destination, snap to final transform position
                if (dist < 0.01f)
                {
                    transform.position = remoteDestination;
                    transform.rotation = grabTransform.rotation;

                    if (flyingTo != null)
                    {
                        flyingTo.GrabGrabbable(this);
                    }
                }
                // Getting close so speed up
                else if (dist < 0.05f)
                {
                    transform.position = Vector3.Lerp(transform.position, remoteDestination, Time.deltaTime * GrabSpeed * 2);
                    transform.rotation = Quaternion.Lerp(transform.rotation, remoteRotation, Time.deltaTime * GrabSpeed * 2);
                }
                // Normal Lerp
                else
                {
                    transform.position = Vector3.Lerp(transform.position, remoteDestination, Time.deltaTime * GrabSpeed);
                    transform.rotation = Quaternion.Lerp(transform.rotation, remoteRotation, Time.deltaTime * GrabSpeed);
                }
            }

            if (BeingHeld)
            {
                // Something happened to our Grabber. Drop the item
                if (heldByGrabbers == null)
                {
                    DropItem(null, true, true);
                    return;
                }

                // Make sure all collisions are valid
                filterCollisions();

                if (collisions != null && collisions.Count > 0)
                {
                    lastCollisionSeconds = Time.time;
                }

                for (int x = 0; x < heldByGrabbers.Count; x++)
                {
                    Grabber g = heldByGrabbers[x];

                    // Should we drop the item if it's too far away?
                    if (BreakDistance > 0 && Vector3.Distance(grabPosition, g.transform.position) > BreakDistance)
                    {
                        DropItem(g, true, true);
                        break;
                    }

                    // Should we drop the item if no longer holding the required Grabbable?
                    if (OtherGrabbableMustBeGrabbed != null && !OtherGrabbableMustBeGrabbed.BeingHeld)
                    {
                        // Fixed joints work ok. Configurable Joints have issues
                        if (GetComponent <ConfigurableJoint>() != null)
                        {
                            DropItem(g, true, true);
                            break;
                        }
                    }

                    // Fire off any relevant events
                    callEvents(g);
                }

                // Rotate the grabber to look at our secondary object
                checkSecondaryLook();
            }
        }