123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- using System.Collections.Generic;
- using Core.Audio;
- using Core.Triiger;
- using Core.Utility;
- using GameLogic.Combat.CombatTool;
- using GameLogic.Combat.Hero;
- using GameLogic.Combat.Skill;
- using UnityEditor;
- using UnityEngine;
- using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
- namespace Common.Combat.FxAILogic
- {
- [AddComponentMenu("特效脚本/弹道/功法通用弹道")]
- public class FxParabolaBulletLogic : FxAILogicBasic
- {
- public float speed;
- private IUnRegister UnRegister = null;
- public enum CurveType
- {
- DynamicCurve,
- Beeline,
- CustomizeCurve,
- }
- [Header("曲线类型")] public CurveType parabolaCurveType;
- [Header("释放碰撞到地面时结束")] public bool isTriggerGroundEnd;
- [Header("碰撞到地面时的特效")] public string GroundHitFxName;
- [Header("是否使用X曲线跟随角色")] public bool isUseX;
- [Header("自定义曲线")] public BesselPath BesselPath;
- private Vector3 endPos;
- private Vector3 dir;
- public float maxDis = 20;
- protected float maxDisSpr;
- // private BesselPath _besselPath;
- protected BesselPath moveBezierPath;
- 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);
- }
- if (parabolaCurveType == CurveType.DynamicCurve)
- {
- Vector3 off = _currPos - CombatHeroEntity.GameObject.transform.position;
- float x = Mathf.Sign(Random.Range(-1, 1));
- if (isUseX)
- {
- Vector3 pos =
- CombatHeroEntity.GameObject.transform.InverseTransformPoint(gameObject.transform.position);
- x = Mathf.Sign(pos.x);
- }
- startDir = CombatHeroEntity.GameObject.transform.TransformPoint(off +
- new Vector3(
- x,
- 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);
- }
- else if (parabolaCurveType == CurveType.Beeline)
- {
- dir = (endPos - _currPos).normalized;
- gameObject.transform.rotation = Quaternion.LookRotation(dir);
- }
- else if (parabolaCurveType == CurveType.CustomizeCurve)
- {
- gameObject.transform.rotation = CombatHeroEntity.GameObject.transform.rotation;
- Vector3 pos =
- CombatHeroEntity.GameObject.transform.InverseTransformPoint(gameObject.transform.position);
- if (moveBezierPath == null)
- {
- moveBezierPath = new BesselPath();
- }
- moveBezierPath.controlPoints.Clear();
- for (int i = 0; i < BesselPath.controlPoints.Count; i++)
- {
- Vector3 p = BesselPath.controlPoints[i];
- if (isUseX)
- {
- if (i == 1)
- {
- p.x = pos.x > 0 ? p.x * -1 : p.x;
- }
- }
- moveBezierPath.controlPoints.Add(gameObject.transform.TransformPoint(p / (size * size)));
- }
- _addTime = 1.0f / (moveBezierPath.GetLengthAtT(0) / speed);
- currTime = 0;
- }
- }
- 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;
- }
- CombatCalculateTool.Instance.GongFaPengZhuang(SkillFeaturesData, skillFeaturesData, CombatHeroEntity,
- fxAILogicBasic.CombatHeroEntity);
- if (SkillFeaturesData.hp > 0)
- {
- fxAILogicBasic.PlayHit();
- fxAILogicBasic.Dispose();
- }
- else if (skillFeaturesData.hp > 0)
- {
- Dispose();
- PlayHit();
- }
- else
- {
- fxAILogicBasic.PlayHit();
- fxAILogicBasic.Dispose();
- Dispose();
- PlayHit();
- }
- return;
- }
- else
- {
- HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
- if (heroEntityMono != null)
- {
- TriggerHero(collision, heroEntityMono);
- return;
- }
- BarrierEntityMono barrierEntityMono = collision.gameObject.GetComponent<BarrierEntityMono>();
- if (barrierEntityMono != null)
- {
- TriggerBarrier(collision, barrierEntityMono);
- }
- }
- }
- protected void TriggerBarrier(Collider collision, BarrierEntityMono barrierEntityMono)
- {
- if (barrierEntityMono == null)
- {
- return;
- }
- CombatHeroEntity target = barrierEntityMono.Barrier.Own as CombatHeroEntity;
- if (target.IsEnemy == CombatHeroEntity.IsEnemy || target is CombatMagicWeaponEntity)
- {
- return;
- }
- if (TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName == null)
- {
- Dispose();
- return;
- }
- bool isOk = barrierEntityMono.Barrier.CollideTriiger(this);
- if (!isOk) //被主档
- {
- triggerData.IBarrier = true;
- ITimeLineTriggerEvent timeLineTriggerEvent =
- TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
- if (timeLineTriggerEvent != null)
- {
- timeLineTriggerEvent.TimeLineTrigger(
- TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
- target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
- if (!string.IsNullOrEmpty(hitFxName))
- {
- FinishHit(collision.ClosestPoint(gameObject.transform.position), hitFxName);
- }
- AudioManager.Instance.PlayAudio(hitAudioName, false);
- if (!isPenetrate)
- {
- Dispose();
- }
- }
- }
- }
- 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<ILifetCycleHitPoint>(), 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)
- {
- switch (parabolaCurveType)
- {
- case CurveType.Beeline:
- Beeline(time);
- break;
- case CurveType.DynamicCurve:
- DynamicCurve(time);
- break;
- case CurveType.CustomizeCurve:
- CustomizeCurve(time);
- break;
- }
- // if (Vector3.Distance(endPos, _currPos) < 0.5f)
- // {
- // Dispose();
- // }
- }
- private void Beeline(float time)
- {
- 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);
- }
- private void CustomizeCurve(float time)
- {
- currTime += _addTime * time;
- GetTargetPos();
- moveBezierPath.controlPoints[3] = endPos;
- // moveBezierPath.controlPoints[0] = (gameObject.transform.TransformPoint(BesselPath.controlPoints[0]));
- Vector3 p = moveBezierPath.CalculatePoint(currTime);
- Vector3 p2 = moveBezierPath.CalculatePoint(currTime - 0.01f);
- gameObject.transform.position = p;
- gameObject.transform.rotation = Quaternion.LookRotation((p - p2).normalized);
- }
- private void DynamicCurve(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);
- }
- protected override void ProDispose()
- {
- if (UnRegister != null)
- {
- UnRegister.UnRegister();
- }
- UnRegister = null;
- }
- private void OnDrawGizmos()
- {
- if (parabolaCurveType != CurveType.CustomizeCurve)
- {
- return;
- }
- if (BesselPath.controlPoints.Count < 4)
- {
- BesselPath.controlPoints.Add(Vector3.zero);
- BesselPath.controlPoints.Add(new Vector3(-1, 1, -1));
- BesselPath.controlPoints.Add(new Vector3(0, 0, 2));
- BesselPath.controlPoints.Add(new Vector3(0, 0, 5));
- return;
- }
- Gizmos.color = Color.blue;
- // 绘制控制点
- // 绘制曲线
- Vector3 previousPoint = BesselPath.CalculatePoint(0) + transform.position;
- int segments = 50;
- for (int i = 1; i <= segments; i++)
- {
- float t = i / (float)segments;
- Vector3 currentPoint = BesselPath.CalculatePoint(t) + transform.position;
- // Gizmos.DrawSphere(currentPoint, 0.03f);
- Gizmos.DrawLine(previousPoint, currentPoint);
- previousPoint = currentPoint;
- }
- }
- #if UNITY_EDITOR
- [CustomEditor(typeof(FxParabolaBulletLogic))]
- public class MovableCoordinateEditor : Editor
- {
- void OnSceneGUI()
- {
- FxParabolaBulletLogic fxParabolaBulletLogic = target as FxParabolaBulletLogic;
- if (fxParabolaBulletLogic.parabolaCurveType != CurveType.CustomizeCurve)
- {
- return;
- }
- if (fxParabolaBulletLogic.BesselPath.controlPoints.Count < 4)
- {
- return;
- }
- // 使用 Handles.PositionHandle 提供一个可拖动的控制柄
- for (int i = 0; i < fxParabolaBulletLogic.BesselPath.controlPoints.Count; i++)
- {
- EditorGUI.BeginChangeCheck();
- Vector3 newPosition = Handles.PositionHandle(
- fxParabolaBulletLogic.BesselPath.controlPoints[i] +
- fxParabolaBulletLogic.gameObject.transform.position,
- Quaternion.identity);
- if (EditorGUI.EndChangeCheck())
- {
- Undo.RecordObject(fxParabolaBulletLogic, "Move Coordinate");
- fxParabolaBulletLogic.BesselPath.controlPoints[i] =
- newPosition - fxParabolaBulletLogic.gameObject.transform.position;
- }
- }
- }
- }
- #endif
- }
- }
|