コード例 #1
0
        public bool SlideToggleLock()
        {
            if ((insertedMagazine != null) && (insertedMagazine.GetAmmoCount() <= 0))
            {
                return(false);
            }

            if (slideController != null)
            {
                // If the slide is locked back and there is a loaded magazine inserted, load the next round
                if (slideController.IsLocked())
                {
                    if (ConsumeOneFromMagazine())
                    {
                        roundChambered = true;
                    }
                    chamberRoundOnNext = false;
                    playSoundOnNext    = false;
                    isRacked           = true;
                    isPulledBack       = false;
                    slideController.ForwardState();
                    if (rackforwardSound != null)
                    {
                        rackforwardSound.Play();
                    }
                    UpdateAmmoCounter();
                    return(true);
                }
                // If the slide is held back by the player and not yet locked, lock it
                else if (slideController.IsHeld() && isPulledBack)
                {
                    slideController.LockedBackState();
                    if (emptySound != null)
                    {
                        emptySound.Play();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        protected void LateUpdate()
        {
            if ((slideObject.transform.localPosition.z <= PULL_THRESHOLD) && !isPulledBack)
            {
                if (slideController != null)
                {
                    if (slideController.IsHeld())
                    {
                        //currentSlideState = false;
                        if (pullbackSound != null)
                        {
                            pullbackSound.Play();
                        }
                        isPulledBack    = true;
                        isRacked        = false;
                        playSoundOnNext = true;
                        slideController.LockedBackState();
                        FrameworkCore.Animate(Animations, module.openAnimationRef);
                        shellReceiver.data.disableTouch = false;
                        //if (shellReceiver.data.locked && (currentReceiverAmmo < module.maxReceiverAmmo))
                        //{
                        //    shellReceiver.data.locked = false;
                        //}
                        if (roundChambered)
                        {
                            if (roundSpent)
                            {
                                FrameworkCore.ShootProjectile(item, module.shellID, shellEjectionPoint, null, module.shellEjectionForce, 1.0f, false, slideCapsuleStabilizer);
                            }
                            else
                            {
                                FrameworkCore.ShootProjectile(item, module.ammoID, shellEjectionPoint, null, module.shellEjectionForce, 1.0f, false, slideCapsuleStabilizer);
                            }
                            roundChambered = false;
                            slideController.ChamberRoundVisible(false);
                        }
                        if (CountAmmoFromReceiver() > 0)
                        {
                            chamberRoundOnNext = true;
                        }
                    }
                }
            }
            if ((slideObject.transform.localPosition.z > (PULL_THRESHOLD - RACK_THRESHOLD)) && isPulledBack)
            {
                if (CountAmmoFromReceiver() > 0)
                {
                    slideController.ChamberRoundVisible(true);
                }
            }
            if ((slideObject.transform.localPosition.z >= RACK_THRESHOLD) && !isRacked)
            {
                //currentSlideState = true;
                isRacked     = true;
                isPulledBack = false;
                shellReceiver.data.disableTouch = true;
                slideController.ForwardState();
                FrameworkCore.Animate(Animations, module.closeAnimationRef);
                if (playSoundOnNext)
                {
                    if (rackforwardSound != null)
                    {
                        rackforwardSound.Play();
                    }
                    playSoundOnNext = false;
                }

                if (chamberRoundOnNext)
                {
                    if (!ConsumeOneFromReceiver())
                    {
                        return;
                    }
                    slideController.ChamberRoundVisible(true);
                    chamberRoundOnNext = false;
                    roundChambered     = true;
                    roundSpent         = false;
                }
            }

            if (slideController != null)
            {
                slideController.FixCustomComponents();
            }
            else
            {
                return;
            }
            if (slideController.initialCheck)
            {
                return;
            }
            try
            {
                if (gunGripHeldRight || gunGripHeldLeft)
                {
                    slideController.UnlockSlide();
                    slideController.initialCheck = true;
                }
            }
            catch { Debug.Log("[ModularFirearmsFramework] Slide EXCEPTION"); }
        }