/// <summary> /// Async method to instant weapon switch. /// </summary> /// <param name="weaponNumber">Weapon number to switch to.</param> /// <returns>IEnumerator for use with StartCoroutine.</returns> /// /// <summary> public IEnumerator _InstantWeaponSwitch(int weaponNumber) { Debug.Log("_InstantWeaponSwitch:" + weaponNumber); rpgCharacterController.SetAnimatorTrigger(AnimatorTrigger.InstantSwitchTrigger); rpgCharacterController.SetIKOff(); // 1Handed. if (AnimationData.Is1HandedWeapon(weaponNumber)) { // Dual weapons. if (dualSwitch) { animator.SetInteger("Weapon", 7); StartCoroutine(_HideAllWeapons(false, false)); StartCoroutine(_WeaponVisibility(weaponNumber, true, true)); animator.SetInteger("LeftRight", 3); } else { animator.SetInteger("Weapon", 7); animator.SetInteger("WeaponSwitch", 7); if (rpgCharacterController.hasTwoHandedWeapon) { StartCoroutine(_HideAllWeapons(false, false)); } // Properly set animator left/right hand parameters. if (AnimationData.IsRightWeapon(weaponNumber)) { // Hide existing Righthand weapon or 2Handed weapon. if (rpgCharacterController.hasRightWeapon) { StartCoroutine(_WeaponVisibility(rpgCharacterController.rightWeapon, false, false)); } animator.SetInteger("RightWeapon", weaponNumber); rpgCharacterController.rightWeapon = weaponNumber; StartCoroutine(_WeaponVisibility(weaponNumber, true, false)); if (rpgCharacterController.hasLeftWeapon) { animator.SetInteger("LeftRight", 3); } else { animator.SetInteger("LeftRight", 2); } } else if (AnimationData.IsLeftWeapon(weaponNumber)) { if (rpgCharacterController.hasRightWeapon) { StartCoroutine(_WeaponVisibility(rpgCharacterController.leftWeapon, false, false)); } animator.SetInteger("LeftWeapon", weaponNumber); rpgCharacterController.leftWeapon = weaponNumber; StartCoroutine(_WeaponVisibility(weaponNumber, true, false)); if (rpgCharacterController.hasRightWeapon) { animator.SetInteger("LeftRight", 3); } else { animator.SetInteger("LeftRight", 1); } } } } // 2Handed. else if (AnimationData.Is2HandedWeapon(weaponNumber)) { animator.SetInteger("Weapon", weaponNumber); rpgCharacterController.rightWeapon = 0; rpgCharacterController.leftWeapon = 0; animator.SetInteger("LeftWeapon", 0); animator.SetInteger("RightWeapon", 0); StartCoroutine(_HideAllWeapons(false, false)); StartCoroutine(_WeaponVisibility(weaponNumber, true, false)); if (AnimationData.IsIKWeapon(weaponNumber)) { rpgCharacterController.SetIKOn(); } } // Switching to Unarmed or Relax. else { animator.SetInteger("Weapon", weaponNumber); rpgCharacterController.rightWeapon = 0; rpgCharacterController.leftWeapon = 0; animator.SetInteger("LeftWeapon", 0); animator.SetInteger("RightWeapon", 0); animator.SetInteger("LeftRight", 0); StartCoroutine(_HideAllWeapons(false, false)); } yield return(null); }