// PRIVATE METHODS: ---------------------------------------------------- private void ShootGeneric(CharacterShooter shooter, float deviation, CharacterShooter.ShotType shotType) { shooter.UpdateShootFireRate(this.ammoID); shooter.PlayAudio(this.audioShoot); if (this.animationShoot && shooter.animator != null) { shooter.animator.CrossFadeGesture( this.animationShoot, 1f, this.maskShoot, 0.05f, 0.2f ); } if (this.prefabMuzzleFlash) { GameObject muzzleInstance = PoolManager.Instance.Pick(this.prefabMuzzleFlash); muzzleInstance.transform.SetPositionAndRotation( shooter.muzzle.GetPosition(), shooter.muzzle.GetRotation() ); } if (this.delay < 0.01f) { this.ShootSelection(shooter, deviation, shotType); } else { CoroutinesManager.Instance.StartCoroutine( this.ShootSelectionDelayed(shooter, deviation, shotType) ); } }
public void OnRecevieShot(CharacterShooter shooter, CharacterShooter.ShotType type) { if (((int)type & (int)this.filterByShotType) == 0) { return; } bool tagFilter = ( string.IsNullOrEmpty(this.filterByTag) || this.filterByTag == "Untagged" || shooter.CompareTag(this.filterByTag) ); if (!tagFilter) { return; } if (this.filterByWeapon && shooter.currentWeapon != this.filterByWeapon) { return; } if (this.filterByAmmo && shooter.currentAmmo != this.filterByAmmo) { return; } this.storeShooter.Set(shooter.gameObject, gameObject); this.ExecuteTrigger(shooter.gameObject); }
protected virtual void OnChangeAmmo(Ammo ammo) { if (ammo == null) { return; } this.currentAmmoID = ammo.ammoID; if (this.ammoMaxClip != null) { this.ammoMaxClip.text = ammo.clipSize.ToString(); } if (this.ammoName != null) { this.ammoName.text = ammo.ammoName.GetText(); } if (this.ammoDescription != null) { this.ammoDescription.text = ammo.ammoDesc.GetText(); } CharacterShooter shooter = this.character.GetComponent <CharacterShooter>(gameObject); if (shooter != null) { this.OnChangeInClip(this.currentAmmoID, shooter.GetAmmoInClip(this.currentAmmoID)); this.OnChangeInStorage(this.currentAmmoID, shooter.GetAmmoInStorage(this.currentAmmoID)); } }
public IEnumerator Reload(CharacterShooter shooter) { WaitForSeconds wait = new WaitForSeconds(this.reloadDuration / 2f); if (shooter.animator && this.animationReload) { float speed = this.animationReload.length / this.reloadDuration; shooter.animator.CrossFadeGesture( this.animationReload, speed, this.maskReload, 0.2f, 0.2f ); } if (shooter.aimIK) { shooter.aimIK.SetStability( shooter.currentWeapon.aiming.stabilizeBody, 0.1f ); } shooter.PlayAudio(this.audioReload); yield return(wait); this.AddAmmoPrefab(shooter); if (shooter.aimIK) { shooter.aimIK.SetStability(false); } shooter.eventReload.Invoke(shooter.currentWeapon, this); yield return(wait); }
public bool ExecuteChargedShot(CharacterShooter shooter, float deviation) { if (!this.CanExecuteChargedShoot(shooter)) { return(false); } if (Time.time - shooter.chargeShotStartTime < this.minChargeTime) { this.StopCharge(shooter); return(false); } if (!this.ClipRequirements(shooter, false)) { this.StopCharge(shooter); return(false); } float maxCharge = this.chargeTime.GetValue(shooter.gameObject); float charge = (Time.time - shooter.chargeShotStartTime) / maxCharge; this.chargeValue.Set(Mathf.Clamp01(charge), shooter.gameObject); this.Shoot(shooter, deviation, CharacterShooter.ShotType.Charge); this.StopCharge(shooter); return(true); }
public void AddAmmoPrefab(CharacterShooter shooter) { if (!this.prefabAmmo) { return; } CharacterAttachments attachments = this.GetCharacterAttachments(shooter); if (!attachments) { return; } GameObject instance = Instantiate <GameObject>( this.prefabAmmo, Vector3.zero, Quaternion.identity ); instance.transform.localScale = Vector3.one; attachments.Attach( (HumanBodyBones)this.prefabAmmoBone, instance, this.prefabAmmoPosition, Quaternion.Euler(this.prefabAmmoRotation) ); }
// INITIALIZERS: ------------------------------------------------------- protected void OnEnable() { this.instance = this.target as CharacterShooter; this.spCurrentWeapon = this.serializedObject.FindProperty("currentWeapon"); this.spCurrentAmmo = this.serializedObject.FindProperty("currentAmmo"); }
public override IEnumerator Execute(GameObject target, IAction[] actions, int index) { CharacterShooter charShooter = this.shooter.GetComponent <CharacterShooter>(target); if (charShooter == null || charShooter.currentWeapon == null || charShooter.currentAmmo == null) { Debug.LogError("Target Game Object does not have a CharacterShooter component"); yield break; } int burstCount = Mathf.Min( charShooter.GetAmmoInClip(charShooter.currentAmmo.ammoID), this.burstAmount.GetInt(target) ); if (burstCount <= 0) { burstCount = 1; } float fireRate = charShooter.currentAmmo.fireRate.GetValue(target); for (int i = 0; i < burstCount; ++i) { while (!charShooter.CanShootFireRate(charShooter.currentAmmo.ammoID, fireRate)) { yield return(null); } charShooter.Shoot(); } yield return(0); }
public override bool Check(GameObject target) { CharacterShooter shooter = this.character.GetComponent <CharacterShooter>(target); if (shooter == null) { return(false); } if (shooter.currentAmmo == null) { return(false); } string ammoID = shooter.currentAmmo.ammoID; int capacity = shooter.currentAmmo.clipSize; int inClip = shooter.GetAmmoInClip(ammoID); switch (this.state) { case State.IsFull: return(inClip >= capacity); case State.IsEmpty: return(inClip <= 0); } return(false); }
public override bool InstantExecute(GameObject target, IAction[] actions, int index) { if (ammo == null) { return(true); } CharacterShooter charShooter = this.shooter.GetComponent <CharacterShooter>(target); if (!charShooter) { Debug.LogError("Target Game Object does not have a CharacterShooter component"); return(true); } switch (this.operation) { case Operation.Add: charShooter.AddAmmoToStorage(this.ammo.ammoID, this.amount.GetInt(target)); break; case Operation.Set: charShooter.SetAmmoToStorage(this.ammo.ammoID, this.amount.GetInt(target)); break; } return(true); }
private void ShootTrajectoryCast(CharacterShooter shooter, float deviation, CharacterShooter.ShotType shotType) { TrajectoryRenderer.TrajectoryResult result = this.GetTrajectoryResult(shooter); if (result.hit.collider) { Vector3 pointA = result.hit.point; Vector3 pointB = result.hit.point; if (result.points.Length > 2) { pointA = result.points[result.count - 2]; pointB = result.points[result.count - 1]; } Vector3 direction = (pointA - pointB).normalized; Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, direction); GameObject other = result.hit.collider.gameObject; this.ExecuteShootActions( other, result.hit.point, rotation ); IgniterOnReceiveShot[] igniters = other.GetComponentsInChildren <IgniterOnReceiveShot>(); foreach (IgniterOnReceiveShot igniter in igniters) { if (igniter) { igniter.OnRecevieShot(shooter, shotType); } } if (!Mathf.Approximately(this.pushForce, 0f) && result.hit.rigidbody && direction != Vector3.zero) { result.hit.rigidbody.AddForceAtPosition( -direction * this.pushForce, result.hit.point, ForceMode.Impulse ); } if (this.prefabImpactEffect) { GameObject impact = PoolManager.Instance.Pick(this.prefabImpactEffect); impact.transform.SetPositionAndRotation(result.hit.point, rotation); } this.shootTrail.position1 = shooter.muzzle.GetPosition(); this.shootTrail.position2 = result.hit.point; } if (this.shootTrail.useShootingTrail) { ShootingTrailRenderer.Create(this.shootTrail, result); } }
protected void Callback(Weapon weapon) { CharacterShooter charShooter = this.GetShooter(); if (charShooter != null) { this.ExecuteTrigger(charShooter.gameObject); } }
private void Start() { CharacterShooter charShooter = this.GetShooter(); if (charShooter != null) { charShooter.eventOnAim.AddListener(this.OnAimChange); } }
private void Start() { CharacterShooter charShooter = this.GetShooter(); if (charShooter != null) { charShooter.eventUnequipWeapon.AddListener(this.Callback); } }
private void OnDestroy() { CharacterShooter shooter = this.character.GetComponent <CharacterShooter>(gameObject); if (shooter == null) { return; } }
private void Start() { CharacterShooter charShooter = this.GetShooter(); if (charShooter != null) { charShooter.eventChargedShotStop.AddListener(this.Callback); } }
private void OnDestroy() { CharacterShooter charShooter = this.GetShooter(); if (charShooter != null) { charShooter.eventOnAim.RemoveListener(this.OnAimChange); } }
private void OnDestroy() { CharacterShooter charShooter = this.GetShooter(); if (charShooter != null) { charShooter.eventChargedShotStop.RemoveListener(this.Callback); } }
private void OnDestroy() { CharacterShooter charShooter = this.GetShooter(); if (charShooter != null) { charShooter.eventUnequipWeapon.RemoveListener(this.Callback); } }
public void Setup() { this.shooter = HookPlayer.Instance.Get <CharacterShooter>(); if (CURRENT != null) { WeaponCrosshair.Destroy(); } CURRENT = this; }
private CharacterAttachments GetCharacterAttachments(CharacterShooter shooter) { CharacterAnimator characterAnimator = shooter.character.GetCharacterAnimator(); if (!characterAnimator) { return(null); } return(characterAnimator.GetCharacterAttachments()); }
public override IEnumerator Execute(GameObject target, IAction[] actions, int index) { CharacterShooter charShooter = this.shooter.GetComponent <CharacterShooter>(target); if (charShooter != null) { yield return(charShooter.ChangeWeapon(this.weapon, this.ammo)); } yield return(0); }
// PUBLIC METHODS: ------------------------------------------------------------------------ public bool StartChargedShot(CharacterShooter shooter) { if (!this.CanStartChargedShoot(shooter)) { return(false); } shooter.chargeShotStartTime = Time.time; shooter.isChargingShot = true; if (this.actionsOnStartCharge) { ShootData shootData = this.GetShootData(shooter); GameObject actionsInstance = Instantiate( this.actionsOnStartCharge.gameObject, shootData.originWeapon, Quaternion.FromToRotation( Vector3.up, shootData.destination - shootData.originWeapon ) ); actionsInstance.hideFlags = HideFlags.HideInHierarchy; Actions actions = actionsInstance.GetComponent <Actions>(); if (actions) { actions.Execute(shooter.gameObject, null); } } if (this.aimingMode == AimType.Trajectory) { if (shooter.trajectoryRenderer) { Destroy(shooter.trajectoryRenderer.gameObject); } this.trajectory.layerMask = this.layerMask; this.trajectory.maxDistance = this.distance; this.trajectory.shooter = shooter; Transform parent = (shooter.muzzle != null ? shooter.muzzle.transform : shooter.transform ); shooter.trajectoryRenderer = TrajectoryRenderer.Create(this.trajectory, parent); } shooter.eventChargedShotStart.Invoke(shooter.currentWeapon, this); return(true); }
private IEnumerator ShootSelectionDelayed(CharacterShooter shooter, float deviation, CharacterShooter.ShotType shotType) { WaitForSeconds wait = new WaitForSeconds(this.delay); yield return(wait); if (shooter) { this.ShootSelection(shooter, deviation, shotType); } }
private void OnAimChange(bool aim) { bool conditions = (aim && this.aim == Aim.OnStartAiming) || (!aim && this.aim == Aim.OnStopAiming); CharacterShooter charShooter = this.GetShooter(); if (charShooter != null && conditions) { this.ExecuteTrigger(charShooter.gameObject); } }
public override bool InstantExecute(GameObject target, IAction[] actions, int index) { CharacterShooter charShooter = this.shooter.GetComponent <CharacterShooter>(target); if (charShooter == null) { Debug.LogError("Target Game Object does not have a CharacterShooter component"); return(true); } charShooter.ExecuteChargedShot(); return(true); }
public void RemoveAmmoPrefab(CharacterShooter shooter) { if (!this.prefabAmmo) { return; } CharacterAttachments attachments = this.GetCharacterAttachments(shooter); if (!attachments) { return; } attachments.Remove((HumanBodyBones)this.prefabAmmoBone); }
public override bool InstantExecute(GameObject target, IAction[] actions, int index) { if (this.waitTillComplete) { return(false); } CharacterShooter charShooter = this.shooter.GetComponent <CharacterShooter>(target); if (charShooter) { CoroutinesManager.Instance.StartCoroutine(charShooter.Reload()); } return(true); }
public override bool InstantExecute(GameObject target, IAction[] actions, int index) { CharacterShooter shooterValue = this.shooter.GetComponent <CharacterShooter>(target); if (shooterValue == null) { return(true); } switch (this.targetType) { case TargetType.Target: IgniterOnReceiveShot[] ignitersTarget = this.target.GetComponentsInChildren <IgniterOnReceiveShot>(target); for (int i = 0; i < ignitersTarget.Length; ++i) { if (ignitersTarget[i] != null) { ignitersTarget[i].OnRecevieShot(shooterValue, this.shotType); } } break; case TargetType.AreaOfEffect: Vector3 pos = this.position.GetPosition(target); float rad = this.radius.GetValue(target); QueryTriggerInteraction query = QueryTriggerInteraction.Collide; Collider[] colliders = Physics.OverlapSphere(pos, rad, -1, query); for (int i = 0; i < colliders.Length; ++i) { IgniterOnReceiveShot[] colliderIgniters = colliders[i] .gameObject.GetComponentsInChildren <IgniterOnReceiveShot>(); for (int j = 0; j < colliderIgniters.Length; ++j) { if (colliderIgniters[j] != null) { colliderIgniters[j].OnRecevieShot(shooterValue, this.shotType); } } } break; } return(true); }
public bool CanExecuteChargedShoot(CharacterShooter shooter) { if (!this.ShootingRequirements(shooter)) { return(false); } if (!shooter.isChargingShot) { return(false); } if (this.chargeType == TriggerType.DisableCharge) { return(false); } return(true); }