public virtual void ShootAtTarget(Vector3 position, Vector3 direction) { if (WeaponState == WeaponStates.IsReadyToShoot) { var newBullet = SimplePool.Spawn(BulletPrefab, position, transform.rotation); var bulletBody = newBullet.GetComponent <Rigidbody2D>(); if (Accuracy > 100) { Accuracy = 100; } float acc = (100 - Accuracy) / 1000; Vector3 roughDirection = new Vector3(Random.Range(direction.x - acc, direction.x + acc), Random.Range(direction.y - acc, direction.y + acc)); roughDirection.Normalize(); bulletBody.velocity = roughDirection * BulletSpeed; _ammoLeft--; WeaponState = WeaponStates.IsInCoolDown; if (_ammoLeft <= 0) { WeaponState = WeaponStates.NeedsReloading; } } }
public void Reload() { if (currentState == WeaponStates.Active && ammoAmount > 0 && curAmmoClip < ammoClip) { currentState = WeaponStates.Reload; playerController.isReloading = true; StartCoroutine(WaitAndRun(reloadTime, () => { if (ammoAmount >= ammoClip - curAmmoClip) { ammoAmount = ammoAmount - (ammoClip - curAmmoClip); curAmmoClip = ammoClip; } else if (ammoAmount < ammoClip - curAmmoClip) { curAmmoClip += ammoAmount; ammoAmount = 0; } playerController.isReloading = false; currentState = WeaponStates.Active; })); } }
IEnumerator ShutdownRoutine() { weaponState = WeaponStates.PoweringDown; if(turret) { while(!turret.ReturnTurret()) //wait till turret has returned { yield return new WaitForFixedUpdate(); } } if(hasDeployAnim) { deployState.enabled = true; deployState.speed = -1; while(deployState.normalizedTime > 0) { yield return null; } deployState.normalizedTime = 0; deployState.speed = 0; deployState.enabled = false; } weaponState = WeaponStates.Disabled; }
public void Hide() { if (animator == null) { animator = GetComponent <Animator>(); } animator.SetBool("is_active", false); currentState = WeaponStates.Disabling; StartCoroutine(WaitAndRun(hideWeaponTime, () => { foreach (SkinnedMeshRenderer item in mesh) { item.enabled = false; } animator.enabled = false; FireEvent.RemoveListener(OnFire); currentState = WeaponStates.Disabled; })); }
void Awake() { //animator = gameObject.AddComponent<Animator>(); //animator.enabled = false; mesh = new List <SkinnedMeshRenderer>(); mesh.AddRange(GetComponentsInChildren <SkinnedMeshRenderer>().OfType <SkinnedMeshRenderer>()); currentState = WeaponStates.Disabled; }
public void ChangeWeaponState(WeaponStates state) { weaponState = state; if (!(WeaponType == WeaponTypes.Bow && state == WeaponStates.StrikeDown)) { currentFrame = 0; } UpdateWeapon(); }
public virtual IEnumerator BulletDelay() { currentState = WeaponStates.Firing; yield return(new WaitForSeconds(1 / bulletsPerSecond)); currentState = WeaponStates.Ready; if (currentAmmo <= 0) { Reload(); } }
public void ChangeWeaponState(WeaponStates state) { weaponState = state; // Only reset frame to 0 for bows if idle state if (WeaponType != WeaponTypes.Bow || state == WeaponStates.Idle) { currentFrame = animTicks = 0; } UpdateWeapon(); }
public void ChangeParent(string state) { if (state == "combat") { current_state = WeaponStates.combat; is_changing = true; CurrentParent = ParentCombat; } else if (state == "idle") { current_state = WeaponStates.idle; is_changing = true; CurrentParent = ParentIdle; } }
// Update is called once per frame public void Update() { switch (WeaponState) { case WeaponStates.IsInCoolDown: { if (_cdTime < 0) { _cdTime = 0; } _cdTime += Time.deltaTime; if (_cdTime > ShootingSpeed) { WeaponState = WeaponStates.IsReadyToShoot; _cdTime = 0; } break; } case WeaponStates.IsReloading: { if (_currentReloadtime < 0) { _currentReloadtime = 0; } _currentReloadtime += Time.deltaTime; if (_currentReloadtime > Reloadtime) { _ammoLeft = MagazineSize; WeaponState = WeaponStates.IsReadyToShoot; _currentReloadtime = 0; } break; } case WeaponStates.NeedsReloading: case WeaponStates.IsReadyToShoot: default: break; } }
IEnumerator StartupRoutine() { weaponState = WeaponStates.PoweringUp; if(hasDeployAnim && deployState) { deployState.enabled = true; deployState.speed = 1; while(deployState.normalizedTime < 1)//wait for animation here { yield return null; } deployState.normalizedTime = 1; deployState.speed = 0; deployState.enabled = false; } weaponState = WeaponStates.Enabled; }
// コルーチンを使用してキャラの動作を行う void Start() { SpriteMat = GetComponent <SpriteRenderer>().material; rigid2d = GetComponent <Rigidbody2D>(); Animations = GetComponent <Animator>(); audioSource = GetComponent <AudioSource>(); weaponStates = GetComponent <WeaponStates>(); PlayerFacing = Vector2.right * Mathf.Sign(transform.localScale.x); layermask = LayerMask.GetMask("LivingThings") + LayerMask.GetMask("Terrain"); WallNearby = (TerrainNearby(PlayerLDEdge, PlayerFacing, layermask, 0.01f)) || (TerrainNearby(PlayerRDEdge, PlayerFacing, layermask)); OnGround = (TerrainNearby(PlayerLDEdge, Vector2.down, layermask)) || (TerrainNearby(PlayerRDEdge, Vector2.down, layermask)); OnBothGround = (TerrainNearby(PlayerLDEdge, Vector2.down, layermask)) && (TerrainNearby(PlayerRDEdge, Vector2.down, layermask)); StartCoroutine("Moving"); StartCoroutine("AnimChange"); }
public virtual IEnumerator ReloadTimings() { yield return(new WaitUntil(() => currentState == WeaponStates.Ready)); if (currentAmmo < maxAmmo && totalAmmo > 0) { currentState = WeaponStates.Reloading; gm.UpdateAmmo(-1); source[1].Play(); yield return(new WaitForSeconds(reloadTime)); //totalAmmo -= maxAmmo - currentAmmo; currentAmmo = maxAmmo; if (totalAmmo < 0) { currentAmmo += totalAmmo; totalAmmo = 0; } currentState = WeaponStates.Ready; gm.UpdateAmmo(currentAmmo); } }
public void Show(Transform attachment = null) { if (attachment == null) { attachment = weaponAttachment; } weaponAttachment = attachment; currentState = WeaponStates.Activating; foreach (SkinnedMeshRenderer item in mesh) { item.enabled = true; } transform.localPosition = Vector3.zero; if (animator == null) { animator = gameObject.AddComponent <Animator>(); animator.runtimeAnimatorController = controller; } animator.enabled = true; animator.SetBool("is_active", true); animator.PlayInFixedTime("Show"); StartCoroutine(WaitAndRun(showWeaponTime, () => { FireEvent.AddListener(OnFire); currentState = WeaponStates.Active; })); }
void OnFire() { timeToFire = 0; playerController.curRotation = playerController.curRotation - curWeaponRecoil * 5; currentState = WeaponStates.Fire; muzzleEnd.Play(); shellPort.Play(); curAmmoClip--; audioSourceFire.Play(); if (hit.collider != null) { GameObject d; int m; try { m = hit.collider.GetComponent <material>().type; } catch { m = 0; } if (!hit.collider.gameObject.CompareTag("Enemy")) { switch (m) { case (0): d = Instantiate(decal0); break; case (1): d = Instantiate(decal1); break; case (2): d = Instantiate(decal2); break; default: d = Instantiate(decal0); break; } } else { d = Instantiate(decal3, hit.collider.GetComponent <Transform>()); if (hit.collider.GetComponent <Rigidbody>() != null) { hit.collider.GetComponent <Rigidbody>().AddForceAtPosition(transform.forward * 25, hit.point); } } d.transform.position = hit.point; d.transform.forward = hit.normal; } if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { try { hit.collider.GetComponentInParent <AIController>().BroadcastMessage("ReceiveDamage", damage); } catch { } } }
// Use this for initialization void Start() { //weaponSettings = GetComponent<WeaponSettings>(); rate = gun.Rate; State = WeaponStates.Hidden; if (damage == 0f) { Debug.LogError("Weapon: " + transform.name + " has 0 damage!"); } damageData = new DamageData(damage); //Load current ammo in the start scene if (!this.ShipSettings.SmallGun.AmmoIsEmpty) { loadShell(this.ShipSettings.SmallGun.CurrentAmmo.Key); } InvokeRepeating("fire", 0f, rate); }
private void UpdateWeapon() { // Do nothing if weapon not ready if (weaponAtlas == null || weaponAnims == null || weaponRects == null || weaponIndices == null) { return; } // Reset state if weapon not visible if (!ShowWeapon) { weaponState = WeaponStates.Idle; return; } // Store rect and anim if (LeftHand && (weaponState == WeaponStates.Idle || weaponState == WeaponStates.StrikeDown || weaponState == WeaponStates.StrikeUp)) { // Mirror weapon rect Rect rect = weaponRects[weaponIndices[(int)weaponState].startIndex + currentFrame]; curAnimRect = new Rect(rect.xMax, rect.yMin, -rect.width, rect.height); } else { curAnimRect = weaponRects[weaponIndices[(int)weaponState].startIndex + currentFrame]; } WeaponAnimation anim = weaponAnims[(int)weaponState]; // Get weapon dimensions int width = weaponIndices[(int)weaponState].width; int height = weaponIndices[(int)weaponState].height; // Get weapon scale weaponScaleX = (float)Screen.width / (float)nativeScreenWidth; weaponScaleY = (float)Screen.height / (float)nativeScreenHeight; // Adjust scale to be slightly larger when not using point filtering // This reduces the effect of filter shrink at edge of display if (dfUnity.MaterialReader.MainFilterMode != FilterMode.Point) { weaponScaleX *= 1.01f; weaponScaleY *= 1.01f; } // Source weapon images are designed to overlay a fixed 320x200 display. // Some weapons need to align with both top, bottom, and right of display. // This means they might be a little stretched on widescreen displays. switch (anim.Alignment) { case WeaponAlignment.Left: AlignLeft(anim, width, height); break; case WeaponAlignment.Center: AlignCenter(anim, width, height); break; case WeaponAlignment.Right: AlignRight(anim, width, height); break; } }
private void UpdateWeapon() { // Do nothing if weapon not ready if (weaponAtlas == null || weaponAnims == null || weaponRects == null || weaponIndices == null) { return; } // Reset state if weapon not visible if (!ShowWeapon || WeaponType == WeaponTypes.None) { weaponState = WeaponStates.Idle; currentFrame = 0; } // Handle bow with no arrows if (!GameManager.Instance.WeaponManager.Sheathed && WeaponType == WeaponTypes.Bow && GameManager.Instance.PlayerEntity.Items.GetItem(Items.ItemGroups.Weapons, (int)Items.Weapons.Arrow) == null) { GameManager.Instance.WeaponManager.SheathWeapons(); DaggerfallUI.SetMidScreenText(UserInterfaceWindows.HardStrings.youHaveNoArrows); } // Store rect and anim int weaponAnimRecordIndex; if (WeaponType == WeaponTypes.Bow) { weaponAnimRecordIndex = 0; // Bow has only 1 animation } else { weaponAnimRecordIndex = (int)weaponState; } try { bool isImported = customTextures.TryGetValue(MaterialReader.MakeTextureKey(0, (byte)weaponState, (byte)currentFrame), out curCustomTexture); if (FlipHorizontal && (weaponState == WeaponStates.Idle || weaponState == WeaponStates.StrikeDown || weaponState == WeaponStates.StrikeUp)) { // Mirror weapon rect if (isImported) { curAnimRect = new Rect(0, 1, -1, 1); } else { Rect rect = weaponRects[weaponIndices[weaponAnimRecordIndex].startIndex + currentFrame]; curAnimRect = new Rect(rect.xMax, rect.yMin, -rect.width, rect.height); } } else { curAnimRect = isImported ? new Rect(0, 0, 1, 1) : weaponRects[weaponIndices[weaponAnimRecordIndex].startIndex + currentFrame]; } WeaponAnimation anim = weaponAnims[(int)weaponState]; // Get weapon dimensions int width = weaponIndices[weaponAnimRecordIndex].width; int height = weaponIndices[weaponAnimRecordIndex].height; // Get weapon scale weaponScaleX = (float)Screen.width / (float)nativeScreenWidth; weaponScaleY = (float)Screen.height / (float)nativeScreenHeight; // Adjust scale to be slightly larger when not using point filtering // This reduces the effect of filter shrink at edge of display if (dfUnity.MaterialReader.MainFilterMode != FilterMode.Point) { weaponScaleX *= 1.01f; weaponScaleY *= 1.01f; } // Source weapon images are designed to overlay a fixed 320x200 display. // Some weapons need to align with both top, bottom, and right of display. // This means they might be a little stretched on widescreen displays. switch (anim.Alignment) { case WeaponAlignment.Left: AlignLeft(anim, width, height); break; case WeaponAlignment.Center: AlignCenter(anim, width, height); break; case WeaponAlignment.Right: AlignRight(anim, width, height); break; } } catch (IndexOutOfRangeException) { DaggerfallUnity.LogMessage("Index out of range exception for weapon animation. Probably due to weapon breaking + being unequipped during animation."); } }
IEnumerator ShutdownRoutine() { weaponState = WeaponStates.PoweringDown; if(turret) { while(!turret.ReturnTurret()) //wait till turret has returned { yield return null; } } if(hasDeployAnim) { deployState.enabled = true; deployState.speed = -1; while(deployState.normalizedTime > 0) { yield return null; } deployState.normalizedTime = 0; deployState.speed = 0; deployState.enabled = false; } weaponState = WeaponStates.Disabled; }
public void EnableWeapon() { if (deployLocked) { weaponState = WeaponStates.Disabled; return; } if(weaponState == WeaponStates.Enabled || weaponState == WeaponStates.PoweringUp) { return; } if(weaponState == WeaponStates.PoweringDown) { StopCoroutine("ShutdownRoutine"); } StartCoroutine("StartupRoutine"); }
void Start() { State = WeaponStates.Hidden; if (damage == 0f) { Debug.LogError("Weapon: " + transform.name + " has 0 damage!"); } damageData = new DamageData(damage); }
// Use this for initialization public void Start() { _ammoLeft = MagazineSize; WeaponState = WeaponStates.IsReadyToShoot; }
void Update() { //Debug.Log(transform.localPosition); if (Time.timeScale == 0 || weaponAttachment == null) { return; } if (playerController == null) { playerController = GetComponentInParent <PlayerController>(); } if (currentState == WeaponStates.Disabled) { return; } WeaponSway(); if (playerController.isAiming && !playerController.isReloading) { weaponAttachment.localPosition = Vector3.Lerp(weaponAttachment.localPosition, aimPosition, 0.2F); curWeaponSlide = weaponSlide / 2; } else { weaponAttachment.localPosition = Vector3.Lerp(weaponAttachment.localPosition, weaponPosition + offset, 2.5F * Time.deltaTime); curWeaponSlide = weaponSlide; } if (weaponOffset > 0) { weaponOffset = Mathf.Lerp(weaponOffset, 0, 0.1F); } if ((curAmmoClip == 0) && (ammoAmount > 0 && curAmmoClip < ammoClip && currentState == WeaponStates.Active)) { Reload(); } targetVectorOffset = Mathf.Abs(playerController.WalkOffset) + Mathf.Abs(weaponOffset); if (!playerController.isAiming) { UIray = new Ray(MuzzleEndTarget.position, Camera.main.transform.forward); ray = new Ray(MuzzleEndTarget.position, Camera.main.transform.forward + new Vector3((UnityEngine.Random.value - 0.5F) * 2, (UnityEngine.Random.value - 0.5F) * 2, 0) * targetVectorOffset); curWeaponRecoil = weaponRecoil; } else { UIray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward + new Vector3((UnityEngine.Random.value - 0.5F) * 2, (UnityEngine.Random.value - 0.5F) * 2, 0) * targetVectorOffset); curWeaponRecoil = weaponRecoil / 5; } Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask); timeToFire += Time.deltaTime; animator.SetBool("is_reloading", playerController.isReloading); animator.SetBool("is_aiming", playerController.isAiming); animator.SetFloat("speed", playerController.animationSpeed); if (currentState == WeaponStates.Fire) { animator.SetBool("is_firing", true); weaponOffset += curWeaponRecoil; } else { animator.SetBool("is_firing", false); } if (!playerController.isReloading) { StopCoroutine("Reload"); } if (timeToFire <= rateOfFire) { if (currentState == WeaponStates.Fire) { currentState = WeaponStates.Active; } } }
IEnumerator ShutdownRoutine() { weaponState = WeaponStates.PoweringDown; if(turret) { while(!turret.ReturnTurret()) //wait till turret has returned { yield return null; } } if(hasDeployAnim) { deployState.enabled = true; deployState.speed = -1; while(deployState.normalizedTime > 0) { yield return null; } deployState.normalizedTime = 0; deployState.speed = 0; deployState.enabled = false; } weaponState = WeaponStates.Disabled; HitManager.FireTurretDeployHooks(false, vessel.id, part.craftID); deployLocked = false; }
IEnumerator StartupRoutine() { weaponState = WeaponStates.PoweringUp; UpdateGUIWeaponState(); if(hasDeployAnim && deployState) { deployState.enabled = true; deployState.speed = 1; while(deployState.normalizedTime < 1)//wait for animation here { yield return null; } deployState.normalizedTime = 1; deployState.speed = 0; deployState.enabled = false; } weaponState = WeaponStates.Enabled; UpdateGUIWeaponState(); BDArmorySettings.Instance.UpdateCursorState(); }
private void UpdateWeapon() { // Do nothing if weapon not ready if (weaponAtlas == null || weaponAnims == null || weaponRects == null || weaponIndices == null) return; // Reset state if weapon not visible if (!ShowWeapon) { weaponState = WeaponStates.Idle; return; } // Store rect and anim if (LeftHand && (weaponState == WeaponStates.Idle || weaponState == WeaponStates.StrikeDown || weaponState == WeaponStates.StrikeUp)) { // Mirror weapon rect Rect rect = weaponRects[weaponIndices[(int)weaponState].startIndex + currentFrame]; curAnimRect = new Rect(rect.xMax, rect.yMin, -rect.width, rect.height); } else { curAnimRect = weaponRects[weaponIndices[(int)weaponState].startIndex + currentFrame]; } WeaponAnimation anim = weaponAnims[(int)weaponState]; // Get weapon dimensions int width = weaponIndices[(int)weaponState].width; int height = weaponIndices[(int)weaponState].height; // Get weapon scale weaponScaleX = (float)Screen.width / (float)nativeScreenWidth; weaponScaleY = (float)Screen.height / (float)nativeScreenHeight; // Adjust scale to be slightly larger when not using point filtering // This reduces the effect of filter shrink at edge of display if (dfUnity.MaterialReader.MainFilterMode != FilterMode.Point) { weaponScaleX *= 1.01f; weaponScaleY *= 1.01f; } // Source weapon images are designed to overlay a fixed 320x200 display. // Some weapons need to align with both top, bottom, and right of display. // This means they might be a little stretched on widescreen displays. switch (anim.Alignment) { case WeaponAlignment.Left: AlignLeft(anim, width, height); break; case WeaponAlignment.Center: AlignCenter(anim, width, height); break; case WeaponAlignment.Right: AlignRight(anim, width, height); break; } }
public void ChangeWeaponState(WeaponStates state) { weaponState = state; currentFrame = 0; UpdateWeapon(); }
public void EnableWeapon() { if (deployLocked) { weaponState = WeaponStates.Disabled; return; } if (weaponState == WeaponStates.Enabled || weaponState == WeaponStates.PoweringUp) { return; } StopShutdownStartupRoutines(); startupRoutine = StartCoroutine(StartupRoutine()); }
public virtual void Reload() { WeaponState = WeaponStates.IsReloading; }
IEnumerator ShutdownRoutine() { weaponState = WeaponStates.PoweringDown; UpdateGUIWeaponState(); BDArmorySettings.Instance.UpdateCursorState(); if(turret) { yield return new WaitForSeconds(0.2f); while(!turret.ReturnTurret()) //wait till turret has returned { yield return new WaitForFixedUpdate(); } } if(hasDeployAnim) { deployState.enabled = true; deployState.speed = -1; while(deployState.normalizedTime > 0) { yield return null; } deployState.normalizedTime = 0; deployState.speed = 0; deployState.enabled = false; } weaponState = WeaponStates.Disabled; UpdateGUIWeaponState(); }
IEnumerator StartupRoutine() { weaponState = WeaponStates.PoweringUp; if(hasDeployAnim && deployState) { deployState.enabled = true; deployState.speed = 1; while(deployState.normalizedTime < 1)//wait for animation here { yield return null; } deployState.normalizedTime = 1; deployState.speed = 0; deployState.enabled = false; } weaponState = WeaponStates.Enabled; HitManager.FireTurretDeployHooks(true, vessel.id, part.craftID); }