private void OnWeaponPullOut(GunAtt gunAtt) { gunRecoverSpeed = gunAtt.spreadRecoverSpeed; if (gunAtt.crosshair2D) { cCrosshairSprite = gunAtt.crosshair2D; cCrosshairCount = gunAtt.crosshairCount; } else { cCrosshairSprite = defaultCrosshair2D; cCrosshairCount = defaultCrosshairCount; } cImmutedSpread = gunAtt.immutedSpreadMax.x > gunAtt.immutedSpreadMax.y ? gunAtt.immutedSpreadMax.x : gunAtt.immutedSpreadMax.y; if (cCrosshairCount <= 1) { cImmutedSpread = 0; additionalFireSpace = 0; } CreateImgs(); cAlpha = 0; chEnabled = false; SetAlphaColor(0); }
virtual public void OnNewClipInLeftHand(AIBrain ai) { GunAtt gunAtt = ai.GetCurrentWeaponScript(); // instantiate new clip in left hand if (gunAtt && gunAtt.curClipObject && gunAtt.curClipPrefab) { // instantiate new clip tempNewClip = gunAtt.InstantiateReturn(gunAtt.curClipPrefab); tempNewClip.SetParent(LeftHandHold, true); tempNewClip.localPosition = Vector3.zero; tempNewClip.localRotation = Quaternion.identity; LeftHandHold.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.LeftHandClip).localPosition; LeftHandHold.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.LeftHandClip).localRotation; tempNewClip.GetComponent <Rigidbody>().isKinematic = true; tempNewClip.GetComponent <Collider>().enabled = false; gunAtt.StartCoroutine(gunAtt.FixClipPosInLHand(tempNewClip)); return; } }
private void Update() { if (ai == null || ssw == null || ssl == null) { return; } GunAtt gunAtt = ai.GetCurrentWeaponScript(); if (gunAtt) { if (Mathf.Abs(immutedTargetX - cImmuted.x) < eps) { immutedTargetX = (immutedSignX ? -1 : 1) * Random.Range(0, ssw.WHandIKProps.immutedWeaponSpreadAgentMultiplier.x * gunAtt.immutedSpreadMax.x); immutedSignX = !immutedSignX; } if (Mathf.Abs(immutedTargetY - cImmuted.y) < eps) { immutedTargetY = (immutedSignY ? -1 : 1) * Random.Range(0, ssw.WHandIKProps.immutedWeaponSpreadAgentMultiplier.y * gunAtt.immutedSpreadMax.y); immutedSignY = !immutedSignY; } Vector2 immutedTarget = new Vector2(immutedTargetX, immutedTargetY); cImmuted = Vector2.Lerp(cImmuted, immutedTarget, Time.deltaTime * ssw.WHandIKProps.immutedSpreadChangeSpeed); transform.localPosition = Vector3.Lerp(transform.localPosition, defLocalPos + new Vector3(cImmuted.x, cImmuted.y, 0), gunAtt.spreadRecoverSpeed * ssw.WHandIKProps.weaponSpreadRecoverAgentMultiplier); ssw.weaponBodyBob = Mathf.Lerp(ssw.weaponBodyBob, 0, gunAtt.bodyRecoverSpeedInverse * ssl.LookIKProps.weaponBodyRecoverSpeedMultiplier * Time.deltaTime); } }
public void InvokeWeaponHolster(GunAtt gunAtt) { if (onWeaponHolster != null) { onWeaponHolster(gunAtt); } }
public void InvokeWeaponSwitch(GunAtt oldWeapon, GunAtt newWeapon) { if (onWeaponSwitch != null) { onWeaponSwitch(oldWeapon, newWeapon); } }
public void InvokeWeaponPullOut(GunAtt gunAtt) { if (onWeaponPullOut != null) { onWeaponPullOut(gunAtt); } }
public void InvokeWeaponCollect(GunAtt gunAtt) { if (onWeaponCollect != null) { onWeaponCollect(gunAtt); } }
public void InvokeWeaponDrop(GunAtt droppedWeapon, GunAtt nextWeapon) { if (onDropWeapon != null) { onDropWeapon(droppedWeapon, nextWeapon); } }
public void InvokeWeaponFire(GunAtt gunAtt) { if (onWeaponFire != null) { onWeaponFire(gunAtt); } }
public void InvokeWeaponReloadDone(GunAtt gunAtt) { if (onReloadDone != null) { onReloadDone(gunAtt); } }
public void InvokeWeaponUnAim(GunAtt gunAtt) { if (onWeaponUnAim != null) { onWeaponUnAim(gunAtt); } }
private void OnWeaponHolster(GunAtt gunAtt) { cCrosshairSprite = defaultCrosshair2D; cCrosshairCount = defaultCrosshairCount; DestroyImgs(); chEnabled = false; }
public override void ReloadWeapon(AIBrain ai) { ai.stateSystemAnimator.AnimateTrigger( ai, "Reload", false, false, "", "LowIdle", 1); ReleaseLeftHandFromWeapon(ai); // Drop current clip object from weapon if there is GunAtt gunAtt = ai.GetCurrentWeaponScript(); if (gunAtt != null && gunAtt.curClipObject && gunAtt.curClipPrefab) { gunAtt.curClipObject.SetParent(null); if (gunAtt.curClipObject.GetComponent <Rigidbody>()) { gunAtt.curClipObject.GetComponent <Rigidbody>().AddForce(ai.Transform.forward * 1f); gunAtt.curClipObject.GetComponent <Rigidbody>().isKinematic = false; } if (gunAtt.curClipObject.GetComponent <Collider>()) { gunAtt.curClipObject.GetComponent <Collider>().enabled = true; gunAtt.curClipObject.GetComponent <Collider>().isTrigger = false; } if (gunAtt.curClipObject.GetComponent <Destroy>()) { gunAtt.curClipObject.GetComponent <Destroy>().destroyTime = 30f; } } }
public override bool IsWeaponArmingFinished(AIBrain ai) { if (ai.stateSystemAnimator.IsStartedAnimationFinished("", "LowIdle")) { // Just in case GunAtt gunAtt = ai.GetCurrentWeaponScript(); if (RightHandHold && ai.HaveCurrentWeapon() && gunAtt && gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand)) { RightHandHold.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand).localPosition; RightHandHold.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand).localRotation; WeaponIK.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localPosition; WeaponIK.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localRotation; } ai.CurrentWeapon.SetParent(RightHandHold, false); ai.CurrentWeapon.localPosition = Vector3.zero; ai.CurrentWeapon.localRotation = Quaternion.identity; return(true); } return(false);; }
private void OnReload(GunAtt gunAtt) { TotalClipTexter(player.SmbWeapon.GetTotalAmmoCount()); CClipTexter(player.SmbWeapon.GetCurrentClip()); SecCClipTexter(player.SmbWeapon.GetSecCurrentClip()); SecTotalClipTexter(player.SmbWeapon.GetSecTotalAmmoCount()); }
public void InvokeWeaponHipFireAim(GunAtt gunAtt) { if (onWeaponHipFireAim != null) { onWeaponHipFireAim(gunAtt); } if (onWeaponAim != null) { onWeaponAim(gunAtt); } }
private void OnWeaponFire(GunAtt gunAtt) { if (cCrosshairCount <= 1) { additionalFireSpace = 0; } else { additionalFireSpace += gunAtt.spreadAmount * spaceMultiplierPerShot; } }
private void OnWeaponPullOut(GunAtt gunAtt) { CClipTexter(player.SmbWeapon.GetCurrentClip()); TotalClipTexter(player.SmbWeapon.GetTotalAmmoCount()); SetWeaponImage(gunAtt.hudSprite); SetWeaponName(gunAtt.weaponName); SetBulletImage(player.SmbWeapon.GetCurrentBulletSprite()); SetBulletnName(player.SmbWeapon.GetCurrentBulletName()); SetSecBulletImage(player.SmbWeapon.GetSecCurrentBulletSprite()); SetSecBulletnName(player.SmbWeapon.GetSecCurrentBulletName()); SecCClipTexter(player.SmbWeapon.GetSecCurrentClip()); SecTotalClipTexter(player.SmbWeapon.GetSecTotalAmmoCount()); }
public override bool HaveAmmoOnClip(AIBrain ai) { GunAtt gunAtt = ai.GetCurrentWeaponScript(); if (!gunAtt) { #if UNITY_EDITOR Debug.Log("No GunAtt script is attached to weapon"); return(false); #endif } return(gunAtt.currentClipCapacity > 0); }
private void OnWeaponCollect(GunAtt gunAtt) { SetWeaponImage(player.SmbWeapon.GetCurrentWeaponSprite()); SetWeaponName(player.SmbWeapon.GetCurrentWeaponName()); SetBulletImage(player.SmbWeapon.GetCurrentBulletSprite()); SetBulletnName(player.SmbWeapon.GetCurrentBulletName()); CClipTexter(player.SmbWeapon.GetCurrentClip()); TotalClipTexter(player.SmbWeapon.GetTotalAmmoCount()); SetSecBulletImage(player.SmbWeapon.GetSecCurrentBulletSprite()); SetSecBulletnName(player.SmbWeapon.GetSecCurrentBulletName()); SecCClipTexter(player.SmbWeapon.GetSecCurrentClip()); SecTotalClipTexter(player.SmbWeapon.GetSecTotalAmmoCount()); }
virtual public void OnNewClipOffLeftHand(AIBrain ai) { // new clip goes to weapon if (tempNewClip) { GunAtt gunAtt = ai.GetCurrentWeaponScript(); tempNewClip.SetParent(gunAtt.transform); tempNewClip.localPosition = gunAtt.clipDefLocalPos; tempNewClip.localRotation = gunAtt.clipDefLocalRot; gunAtt.curClipObject = tempNewClip; } tempNewClip = null; }
private void GetDefault() { GunAtt gunAtt = GetComponent <GunAtt>(); // Handle emptyLeftHandles = GetComponent <GunAtt>().GetFixersForType(WeaponFixerTypes.LeftHandle); // Clip if (gunAtt.curClipObject) { defClipPos = gunAtt.curClipObject.localPosition; defClipRot = gunAtt.curClipObject.localRotation; } defLeftHandAnimNoOnAim = gunAtt.leftHandAnimNoOnAim; defLeftHandAnimNoOnIdle = gunAtt.leftHandAnimNoOnIdle; defClipFixHolders = gunAtt.GetFixersForType(WeaponFixerTypes.LeftHandClip); }
virtual public void OnIsHandOnGun(AIBrain ai) { GunAtt gunAtt = ai.GetCurrentWeaponScript(); if (RightHandHold && ai.HaveCurrentWeapon() && gunAtt && gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand)) { RightHandHold.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand).localPosition; RightHandHold.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand).localRotation; WeaponIK.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localPosition; WeaponIK.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localRotation; } ai.CurrentWeapon.SetParent(RightHandHold, false); ai.CurrentWeapon.localPosition = Vector3.zero; ai.CurrentWeapon.localRotation = Quaternion.identity; }
private void HandleWeaponHandsUpdate(AIBrain ai) { GunAtt gunAtt = ai.GetCurrentWeaponScript(); if (gunAtt) { Vector3 targetLocalPos = target.localPosition; float spreadZ = (Mathf.Abs(target.localPosition.x) + Mathf.Abs(target.localPosition.y)) * randomTwistSign * WHandIKProps.weaponSpreadAgentMultipliers.z; WHandIKProps.weaponSpread = Quaternion.Euler(new Vector3(-targetLocalPos.x * gunAtt.spreadAxisMultipliers.x * WHandIKProps.weaponSpreadAgentMultipliers.x, -targetLocalPos.y * gunAtt.spreadAxisMultipliers.y * WHandIKProps.weaponSpreadAgentMultipliers.y, spreadZ * gunAtt.spreadAxisMultipliers.z)); WHandIKProps.rHandAim = Mathf.Lerp(CheckEpsilon(WHandIKProps.rHandAim, rightHandTarget), rightHandTarget, (rightHandTarget == 1 ? WHandIKProps.rightHandSmooth : WHandIKProps.rightHandBackSmooth) * Time.deltaTime); WHandIKProps.rHandAimRot = Mathf.Lerp(CheckEpsilon(WHandIKProps.rHandAimRot, rightHandTarget), rightHandTarget, (rightHandTarget == 1 ? WHandIKProps.rightHandSmooth : WHandIKProps.rightHandBackSmooth) * Time.deltaTime); WHandIKProps.lHandAim = Mathf.Lerp(CheckEpsilon(WHandIKProps.lHandAim, leftHandTarget), leftHandTarget, Time.deltaTime * (leftHandTarget == 1 ? WHandIKProps.leftHandSmooth : WHandIKProps.leftHandBackSmooth)); } }
public override void StartFiring(AIBrain ai) { GunAtt gunAtt = ai.GetCurrentWeaponScript(); #if UNITY_EDITOR if (!gunAtt) { Debug.Log("No GunAtt script is attached to weapon"); return; } #endif randShotCountI = Mathf.Max(1, (int)(.1f * gunAtt.maxClipCapacity * ((int)Random.Range((fireProps.randShotCount.x * fireProps.randShotCountAgentMultiplier.x), (fireProps.randShotCount.y * fireProps.randShotCountAgentMultiplier.y))))); randWaitTimerF = -1f; isFiring = true; }
private void FireWithTimer(AIBrain ai) { if (isFiring) { GunAtt gunAtt = ai.GetCurrentWeaponScript(); #if UNITY_EDITOR if (!gunAtt) { Debug.Log("No GunAtt script is attached to weapon"); return; } #endif if (ai.InfoCurrentTarget != null && ai.InfoCurrentTarget.GetFireToPosition() != Vector3.zero) { fireTo = ai.InfoCurrentTarget.GetFireToPosition(); } if (randWaitTimerF < 0 && randShotCountI > 0 && nextFireTimer < 0) { float bBob = 0; Vector3 fw = weaponIKParent.forward; Vector3 to = (-weaponIKParent.position + target.position).normalized; Quaternion xQ = Quaternion.FromToRotation(fw, to); gunAtt.Fire(ai.Transform, target, fireTo, ref bBob, ref randomTwistSign, xQ, fireProps.rayCBulletLayerMask); //bBob = Mathf.Sign(target.localPosition.x) * bBob; weaponBodyBob += bBob; nextFireTimer = 1; randShotCountI--; } if (randShotCountI <= 0) { randShotCountI = Mathf.Max(1, (int)(.1f * gunAtt.maxClipCapacity * (Random.Range((fireProps.randShotCount.x * fireProps.randShotCountAgentMultiplier.x), (fireProps.randShotCount.y * fireProps.randShotCountAgentMultiplier.y))))); randWaitTimerF = Random.Range(fireProps.randWaitTimer.x, fireProps.randWaitTimer.y); } randWaitTimerF -= Time.deltaTime; nextFireTimer -= Time.deltaTime * gunAtt.fireSpeed; } }
private void Update() { GunAtt cGunAtt = smbFire.GetCurrentWeaponScript(); if (cGunAtt && smbFire.IsAiming) { if (Mathf.Abs(immutedTargetX - cImmuted.x) < eps) { immutedTargetX = (immutedSignX ? -1 : 1) * Random.Range(0, smbFire.CFireProps.immutedWeaponSpreadAgentMultiplier.x * cGunAtt.immutedSpreadMax.x); immutedSignX = !immutedSignX; } if (Mathf.Abs(immutedTargetY - cImmuted.y) < eps) { immutedTargetY = (immutedSignY ? -1 : 1) * Random.Range(0, smbFire.CFireProps.immutedWeaponSpreadAgentMultiplier.y * cGunAtt.immutedSpreadMax.y); immutedSignY = !immutedSignY; } Vector2 immutedTarget = new Vector2(immutedTargetX, immutedTargetY); cImmuted = Vector2.Lerp(cImmuted, immutedTarget, Time.deltaTime * smbFire.CFireProps.immutedSpreadChangeSpeed); transform.localPosition = Vector3.Lerp(transform.localPosition, defLocalPos + new Vector3(cImmuted.x, cImmuted.y, 0), cGunAtt.spreadRecoverSpeed * smbFire.CFireProps.weaponSpreadRecoverAgentMultiplier); Vector3 camPosWoOffset = camTransform.position - camTransform.right * camTransform.GetComponent <PlayerCamera>().defaultCameraOffset.x; Vector3 plHeadPos = smbFire.cGunAtt.transform.position; float fixOffset = Vector3.Distance(camPosWoOffset, plHeadPos); RaycastHit hit; if (Physics.Raycast(camTransform.position + camTransform.forward * fixOffset, (-camTransform.position + transform.position).normalized, out hit, 999, smbFire.CFireProps.rayCBulletLayerMask)) { fireRef.position = hit.point; IsHit = true; } else { fireRef.position = camTransform.position + camTransform.forward * noHitZ; IsHit = false; } } }
public override void OnUpdate(ref bool needToReplan, ref bool needToReevaluateGoals, AIBrain ai) { GunAtt gunAtt = ai.GetCurrentWeaponScript(); if (gunAtt != null) { if (gunAtt.currentClipCapacity <= 0) { ai.WorldState.SetKey(DS.weaponLoaded, false); } else { ai.WorldState.SetKey(DS.weaponLoaded, true); } } else { ai.WorldState.SetKey(DS.weaponLoaded, true); } // AI is considered to always has ammo for now ai.WorldState.SetKey(DS.haveAmmo, true); }
private void OnFire(GunAtt gunAtt) { CClipTexter(player.SmbWeapon.GetCurrentClip()); SecCClipTexter(player.SmbWeapon.GetSecCurrentClip()); }
public void ManageParts() { GunAtt gunAtt = GetComponent <GunAtt>(); flashLight = null; spreadDecreaser = 0; damageIncreaser = 0; powerIncreaser = 0; forceToRigidbodyIncrease = 0; barrelSpreadDecreaser = 0; SecFireSpeed = .1f; gunAtt.SetFixersForType(emptyLeftHandles, WeaponFixerTypes.LeftHandle); gunAtt.SetFixersForType(defClipFixHolders, WeaponFixerTypes.LeftHandClip); fireSounds = gunAtt.sounds.fireSounds; SecFireGp = null; muzzleFlashPrefab = null; muzzleFlashPosRot = null; gunAtt.clipDefLocalPos = defClipPos; gunAtt.clipDefLocalRot = defClipRot; gunAtt.leftHandAnimNoOnAim = defLeftHandAnimNoOnAim; gunAtt.leftHandAnimNoOnIdle = defLeftHandAnimNoOnIdle; GunPart[] childGunParts = transform.GetComponentsInChildren <GunPart>(); foreach (var childGPart in childGunParts) { if (childGPart.GetComponent <GPBarrel>()) { if (childGPart.GetComponent <GPBarrel>().overrideFireSounds) { fireSounds = childGPart.GetComponent <GPBarrel>().fireSounds; } powerIncreaser += childGPart.GetComponent <GPBarrel>().bulletPowerIncrease; damageIncreaser += childGPart.GetComponent <GPBarrel>().damageIncrease; barrelSpreadDecreaser += childGPart.GetComponent <GPBarrel>().spreadDecrease; forceToRigidbodyIncrease += childGPart.GetComponent <GPBarrel>().bulletForceToRigidbodyIncrease; exitForceIncrease += childGPart.GetComponent <GPBarrel>().exitForceIncrease; muzzleFlashPosRot = childGPart.GetComponent <GPBarrel>().childMuzzleFlashPosRot; muzzleFlashPrefab = childGPart.GetComponent <GPBarrel>().muzzleFlashPrefab; } if (childGPart.GetComponent <GPClip>()) { if (childGPart.GetComponent <GunPart>().partPrefab) { gunAtt.curClipPrefab = childGPart.GetComponent <GunPart>().partPrefab.transform; } gunAtt.SetFixersForType(childGPart.GetComponent <GPClip>().leftHandClipFixers, WeaponFixerTypes.LeftHandClip); gunAtt.curClipObject = childGPart.transform; gunAtt.maxClipCapacity = childGPart.GetComponent <GPClip>().clipCapacity; gunAtt.currentClipCapacity = childGPart.GetComponent <GPClip>().clipCapacity; gunAtt.clipDefLocalPos = childGPart.transform.localPosition; gunAtt.clipDefLocalRot = childGPart.transform.localRotation; gunAtt.DisableRbAndCol(childGPart.transform); } if (childGPart.GetComponent <GPFlashlight>()) { flashLight = childGPart.GetComponent <GPFlashlight>(); } else if (childGPart.GetComponent <GPGrip>()) { spreadDecreaser += childGPart.GetComponent <GPGrip>().spreadDecrease; gunAtt.SetFixersForType(childGPart.GetComponent <GPGrip>().leftHandleFixers, WeaponFixerTypes.LeftHandle); gunAtt.leftHandAnimNoOnIdle = childGPart.GetComponent <GPGrip>().overrideLeftHandAnimNoOnIdle >= 0 ? childGPart.GetComponent <GPGrip>().overrideLeftHandAnimNoOnIdle : defLeftHandAnimNoOnIdle; gunAtt.leftHandAnimNoOnAim = childGPart.GetComponent <GPGrip>().overrideLeftHandAnimNoOnAim >= 0 ? childGPart.GetComponent <GPGrip>().overrideLeftHandAnimNoOnAim : defLeftHandAnimNoOnAim; } else if (childGPart.GetComponent <GPHandle>()) { spreadDecreaser += childGPart.GetComponent <GPHandle>().spreadDecrease; powerIncreaser += childGPart.GetComponent <GPHandle>().bulletPowerIncrease; } if (childGPart.GetComponent <GPSecondaryFire>()) { SecFireGp = childGPart.GetComponent <GPSecondaryFire>(); SecFireSpeed = childGPart.GetComponent <GPSecondaryFire>().fireSpeed; } if (childGPart.GetComponent <GPSight>()) { spreadDecreaser += childGPart.GetComponent <GPSight>().spreadDecrease; } if (childGPart.GetComponent <GPSpecial>()) { spreadDecreaser += childGPart.GetComponent <GPSpecial>().spreadDecrease; powerIncreaser += childGPart.GetComponent <GPSpecial>().powerIncrease; damageIncreaser += childGPart.GetComponent <GPSpecial>().damageIncrease; } } }