using Adon.Game.BO; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace AdonGameKit { /// /// 言灵星空法阵子弹 /// public class YLStarrySkyAdon : MonoBehaviour { /// /// 步进速度 /// public float velocity = 30f; /// /// 最小距离 /// public float minDistance = 0.1f; /// /// 生命周期 /// public float lifeTime = 5f; /// /// 是否延迟销毁 /// public bool DelayDespawn = false; /// /// 粒子消退延迟时间 /// public float despawnDelay; [SerializeField] private BaseYLPartAdon m_YL;//释放者挂件(言灵) [SerializeField] private BaseHero m_Hero;//释放者(英雄) bool isEeach = false;//到达目标位置 bool isFXSpawned = false; // 爆炸光效只生产一次 [SerializeField] private Vector3 m_TargetPoint; //目标点 [SerializeField] private string m_CurUseSkill;//当前技能ID Vector3 startPoint;//开始的点 float timer = 0f; // 子弹生命周期计时 ParticleSystem[] particles;//子弹粒子系统数组 /// /// 初始化 /// /// 释放者挂件(言灵) /// 释放者(英雄) /// 目标点 /// 当前技能ID public void init(BaseYLPartAdon _YL, BaseHero _hero, Vector3 _TargetPoint, string _CurUseSkill) { m_YL = _YL; m_Hero = _hero; m_TargetPoint = _TargetPoint; m_CurUseSkill = _CurUseSkill; } void Awake() { particles = GetComponentsInChildren(); } // Start is called before the first frame update void Start() { startPoint = transform.position; } void FixedUpdate() { if (isEeach)//如果到达目标位置 { if (!isFXSpawned)//只执行一次爆炸生产 { //实例化克隆爆炸光效 Transform effobj = Instantiate(m_YL.m_FxManagerAdon.m_BombEff[0]); if (!effobj.GetComponent()) effobj.gameObject.AddComponent();//添加延迟销毁脚本 effobj.position = m_TargetPoint;//设置爆炸位置 //设置言灵爆炸脚本 YLStarrySkyBomb skyBomb = effobj.gameObject.AddComponent(); skyBomb.init(m_YL,m_Hero, m_YL.m_FxManagerAdon.m_AttackedEff[0], m_CurUseSkill); effobj.gameObject.SetActive(true); isFXSpawned = true; } // 不延迟则销毁 if (!DelayDespawn || (DelayDespawn && (timer >= despawnDelay))) OnProjectileDestroy();//销毁 } else { Vector3 step = transform.forward * Time.deltaTime * velocity;//子弹步进 transform.position += step;//向前步进 // 如果到达目标位置,计算与目标对距离 float distance = Vector3.Distance(startPoint, m_TargetPoint);//到达目标的距离 float distance2 = Vector3.Distance(startPoint, transform.position); if (distance2 >= distance) { isEeach = true; if (DelayDespawn)//延迟重试 { timer = 0f; Delay();//碰撞后粒子延迟消逝 } } else { // 生命周期到了则销毁 if (timer >= lifeTime) OnProjectileDestroy(); } } // Updates projectile timer timer += Time.deltaTime; } /// /// 子弹销毁 /// void OnProjectileDestroy() { //销毁,后期改为对象池 Destroy(this.gameObject); } /// /// 停止粒子释放并逐渐消逝 /// void Delay() { if (particles.Length > 0) { for (int i = 0; i < particles.Length; i++) { particles[i].Stop(false); } } } } }