123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using Adon.Game.BO;
- using Adon.Game.Helper;
- using DG.Tweening;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace AdonGameKit
- {
- /// <summary>
- /// 言灵 抛物线子弹
- /// </summary>
- public class YLParabolicBulletAdon : MonoBehaviour
- {
- /// <summary>
- /// 子弹步进速度
- /// </summary>
- public float velocity = 30;
- /// <summary>
- /// 推进倍增值
- /// </summary>
- public float RaycastAdvance = 2f;
- /// <summary>
- /// 射线碰撞层
- /// </summary>
- public int curLayerMask = 0;
- /// <summary>
- /// 生命周期
- /// </summary>
- public float lifeTime = 5f;
- /// <summary>
- /// 是否延迟销毁
- /// </summary>
- public bool DelayDespawn = false;
- /// <summary>
- /// 粒子消退延迟时间
- /// </summary>
- public float despawnDelay = 0;
- public BaseYLPartAdon m_YL;//释放者挂件(言灵)
- public BaseHero m_Hero;//释放者(英雄)
- public string m_CurUseSkill;
- public Transform m_HitEff;
- /// <summary>
- /// 抛物完成回掉
- /// </summary>
- public Action<GameObject> m_OnComplete;
- bool isHit = false;
- bool isFXSpawned = false; // 碰撞光效只生产一次
- RaycastHit hitPoint; //碰撞点
- float timer = 0f; // 子弹生命周期计时
- ParticleSystem[] particles;//子弹粒子系统数组
- Sequence seq;
- Vector3 m_targetPot;
- void Awake()
- {
- curLayerMask = LayerMask.NameToLayer("Enemy");
- particles = GetComponentsInChildren<ParticleSystem>();
- seq = DOTween.Sequence();
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- void FixedUpdate()
- {
- if (isHit)//如果有碰撞
- {
- if (!isFXSpawned)//执行一次
- {
- isFXSpawned = true;
- BaseMonsterAdon component = hitPoint.transform.GetComponent<BaseMonsterAdon>();
- if (component != null)
- {
- //实例化克隆爆炸光效
- Transform effobj = Instantiate(m_HitEff);
- if (!effobj.GetComponent<DestroyObjectDelayed>()) effobj.gameObject.AddComponent<DestroyObjectDelayed>();//添加延迟销毁脚本
- effobj.position = new Vector3(hitPoint.point.x, component.transform.position.y, hitPoint.point.z);//设置爆炸位置
- effobj.gameObject.SetActive(true);
- if (m_OnComplete != null) m_OnComplete(effobj.gameObject);//抛物线完成回调
- //发送伤害消息
- //X2Battle.X2BattleManager.Instance.mBulletModel.OnCastSkill(
- // m_Hero.mData.UID, m_CurUseSkill,
- // false, m_YL.M_YLType, component.mData.UID, false);
- BulletMessage.catSkillFun(m_Hero.mData.UID, m_CurUseSkill,
- false, (int)m_YL.M_YLType, component.mData.UID, false);
- }
- }
- // 不延迟则销毁
- if (!DelayDespawn || (DelayDespawn && (timer >= despawnDelay)))
- OnProjectileDestroy();//销毁
- }
- else
- {
- Vector3 step = transform.forward * Time.deltaTime * velocity;//子弹步进
- // 如果射线碰撞
- if (Physics.Raycast(transform.position, transform.forward, out hitPoint, step.magnitude * RaycastAdvance, 1 << curLayerMask))
- {
- isHit = 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);
- }
- }
- }
-
- public void ParabolicDoTween(Vector3 targetPot)
- {
- m_targetPot = targetPot;
- var ParabolicDis = Vector3.Distance(targetPot, this.transform.position);
- var ParabolicDown = targetPot.y;
- var speed = 5.0f;
- var time = ParabolicDis / speed;
- seq.Append(this.transform.DOMove(targetPot, time).SetEase(Ease.Linear));
- //seq.Append(this.transform.DOMoveZ(targetPot.z, time / 2).SetEase(Ease.Unset));
- seq.Insert(0, this.transform.DOMoveY(targetPot.y + 3, time * 0.5f).SetEase(Ease.OutCirc));
- seq.Insert(time * 0.5f, this.transform.DOMoveY(ParabolicDown, time * 0.5f).SetEase(Ease.InCirc));
- seq.OnComplete<Sequence>(() => { OnDoTweenComplete(); });
- }
-
-
- public void OnDoTweenComplete()
- {
- Debug.Log("抛物线完成!");
- //实例化克隆爆炸光效
- Transform effobj = Instantiate(m_HitEff);
- if (!effobj.GetComponent<DestroyObjectDelayed>()) effobj.gameObject.AddComponent<DestroyObjectDelayed>();//添加延迟销毁脚本
- effobj.position = m_targetPot;//设置爆炸位置
- effobj.gameObject.SetActive(true);
- if (m_OnComplete != null) m_OnComplete(effobj.gameObject);
- Destroy(this.gameObject);
- }
- }
- }
|