123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using Adon.Game.BO;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace AdonGameKit
- {
- /// <summary>
- /// 言灵星空法阵子弹
- /// </summary>
- public class YLStarrySkyAdon : MonoBehaviour
- {
- /// <summary>
- /// 步进速度
- /// </summary>
- public float velocity = 30f;
- /// <summary>
- /// 最小距离
- /// </summary>
- public float minDistance = 0.1f;
- /// <summary>
- /// 生命周期
- /// </summary>
- public float lifeTime = 5f;
- /// <summary>
- /// 是否延迟销毁
- /// </summary>
- public bool DelayDespawn = false;
- /// <summary>
- /// 粒子消退延迟时间
- /// </summary>
- 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;//子弹粒子系统数组
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="_YL">释放者挂件(言灵)</param>
- /// <param name="_hero">释放者(英雄)</param>
- /// <param name="_TargetPoint">目标点</param>
- /// <param name="_CurUseSkill">当前技能ID</param>
- 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<ParticleSystem>();
- }
- // 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<DestroyObjectDelayed>()) effobj.gameObject.AddComponent<DestroyObjectDelayed>();//添加延迟销毁脚本
- effobj.position = m_TargetPoint;//设置爆炸位置
- //设置言灵爆炸脚本
- YLStarrySkyBomb skyBomb = effobj.gameObject.AddComponent<YLStarrySkyBomb>();
- 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;
- }
- /// <summary>
- /// 子弹销毁
- /// </summary>
- void OnProjectileDestroy()
- {
- //销毁,后期改为对象池
- Destroy(this.gameObject);
-
- }
- /// <summary>
- /// 停止粒子释放并逐渐消逝
- /// </summary>
- void Delay()
- {
- if (particles.Length > 0)
- {
- for (int i = 0; i < particles.Length; i++)
- {
- particles[i].Stop(false);
- }
- }
- }
- }
- }
|