Exemplo n.º 1
0
        /// <summary>
        /// Replace the current weapon for the target weapon and drop it.
        /// </summary>
        /// <param name="current">The current weapon.</param>
        /// <param name="target">The desired weapon.</param>
        /// <param name="drop">The current weapon Prefab.</param>
        private IEnumerator DropAndChange(IWeapon current, IWeapon target, GunPickup drop)
        {
            current.Deselect();
            if (!m_FastChangeWeapons)
            {
                yield return(new WaitForSeconds(((Gun)current).HideAnimationLength));
            }

            if (((Gun)current).DroppablePrefab)
            {
                // ReSharper disable once Unity.InefficientPropertyAccess
                Instantiate(((Gun)current).DroppablePrefab, drop.transform.position, drop.transform.rotation);
            }
            Destroy(drop.transform.gameObject);

            current.Viewmodel.SetActive(false);
            Select(target);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks the target object to analyze if it is a weapon.
        /// </summary>
        private void SearchForWeapons()
        {
            if (Target)
            {
                // Try to convert the target for a gun pickup.
                GunPickup target = Target.GetComponent <GunPickup>();

                // If the gun pickup is not null means that the target is actually a weapon.
                if (target)
                {
                    IWeapon weapon = GetWeaponByID(target.ID);

                    if (weapon == null)
                    {
                        return;
                    }

                    if (m_CurrentWeapon != null)
                    {
                        if (!m_CurrentWeapon.CanSwitch)
                        {
                            return;
                        }

                        if (IsEquipped(weapon))
                        {
                            return;
                        }

                        if (HasFreeSlot)
                        {
                            if (InputManager.GetButtonDown(m_UseButton))
                            {
                                EquipWeapon(GetWeaponIndexOnList(weapon.Identifier));
                                Destroy(target.transform.gameObject);
                                StartCoroutine(Change(m_CurrentWeapon, weapon));

                                m_PlayerBodySource.ForcePlay(m_ItemPickupSound, m_ItemPickupVolume);
                                CalculateWeight();
                            }
                        }
                        else
                        {
                            if (InputManager.GetButtonDown(m_UseButton))
                            {
                                UnequipWeapon(GetEquippedWeaponIndexOnList(m_CurrentWeapon.Identifier));
                                EquipWeapon(GetWeaponIndexOnList(weapon.Identifier));
                                StartCoroutine(DropAndChange(m_CurrentWeapon, weapon, target));

                                if (m_FastChangeWeapons)
                                {
                                    m_PlayerBodySource.ForcePlay(m_ItemPickupSound, m_ItemPickupVolume);
                                }

                                CalculateWeight();
                            }
                        }
                    }
                    else
                    {
                        if (HasFreeSlot)
                        {
                            if (InputManager.GetButtonDown(m_UseButton))
                            {
                                EquipWeapon(GetWeaponIndexOnList(weapon.Identifier));
                                Destroy(target.transform.gameObject);
                                Select(weapon);
                                CalculateWeight();
                            }
                        }
                    }
                }
            }
        }