using System.Collections.Generic; using Core.Audio; using Core.Triiger; using GameLogic.Combat.CombatTool; using GameLogic.Combat.Hero; using GameLogic.Combat.Skill; using UnityEngine; using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface; namespace Common.Combat.FxAILogic { [AddComponentMenu("特效脚本/弹道/功法通用弹道")] public class FxParabolaBulletLogic : FxAILogicBasic { public float speed; private IUnRegister UnRegister = null; [Header("释放碰撞到地面时结束")] public bool isTriggerGroundEnd; [Header("碰撞到地面时的特效")] public string GroundHitFxName; private Vector3 endPos; private Vector3 dir; public float maxDis = 20; protected float maxDisSpr; // private BesselPath _besselPath; private float _addTime; protected Vector3 startDir; private float dirLerpTime; protected override void ProInit() { maxDisSpr = maxDis * maxDis; UnRegister = gameObject.OnTriggerEnterEvent(this, OnTriggerEnterEvent); if (isUseCustomTargetEndPos) { endPos = TimeLineEventParticleLogicBasic.customizePos[ customTargetEndPosIndex]; } else { endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos(); // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z); } Vector3 off = _currPos - CombatHeroEntity.GameObject.transform.position; startDir = CombatHeroEntity.GameObject.transform.TransformPoint(off + new Vector3( Mathf.Sign(Random.Range(-1, 1)), Random.Range(0.1f, 1f), Random.Range(0.1f, 5f))); startDir = (startDir - _currPos).normalized; dirLerpTime = 0; dir = (endPos - CurrPos).normalized; gameObject.transform.rotation = Quaternion.LookRotation(dir); } void TriggerGround() { ITimeLineTriggerEvent timeLineTriggerEvent = TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent; FinishHit(new Vector3(_currPos.x, 0.5f, _currPos.z), GroundHitFxName); AudioManager.Instance.PlayAudio(hitAudioName, false); if (timeLineTriggerEvent != null) { timeLineTriggerEvent.TimeLineTriggerGround( TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName, this, triggerData); } AudioManager.Instance.PlayAudio(hitAudioName, false); Dispose(); } protected void GetTargetPos() { if (isUseCustomTargetEndPos) { endPos = TimeLineEventParticleLogicBasic.customizePos[ customTargetEndPosIndex]; } else { endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos(); // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z); } } protected void OnTriggerEnterEvent(Collider collision, ITriggerEntity triggerEntity) { if (isTriggerGroundEnd) { if (collision.gameObject.CompareTag("dimian")) { TriggerGround(); return; } } FxAILogicBasic fxAILogicBasic = triggerEntity as FxAILogicBasic; if (fxAILogicBasic != null) //击中其他的功法 { SkillFeaturesData skillFeaturesData = fxAILogicBasic.SkillFeaturesData; if (skillFeaturesData.isEnemy == SkillFeaturesData.isEnemy) { return; } int myRestrained = SkillFeaturesData.GetRestrained(skillFeaturesData.SkillFeaturesType); int targetRestrained = skillFeaturesData.GetRestrained(SkillFeaturesData.SkillFeaturesType); int c = myRestrained - targetRestrained; int myHp = SkillFeaturesData.hp; int targetHp = skillFeaturesData.hp; if (c < 0) //我被压制 { myHp -= CombatCalculateTool.Instance.GetVlaueRatioForInt(myHp, 10 * (Mathf.Abs(c))); } else if (c > 0) { targetHp -= CombatCalculateTool.Instance.GetVlaueRatioForInt(targetHp, 10 * (Mathf.Abs(c))); } if (myHp > targetHp) { myHp -= targetHp; SkillFeaturesData.hp = myHp; fxAILogicBasic.PlayHit(); fxAILogicBasic.Dispose(); } else if (myHp < targetHp) { targetHp -= myHp; skillFeaturesData.hp = targetHp; Dispose(); PlayHit(); } else if (myHp == targetHp) { myHp = 0; fxAILogicBasic.PlayHit(); fxAILogicBasic.Dispose(); Dispose(); PlayHit(); } return; } else { HeroEntityMono heroEntityMono = collision.gameObject.GetComponent(); TriggerHero(collision, heroEntityMono); } } protected void TriggerHero(Collider collision, HeroEntityMono heroEntityMono) { if (heroEntityMono == null) { return; } CombatHeroEntity target = heroEntityMono.combatHeroEntity; if (target.IsEnemy == CombatHeroEntity.IsEnemy||target is CombatMagicWeaponEntity) { return; } if (TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName == null) { Dispose(); return; } ITimeLineTriggerEvent timeLineTriggerEvent = TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent; if (timeLineTriggerEvent != null) { timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName, target.GetMainHotPoin(), this, triggerData); if (!string.IsNullOrEmpty(hitFxName)) { FinishHit(collision.ClosestPoint(gameObject.transform.position), hitFxName); } AudioManager.Instance.PlayAudio(hitAudioName, false); if (!isPenetrate) { Dispose(); } } } private void FinishHit(Vector3 pos, string hitFxName) { if (!string.IsNullOrEmpty(hitFxName)) { CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName, pos, null, false, null, null); } } protected override void ProCombatUpdate(float time) { currTime += _addTime * time; dirLerpTime += time * 4F; if (dirLerpTime > 1) { dirLerpTime = 1; } GetTargetPos(); Vector3 dir = (endPos - _currPos).normalized; dir = Vector3.Lerp(startDir, dir, dirLerpTime).normalized; // startDir= dir; Vector3 lasetPos = _currPos; _currPos += dir * speed * time; gameObject.transform.position = _currPos; gameObject.transform.rotation = Quaternion.LookRotation(dir); // if (Vector3.Distance(endPos, _currPos) < 0.5f) // { // Dispose(); // } } protected override void ProDispose() { if (UnRegister != null) { UnRegister.UnRegister(); } UnRegister = null; } } }