using UnityEngine; using System.Collections; using System.Collections.Generic; public class ShotManager : MonoBehaviour { public Transform[] attackTransArr; public GameObject[] attackMuzzleArr; public ParticleSystem[] attackShellArr; public int attackShotCount; public float[] attackShotTimeArr; public float attackShotTime; public float attackMuzzleDuration = 0.05f; public float attackSoundDuration = float.MaxValue; public Animator attackAnimator; public Transform[] powerTransArr; public GameObject[] powerMuzzleArr; public ParticleSystem[] powerShellArr; public int powerShotCount; public float[] powerShotTimeArr; public float powerShotTime; public float powerMuzzleDuration = 0.05f; public float powerSoundDuration = float.MaxValue; public Animator powerAnimator; private List list = new List(); private bool hasMuzzle = true; void Awake() { if(attackAnimator != null) attackAnimator.gameObject.SetActive(false); if(powerAnimator != null) powerAnimator.gameObject.SetActive(false); } public void Fire(Power power, List bulletList) { if (bulletList.Count > 0 && power.GetOwner() is Craft && power.GetId () == power.GetOwner ().GetPowerManager ().GetAttack ().GetId ()) { UAVehicle uav = (power.GetOwner () as Craft).GetUAV (); if(uav != null) { Bullet bullet = bulletList [0]; uav.Attack (bullet.GetTarget() as Craft); } } for(int i=0; i=0; i--) { Bullet bullet = list[i]; bool isAttack = bullet.GetPower().isAttack; float lastShotTime = bullet.GetPower().isAttack ? attackShotTime : powerShotTime; float interval = bullet.GetPower().GetButtetsInterval(); if(GameTime.time >= lastShotTime + interval) { Launch(bullet); list.RemoveAt(i); } } } private void Launch(Bullet bullet) { Vector3 position = new Vector3(); bool isAttack = bullet.GetPower().isAttack; Transform[] transArr = isAttack ? attackTransArr : powerTransArr; GameObject[] muzzleArr = isAttack ? attackMuzzleArr : powerMuzzleArr; ParticleSystem[] shellArr = isAttack ? attackShellArr : powerShellArr; float[] shotArr = isAttack ? attackShotTimeArr : powerShotTimeArr; int shotCount = isAttack ? attackShotCount : powerShotCount; float soundDuration = isAttack ? attackSoundDuration : powerSoundDuration; Animator animator = isAttack ? attackAnimator : powerAnimator; Transform shotTrans = null; if(transArr.Length > 0) { int index = shotCount % transArr.Length; shotTrans = transArr[index]; position = transArr[index].position; if(index < muzzleArr.Length && muzzleArr[index] != null) { muzzleArr[index].SetActive(true); shotArr[index] = GameTime.time; } if(index < shellArr.Length && shellArr[index] != null) { shellArr[index].Emit(1); } hasMuzzle = true; } else { position = this.transform.position; position.y = 1.5f; } if(animator != null) { animator.gameObject.SetActive(true); animator.Play(0, 0, 0); } if(isAttack) { attackShotTime = GameTime.time; attackShotCount++; } else { powerShotTime = GameTime.time; powerShotCount++; } bullet.gameObject.SetActive(true); bullet.transform.position = position; bullet.InitRotation(); bullet.shotTrans = shotTrans; bullet.GetPower().PlaySound(soundDuration); } private void CheckMuzzle() { if(!hasMuzzle) return; bool found = false; for(int i=0; i= attackMuzzleDuration) { muzzle.SetActive(false); } else { found = true; } } } for(int i=0; i= powerMuzzleDuration) { muzzle.SetActive(false); } else { found = true; } } } if(!found) hasMuzzle = false; } }