/// <summary> /// 播放子弹 /// </summary> /// <param name="part"></param> /// <param name="target"></param> /// <param name="delayFrame"></param> private void ShowBullet(ClientParts clientPart, List <BulletTarget> targetList, SpellType spellType, string attackPoint, string bulletPath, Effect hurtEffect, Vector3 position, ClientSkill skill = null) { Transform attackTransRoot = GetTransformByName(attackPoint); foreach (Transform attackTrans in attackTransRoot) { BulletDisplay.ShowBullet(attackTrans.position.x, attackTrans, targetList, clientPart, spellType, bulletPath, hurtEffect, position, skill); } }
private static BulletDisplay InitBullet(Transform attackTrans, ShipDisplay targetShip, Transform targetTrans, SpellType spellType, string bulletPath, Effect hurtEffect) { GameObject bullet = AssetLoader.PlayEffect(bulletPath); if (bullet == null) { Debug.Log("can not find bullet:" + bulletPath); bullet = new GameObject(); //return null; } bullet.name = spellType.ToString(); bullet.transform.position = attackTrans.position; bullet.transform.rotation = attackTrans.rotation; BulletDisplay display = bullet.GetComponent <BulletDisplay>(); if (display == null) { display = bullet.AddComponent <BulletDisplay>(); } display.SetCache(attackTrans, targetShip, targetTrans, spellType, bulletPath, hurtEffect); return(display); }
// Update is called once per frame void Update() { chargeTime = Mathf.Clamp(chargeTime - Time.deltaTime, 0, gun.chargeTime); if (chargeTime <= 0 && Input.GetButton("Fire1")) { for (int i = 0; i < gun.shotAmount; i++) { GameObject bulletClone = new GameObject("bullet"); BulletDisplay bd = bulletClone.AddComponent <BulletDisplay>(); bd.bullet = bullet; bulletClone.AddComponent <BulletPhysics>(); bulletClone.transform.position = bulletPoint.position; Vector3 bulletRotation = gunPos.eulerAngles; bulletRotation.z += Random.Range(gun.minDeviation, gun.maxDeviation); bulletClone.transform.eulerAngles = bulletRotation; bulletClone.transform.localScale = new Vector3(bullet.scaleX, bullet.scaleY, bullet.scaleZ); Rigidbody2D rb = bulletClone.AddComponent <Rigidbody2D>(); rb.AddForce(bulletClone.transform.right * gun.bulletForce, ForceMode2D.Impulse); chargeTime = gun.chargeTime; } AudioManager.PlaySound("gunshot"); } }
/// <summary> /// 子弹 /// </summary> /// <param name="attackShipTrans"></param> /// <param name="attackPartTrans"></param> /// <param name="target"></param> /// <param name="attackPart"></param> /// <param name="part"></param> /// <param name="delayTime"></param> public static void ShowBullet(float srcX, Transform attackPartTrans, List <BulletTarget> targetList, ClientParts attackPart, SpellType spellType, string bulletPath, Effect hurtEffect, Vector3 position, ClientSkill skill) { // 范围攻击特殊处理 if (spellType == SpellType.AOE) { BulletDisplay display = InitBullet(attackPartTrans, null, null, spellType, bulletPath, hurtEffect); if (display == null) { return; } display.SetAOE(targetList, position, skill); return; } // 其他攻击,一个子弹只对应一个目标 if (targetList.Count != 1) { return; } if (targetList[0].Target == null) { return; } ShipDisplay targetShip = targetList[0].Target.GetHurtShip(); if (targetShip == null) { return; } float delayTime = FightServiceDef.FRAME_INTERVAL_TIME_F * targetList[0].delayFrame; Transform targetTrans = targetShip.GetTransformByName(targetShip.GetHitPoint(srcX, spellType)); if (targetTrans == null) { targetTrans = targetShip.Trans; } // 导弹特殊处理,从左右发子弹 if (spellType == SpellType.Missile) { // TODO: 临时增加逻辑,防御节点一边扔3颗导弹 // 后面要考虑走配置 int missileCout = 1; if (attackPart.Owner.Reference.unitstrait == Def.ShipTrait.DefenseBuild) { missileCout = 3; } for (int i = 0; i < missileCout; i++) { BulletDisplay display = InitBullet(attackPartTrans, targetShip, targetTrans, spellType, bulletPath, hurtEffect); if (display == null) { return; } display.SetMissile(attackPartTrans.name.Contains("left"), delayTime); } } // 机枪特殊处理,做成扫射效果 else if (spellType == SpellType.MachineGun) { for (int i = 0; i < attackPart.Reference.continuity_times; i++) { BulletDisplay display = InitBullet(attackPartTrans, targetShip, targetTrans, spellType, bulletPath, hurtEffect); display.SetGun(delayTime, (float)attackPart.Reference.continuity_interval / 1000f * i); } } else { BulletDisplay display = InitBullet(attackPartTrans, targetShip, targetTrans, spellType, bulletPath, hurtEffect); display.SetLaserOrConnon(delayTime); } }