Beispiel #1
0
        /// <summary>
        /// Changes the character's current weapon to the one passed as a parameter
        /// </summary>
        /// <param name="newWeapon">The new weapon.</param>
        public virtual void ChangeWeapon(Weapon newWeapon, string weaponID, bool combo = false)
        {
            // if the character already has a weapon, we make it stop shooting
            if (CurrentWeapon != null)
            {
                if (!combo)
                {
                    ShootStop();
                    if (_weaponAim != null)
                    {
                        _weaponAim.RemoveReticle();
                    }
                    Destroy(CurrentWeapon.gameObject);
                }
            }

            if (newWeapon != null)
            {
                if (!combo)
                {
                    CurrentWeapon = (Weapon)Instantiate(newWeapon, WeaponAttachment.transform.position + newWeapon.WeaponAttachmentOffset, WeaponAttachment.transform.rotation);
                }
                CurrentWeapon.transform.parent        = WeaponAttachment.transform;
                CurrentWeapon.transform.localPosition = newWeapon.WeaponAttachmentOffset;
                CurrentWeapon.SetOwner(_character, this);
                CurrentWeapon.WeaponID = weaponID;
                _weaponAim             = CurrentWeapon.gameObject.MMGetComponentNoAlloc <WeaponAim>();
                // we handle (optional) inverse kinematics (IK)
                if (_weaponIK != null)
                {
                    _weaponIK.SetHandles(CurrentWeapon.LeftHandHandle, CurrentWeapon.RightHandHandle);
                }
                _projectileWeapon = CurrentWeapon.gameObject.MMFGetComponentNoAlloc <ProjectileWeapon>();
                if (_projectileWeapon != null)
                {
                    _projectileWeapon.SetProjectileSpawnTransform(ProjectileSpawn);
                }
                // we turn off the gun's emitters.
                CurrentWeapon.Initialization();
                CurrentWeapon.InitializeComboWeapons();
                CurrentWeapon.InitializeAnimatorParameters();
                InitializeAnimatorParameters();
            }
            else
            {
                CurrentWeapon = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Aims the weapon model at the target
        /// </summary>
        protected virtual void Update()
        {
            if (!AimWeaponModelAtTarget)
            {
                return;
            }

            if (_weaponAim == null)
            {
                _weaponAim = _handleWeapon.CurrentWeapon.gameObject.MMGetComponentNoAlloc <WeaponAim>();
            }
            else
            {
                this.transform.LookAt(_weaponAim.transform.position + 10f * _weaponAim.CurrentAim);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initialize this weapon.
        /// </summary>
        public virtual void Initialization()
        {
            Flipped         = false;
            _spriteRenderer = this.gameObject.GetComponent <SpriteRenderer>();
            _comboWeapon    = this.gameObject.GetComponent <ComboWeapon>();

            WeaponState = new MMStateMachine <WeaponStates>(gameObject, true);
            WeaponState.ChangeState(WeaponStates.WeaponIdle);
            WeaponAmmo          = GetComponent <WeaponAmmo>();
            _animatorParameters = new List <List <int> >();
            _aimableWeapon      = GetComponent <WeaponAim>();
            InitializeAnimatorParameters();
            if (WeaponAmmo == null)
            {
                CurrentAmmoLoaded = MagazineSize;
            }
            InitializeFeedbacks();
        }
Beispiel #4
0
        /// <summary>
        /// Changes the character's current weapon to the one passed as a parameter
        /// </summary>
        /// <param name="newWeapon">The new weapon.</param>
        public virtual void ChangeWeapon(Weapon newWeapon, string weaponID, bool combo = false)
        {
            // if the character already has a weapon, we make it stop shooting
            if (CurrentWeapon != null)
            {
                if (!combo)
                {
                    ShootStop();
                    if (_weaponAim != null)
                    {
                        _weaponAim.RemoveReticle();
                    }
                    Destroy(CurrentWeapon.gameObject);
                }
            }

            if (newWeapon != null)
            {
                if (!combo)
                {
                    CurrentWeapon = (Weapon)Instantiate(newWeapon, WeaponAttachment.transform.position + newWeapon.WeaponAttachmentOffset, WeaponAttachment.transform.rotation);
                }
                CurrentWeapon.transform.parent         = WeaponAttachment.transform;
                CurrentWeapon.transform.localPosition += newWeapon.WeaponAttachmentOffset;
                CurrentWeapon.WeaponID = weaponID;
                _weaponAim             = CurrentWeapon.GetComponent <WeaponAim>();

                // we turn off the gun's emitters.
                CurrentWeapon.Initialization();
                CurrentWeapon.InitializeComboWeapons();
                CurrentWeapon.InitializeAnimatorParameters();
            }
            else
            {
                CurrentWeapon = null;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Aims the weapon model at the target
        /// </summary>
        protected virtual void Update()
        {
            if (!AimWeaponModelAtTarget)
            {
                return;
            }

            if (_weaponAim == null)
            {
                if (_handleWeapon.CurrentWeapon != null)
                {
                    _weaponAim = _handleWeapon.CurrentWeapon.gameObject.MMGetComponentNoAlloc <WeaponAim>();
                }
            }
            else
            {
                _rotationDirection = _weaponAim.CurrentAim.normalized;
                if (LockVerticalRotation)
                {
                    _rotationDirection.y = 0;
                }
                this.transform.LookAt(_weaponAim.transform.position + 10f * _rotationDirection);
            }
        }
Beispiel #6
0
        protected virtual void InstantiateWeapon(Weapon newWeapon, string weaponID, bool combo = false)
        {
            if (!combo)
            {
                CurrentWeapon = (Weapon)Instantiate(newWeapon, WeaponAttachment.transform.position + newWeapon.WeaponAttachmentOffset, WeaponAttachment.transform.rotation);
            }
            CurrentWeapon.transform.parent        = WeaponAttachment.transform;
            CurrentWeapon.transform.localPosition = newWeapon.WeaponAttachmentOffset;
            CurrentWeapon.SetOwner(_character, this);
            CurrentWeapon.WeaponID = weaponID;
            _weaponAim             = CurrentWeapon.gameObject.MMGetComponentNoAlloc <WeaponAim>();

            // we handle (optional) inverse kinematics (IK)
            HandleWeaponIK();

            // we handle the weapon model
            HandleWeaponModel(newWeapon, weaponID, combo, CurrentWeapon);

            // we turn off the gun's emitters.
            CurrentWeapon.Initialization();
            CurrentWeapon.InitializeComboWeapons();
            CurrentWeapon.InitializeAnimatorParameters();
            InitializeAnimatorParameters();
        }
 /// <summary>
 /// On Awake we grab our weapon
 /// </summary>
 protected virtual void Awake()
 {
     _weapon       = this.GetComponent <Weapon>();
     _weaponAim    = this.GetComponent <WeaponAim>();
     _shootStopped = false;
 }