123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using Adon.Game.BO;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace AdonGameKit
- {
- /// <summary>
- /// 言灵法阵
- /// </summary>
- public class YLMagicCircleAdon : 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;
- public BaseYLPartAdon m_YL;//释放者挂件(言灵)
- public BaseHero m_Hero;//释放者(英雄)
- bool isEeach = false;//到达目标位置
- bool isFXSpawned = false; // 爆炸光效只生产一次
- public Vector3 m_TargetPoint; //目标点
- public string m_CurUseSkill;
- Vector3 startPoint;//开始的点
- float timer = 0f; // 子弹生命周期计时
- ParticleSystem[] particles;//子弹粒子系统数组
- void Awake()
- {
- particles = GetComponentsInChildren<ParticleSystem>();
- }
- // Start is called before the first frame update
- void Start()
- {
- startPoint = transform.position;
- }
- void FixedUpdate()
- {
- if (isEeach)//如果到达目标位置
- {
- if (!isFXSpawned)//只执行一次爆炸生产
- {
- isFXSpawned = true;
- //实例化克隆爆炸光效
- Transform effobj = Instantiate(m_YL.m_FxManagerAdon.m_BombEff[0]);
- if (!effobj.GetComponent<DestroyObjectDelayed>()) effobj.gameObject.AddComponent<DestroyObjectDelayed>();//添加延迟销毁脚本
- effobj.position = m_TargetPoint;//设置爆炸位置
- //设置言灵爆炸脚本
- YLMagicCircleBomb bomb = effobj.gameObject.AddComponent<YLMagicCircleBomb>();
- bomb.SetHero(m_Hero);
- bomb.SetBombEff(m_YL.m_FxManagerAdon.m_AttackedEff[0]);
- bomb.m_CurUseSkill = m_CurUseSkill;
- bomb.m_YL = m_YL;
- effobj.gameObject.SetActive(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);
- }
- }
- }
- }
- }
|