// PUBLIC METHODS: ----------------------------------------------------- public IEnumerator ChangeWeapon(Weapon weapon, Ammo ammo = null) { this.RequireAimIK(); if (this.isReloading) { yield break; } if (this.isDrawing) { yield break; } if (this.isHolstering) { yield break; } if (this.character != null) { if (!this.character.IsControllable()) { yield break; } if (this.character.characterLocomotion.isBusy) { yield break; } } if (this.character != null) { this.character.characterLocomotion.isBusy = true; } if (this.isAiming) { this.StopAiming(); } if (this.isChargingShot) { this.currentAmmo.StopCharge(this); } yield return(this.UnequipWeapon()); yield return(this.EquipWeapon(weapon, ammo)); if (this.character != null) { this.character.characterLocomotion.isBusy = false; } }
// PRIVATE & PROTECTED METHODS: ---------------------------------------- private IEnumerator UnequipWeapon() { this.OnBeforeUnequipWeapon(); WaitForSeconds wait = new WaitForSeconds(0f); if (this.currentWeapon != null) { if (this.currentWeapon.aiming.state != null) { CharacterState currentState = this.animator.GetState(Weapon.STATE_LAYER_IDLE); if (currentState != null && currentState.exitClip != null) { float time = this.ResetState(currentState, Weapon.STATE_LAYER_IDLE); wait = new WaitForSeconds(time); } } this.PlayAudio(this.currentWeapon.audioHolster); if (this.aimIK) { this.aimIK.SetWeapon(null, null); } } this.isHolstering = true; yield return(wait); this.eventUnequipWeapon.Invoke(this.currentWeapon); if (this.modelWeapon != null) { Destroy(this.modelWeapon); } if (this.currentAmmo != null) { this.currentAmmo.RemoveAmmoPrefab(this); } this.OnAfterUnequipWeapon(); yield return(wait); this.isHolstering = false; this.currentWeapon = null; this.currentAmmo = null; }
public void ChangeAmmo(Ammo ammo) { this.RequireAimIK(); if (this.isReloading) { return; } if (this.isDrawing) { return; } if (this.isHolstering) { return; } if (this.isChargingShot) { this.currentAmmo.StopCharge(this); } this.currentAmmo = ammo; this.eventChangeAmmo.Invoke(this.currentAmmo); }
// INITIALIZERS: ------------------------------------------------------- private void OnEnable() { this.ammo = this.target as Ammo; if (this.ammo == null) { return; } this.spID = this.serializedObject.FindProperty("ammoID"); if (string.IsNullOrEmpty(this.spID.stringValue)) { this.spID.stringValue = Guid.NewGuid().ToString("N"); this.serializedObject.ApplyModifiedProperties(); this.serializedObject.Update(); } this.spName = this.serializedObject.FindProperty("ammoName"); this.spDesc = this.serializedObject.FindProperty("ammoDesc"); this.sectionGeneral = new Section("General", this.LoadIcon("General"), this.Repaint); this.sectionCharge = new Section("Charging", this.LoadIcon("Charging"), this.Repaint); this.sectionAiming = new Section("Aiming", this.LoadIcon("Aiming"), this.Repaint); this.sectionShooting = new Section("Shooting", this.LoadIcon("Shooting"), this.Repaint); this.sectionAmmoRepr = new Section("Ammo Model", this.LoadIcon("Ammo-Model"), this.Repaint); this.sectionAudio = new Section("Audio", this.LoadIcon("Audio"), this.Repaint); this.sectionAnimations = new Section("Animations", this.LoadIcon("Animations"), this.Repaint); this.spFireRate = this.serializedObject.FindProperty("fireRate"); this.spInfiniteAmmo = this.serializedObject.FindProperty("infiniteAmmo"); this.spClipSize = this.serializedObject.FindProperty("clipSize"); this.spAutoReload = this.serializedObject.FindProperty("autoReload"); this.spReloadDuration = this.serializedObject.FindProperty("reloadDuration"); this.spChargeType = this.serializedObject.FindProperty("chargeType"); this.spMinChargeTime = this.serializedObject.FindProperty("minChargeTime"); this.spChargeTime = this.serializedObject.FindProperty("chargeTime"); this.spChargeValue = this.serializedObject.FindProperty("chargeValue"); this.spAimingMode = this.serializedObject.FindProperty("aimingMode"); this.spTrajectory = this.serializedObject.FindProperty("trajectory"); this.spCrosshair = this.serializedObject.FindProperty("crosshair"); this.spCrosshairFocusTime = this.serializedObject.FindProperty("crosshairFocusTime"); this.spProjectileVelocity = this.serializedObject.FindProperty("projectileVelocity"); this.spShootType = this.serializedObject.FindProperty("shootType"); this.spDistance = this.serializedObject.FindProperty("distance"); this.spRadius = this.serializedObject.FindProperty("radius"); this.spLayerMask = this.serializedObject.FindProperty("layerMask"); this.spTriggersMask = this.serializedObject.FindProperty("triggersMask"); this.spPrefabImpactEffect = this.serializedObject.FindProperty("prefabImpactEffect"); this.spPrefabMuzzleFlash = this.serializedObject.FindProperty("prefabMuzzleFlash"); this.spShootTrail = this.serializedObject.FindProperty("shootTrail"); this.spPrefabProjectile = this.serializedObject.FindProperty("prefabProjectile"); this.spRecoil = this.serializedObject.FindProperty("recoil"); this.spDelay = this.serializedObject.FindProperty("delay"); this.spPushForce = this.serializedObject.FindProperty("pushForce"); this.spMinSpread = this.serializedObject.FindProperty("minSpread"); this.spMaxSpread = this.serializedObject.FindProperty("maxSpread"); this.spPrefabAmmo = this.serializedObject.FindProperty("prefabAmmo"); this.spPrefabAmmoBone = this.serializedObject.FindProperty("prefabAmmoBone"); this.spPrefabAmmoPosition = this.serializedObject.FindProperty("prefabAmmoPosition"); this.spPrefabAmmoRotation = this.serializedObject.FindProperty("prefabAmmoRotation"); this.spAudioShoot = this.serializedObject.FindProperty("audioShoot"); this.spAudioEmpty = this.serializedObject.FindProperty("audioEmpty"); this.spAudioReload = this.serializedObject.FindProperty("audioReload"); this.spAnimationShoot = this.serializedObject.FindProperty("animationShoot"); this.spMaskShoot = this.serializedObject.FindProperty("maskShoot"); this.spAnimationReload = this.serializedObject.FindProperty("animationReload"); this.spMaskReload = this.serializedObject.FindProperty("maskReload"); this.spActionsOnStartCharge = this.serializedObject.FindProperty("actionsOnStartCharge"); this.spActionsOnEndCharge = this.serializedObject.FindProperty("actionsOnEndCharge"); this.spActionsOnShoot = this.serializedObject.FindProperty("actionsOnShoot"); this.InitActions(this.spActionsOnStartCharge, PATH_ONSTART); this.InitActions(this.spActionsOnEndCharge, PATH_ONEND); this.InitActions(this.spActionsOnShoot, PATH_ONSHOOT); }