using Thousandto.Cfg.Data; using Thousandto.Code.Center; using Thousandto.Core.Asset; using Thousandto.Plugins.Common.UniScene; using UnityEngine; namespace Thousandto.Code.Logic { //锁定弹道 public class LockTrajectoryObj : Entity { #region//私有变量 private bool _postDelete = false; private float _hitSprDis = 0f; #endregion #region//属性 public Character Owner { get; private set; } public DeclareSkill SkillCfg { get; private set; } public SkillVisualInfo VisualInfo { get; private set; } public PlayLockTrajectoryEventInfo EventInfo { get; private set; } public FGameObjectVFX Vfx { get; private set; } public ulong TargetID { get; private set; } public float CurSpeed { get; private set; } #endregion #region//初始化,加载Skin,卸载处理 protected override FSkinBase OnSetupSkin() { FSkinModel skin = GameCenter.LuaSystem.Adaptor.CreateFSkinModel(FSkinTypeCode.Custom); skin.SetLayer(LayerUtils.SceneVFX); return skin; } protected override bool OnInitializeAfter(EntityInitInfo baseInfo) { base.OnInitializeAfter(baseInfo); var info = baseInfo as LockTrajectoryObjInitInfo; SyncInfo(info); return true; } protected override void OnUninitializeBefore() { if (Vfx != null) { Vfx.Destroy(); } base.OnUninitializeBefore(); } public void SyncInfo(LockTrajectoryObjInitInfo info) { Owner = info.Owner; SkillCfg = info.SkillCfg; VisualInfo = info.VisualInfo; EventInfo = info.EventInfo; TargetID = info.TargetID; var startTrans = Owner.GetSlotTransform(EventInfo.StartSlot); SetPosition(startTrans.position); var target = GameCenter.GameSceneSystem.FindEntity(TargetID); if(target == null) { PostDelete(); return; } SetDirection((target.Position - Position), false, false); Vfx = new FGameObjectVFX(ModelTypeCode.SkillVFX, EventInfo.VfxID); Vfx.SetParent(this.ModelTransform); Vfx.SetPosition(Position); Vfx.SetLayer(this.Layer); Vfx.Play(); Vfx.LiftTime = 10f; CurSpeed = EventInfo.FlySpeed; _postDelete = false; _hitSprDis = EventInfo.VfxRadius / 2f + target.PropMoudle.LogicBodyRadius / 2f; _hitSprDis = _hitSprDis * _hitSprDis; } protected override void OnUpdate(float dt) { base.OnUpdate(dt); if (_postDelete) return; if(EventInfo.FlyAddSpeed != 0f) { CurSpeed += dt * EventInfo.FlyAddSpeed; } var target = GameCenter.GameSceneSystem.FindEntity(TargetID); if (target == null) { PostDelete(); return; } var dir = (target.Position - Position).normalized; SetDirection(dir, true, true); SetPosition(Position + dir * CurSpeed); if(Vector3.SqrMagnitude(target.Position - Position) <= _hitSprDis) { //碰撞到了,直接消失,受击表现在受击消息里边处理 PostDelete(); return; } var newDir = (target.Position - Position).normalized; if(Vector3.Dot(dir, newDir) <= 0f) { //如果路过了目标,表示已经碰到了 PostDelete(); return; } } private void PostDelete() { if (!_postDelete) { var baseScene = Scene as BaseScene; if (baseScene != null) { baseScene.DeleteEntity(ID); } _postDelete = true; } } #endregion } }