using Thousandto.Code.Logic; using Thousandto.Core.Asset; using Thousandto.Core.PostEffect; using Thousandto.SkillEditor.Support; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using UnityEditor; using UnityEngine; namespace Thousandto.SkillEditor.DIY { public class SkillEditorBaseEvent { public enum EditorEventState { HoldOn, Running, Finish, } public EditorBaseObject Owner { get; private set; } public SkillEventDefine EventType { get; private set; } public SkillBaseEventInfo BaseEventInfo { get; private set; } public SkillVisualInfo VisualInfo { get; private set; } public EditorEventState CurState { get; private set; } public EditorEntity OwnerEntity { get { return Owner as EditorEntity; } } public SkillEditorBaseEvent(SkillEventDefine type, SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) { EventType = type; VisualInfo = skillInfo; BaseEventInfo = eventInfo; Owner = owner; CurState = EditorEventState.HoldOn; } public void Update(float dt) { if (CurState == EditorEventState.Running) { OnUpdate(dt); } } public void FrameUpdate(int frame) { OnFrameUpdate(frame); } public void Enter() { CurState = EditorEventState.Running; OnEnter(); } public void Stop() { CurState = EditorEventState.Finish; OnStop(); } protected virtual void OnEnter() { } protected virtual void OnStop() { } protected virtual void OnUpdate(float dt) { } protected virtual void OnFrameUpdate(int frame) { } } //播放动作 public class EditorPlayAnimEvent : SkillEditorBaseEvent { public PlayAnimEventInfo AnimInfo { get; private set; } public EditorPlayAnimEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlayAnimation, skillInfo, eventInfo, owner) { AnimInfo = BaseEventInfo as PlayAnimEventInfo; } protected override void OnEnter() { OwnerEntity.PlayAnim(AnimInfo.AnimName, AnimInfo.Loop != 0 ? WrapMode.Loop : WrapMode.Once, AnimInfo.Speed, AnimInfo.NormalizedTime); base.OnEnter(); } protected override void OnStop() { if (AnimInfo.Loop != 0) { OwnerEntity.StopAnim(); } base.OnStop(); } } //播放特效 public class EditorPlayVfxEvent : SkillEditorBaseEvent { public PlayVfxEventInfo VfxInfo { get; private set; } public EditorVFXScript Vfx { get; private set; } public Transform SyncTrans { get; private set; } public int CurFrameCount { get; private set; } public EditorPlayVfxEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlayVfx, skillInfo, eventInfo, owner) { VfxInfo = BaseEventInfo as PlayVfxEventInfo; } protected override void OnEnter() { SyncTrans = SlotUtils.GetSlotTransform(Owner.RootTrans, VfxInfo.SlotName); Vfx = Owner.PlayVFX(VfxInfo.VfxID); if (Vfx != null) { if (VfxInfo.SyncPos != 0) { Vfx.transform.position = SyncTrans.position; } if (VfxInfo.SyncRot != 0) { Vfx.transform.rotation = SyncTrans.rotation; } if (VfxInfo.SyncScale != 0) { Vfx.transform.localScale = SyncTrans.lossyScale; } } base.OnEnter(); } protected override void OnFrameUpdate(int frame) { CurFrameCount = frame; base.OnFrameUpdate(frame); } protected override void OnUpdate(float dt) { if (SyncTrans != null && Vfx != null) { if (VfxInfo.SyncFrameCount == 0 || (CurFrameCount - VfxInfo.EventFrame) < VfxInfo.SyncFrameCount) { if (VfxInfo.SyncPos != 0) { Vfx.transform.position = SyncTrans.position; } if (VfxInfo.SyncRot != 0) { Vfx.transform.rotation = SyncTrans.rotation; } if (VfxInfo.SyncScale != 0) { Vfx.transform.localScale = SyncTrans.lossyScale; } } } base.OnUpdate(dt); } protected override void OnStop() { if (VisualInfo.EndClearVfx && Vfx != null) { Vfx.Stop(); } else if (Vfx != null) { Vfx.transform.parent = null; } base.OnStop(); } } //播放音效 public class EditorPlaySFXEvent : SkillEditorBaseEvent { public PlaySfxEventInfo SfxInfo { get; private set; } public EditorPlaySFXEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlaySfx, skillInfo, eventInfo, owner) { SfxInfo = BaseEventInfo as PlaySfxEventInfo; } protected override void OnEnter() { AudioPlayer.PlaySfx(null, SfxInfo.Sound); base.OnEnter(); Stop(); } } //播放摄像机震动 public class EditorPlayCameraShakeEvent : SkillEditorBaseEvent { public PlayCameraShakeEventInfo ShakeInfo { get; private set; } public EditorPlayCameraShakeEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlayCameraShake, skillInfo, eventInfo, owner) { ShakeInfo = BaseEventInfo as PlayCameraShakeEventInfo; } protected override void OnEnter() { PostEffectManager.Instance.PlayCameraShake(ShakeInfo.Curve, ShakeInfo.CurveTotalTime, ShakeInfo.CurveType, ShakeInfo.CurvePower); base.OnEnter(); Stop(); } } //播放辐射状模糊效果 public class EditorPlayBlurEvent : SkillEditorBaseEvent { public PlayBlurEventInfo BlurInfo { get; private set; } public EditorPlayBlurEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlayBlur, skillInfo, eventInfo, owner) { BlurInfo = BaseEventInfo as PlayBlurEventInfo; } protected override void OnEnter() { if (BlurInfo.BlurType == 0) { PostEffectManager.Instance.PlayRadiaBlur(BlurInfo.Start, BlurInfo.End, BlurInfo.Time); } else { PostEffectManager.Instance.PlayGaussBlur(BlurInfo.GrassBlurSize, BlurInfo.Time); } base.OnEnter(); Stop(); } } //播放减速效果 public class EditorPlaySlowEvent : SkillEditorBaseEvent { public PlaySlowEventInfo SlowInfo { get; private set; } public float Timer { get; private set; } public EditorPlaySlowEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlaySlow, skillInfo, eventInfo, owner) { SlowInfo = eventInfo as PlaySlowEventInfo; } protected override void OnEnter() { base.OnEnter(); Time.timeScale = SlowInfo.TimeScale; Timer = SlowInfo.Time; } protected override void OnUpdate(float dt) { base.OnUpdate(dt); dt /= Time.timeScale; Timer -= dt; if (Timer <= 0f) { Stop(); } } protected override void OnStop() { base.OnStop(); Time.timeScale = 1f; } } //禁止角色移动事件 public class EditorDisableMoveEvent : SkillEditorBaseEvent { public DisableMoveEventInfo Info { get; private set; } public EditorDisableMoveEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.DisableMove, skillInfo, eventInfo, owner) { Info = BaseEventInfo as DisableMoveEventInfo; } protected override void OnEnter() { base.OnEnter(); OwnerEntity.DisableMove = true; OwnerEntity.StopSate(); } protected override void OnStop() { base.OnStop(); OwnerEntity.DisableMove = false; } protected override void OnFrameUpdate(int frame) { base.OnFrameUpdate(frame); if (Info.DisableFrameCount > 0) { if (frame - Info.EventFrame > Info.DisableFrameCount) { Stop(); } } } } //禁止角色改变方向事件 public class EditorDisableChangeDirEvent : SkillEditorBaseEvent { public DisableChangeDirEventInfo Info { get; private set; } public EditorDisableChangeDirEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.DisableChangeDir, skillInfo, eventInfo, owner) { Info = BaseEventInfo as DisableChangeDirEventInfo; } protected override void OnEnter() { base.OnEnter(); OwnerEntity.DisableChangeDir = true; } protected override void OnStop() { base.OnStop(); OwnerEntity.DisableChangeDir = false; } protected override void OnFrameUpdate(int frame) { base.OnFrameUpdate(frame); if (Info.DisableFrameCount > 0) { if (frame - Info.EventFrame > Info.DisableFrameCount) { Stop(); } } } } //播放锁定弹道 public class EditorPlayLockTrajectoryEvent : SkillEditorBaseEvent { public PlayLockTrajectoryEventInfo Info { get; private set; } public EditorPlayLockTrajectoryEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlayLockTrajectory, skillInfo, eventInfo, owner) { Info = BaseEventInfo as PlayLockTrajectoryEventInfo; } protected override void OnEnter() { base.OnEnter(); SkillEditorScene.PlayLockFlyVfx(OwnerEntity, Info); Owner.AddWarningField(Info.FindInfo); } protected override void OnStop() { base.OnStop(); Owner.RemoveWarningField(); } } //播放简单召唤物 public class EditorPlaySimpleSkillObjectEvent : SkillEditorBaseEvent { public PlaySimpleSkillObjectEventInfo Info { get; private set; } public EditorPlaySimpleSkillObjectEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlaySimpleSkillObject, skillInfo, eventInfo, owner) { Info = BaseEventInfo as PlaySimpleSkillObjectEventInfo; } protected override void OnEnter() { base.OnEnter(); SkillEditorScene.PlaySimpleSkillObject(OwnerEntity, Info); Stop(); } } //播放技能召唤物 public class EditorPlaySkillObjectEvent : SkillEditorBaseEvent { public PlaySkillObjectEventInfo Info { get; private set; } public EditorPlaySkillObjectEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlaySkillObject, skillInfo, eventInfo, owner) { Info = BaseEventInfo as PlaySkillObjectEventInfo; } protected override void OnEnter() { base.OnEnter(); SkillEditorScene.PlaySkillObject(OwnerEntity, Info); Stop(); } } //播放产生伤害事件 public class EditorPlayHitEvent : SkillEditorBaseEvent { public PlayHitEventInfo Info { get; private set; } public EditorPlayHitEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlayHit, skillInfo, eventInfo, owner) { Info = BaseEventInfo as PlayHitEventInfo; } protected override void OnEnter() { base.OnEnter(); Owner.AddWarningField(Info.FindInfo); SkillEditorScene.PlayHitEvent(Owner, Info); } protected override void OnStop() { base.OnStop(); Owner.RemoveWarningField(); } } //播放自身移动事件 public class EditorPlaySelfMoveEvent : SkillEditorBaseEvent { public PlaySelfMoveEventInfo Info { get; private set; } public Vector3 OriPos { get; private set; } public Vector3 EndPos { get; private set; } public float MoveTimer { get; private set; } public EditorPlaySelfMoveEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlaySelfMove, skillInfo, eventInfo, owner) { Info = BaseEventInfo as PlaySelfMoveEventInfo; } protected override void OnEnter() { base.OnEnter(); MoveTimer = 0f; var mainTarget = SkillEditorScene.FindMainTarget(OwnerEntity); var dir = OwnerEntity.RootTrans.forward; dir.y = 0f; dir = dir.normalized; OriPos = Owner.Position; switch (Info.MoveType) { case SelfMoveType.TargetFace: { if (mainTarget != null) { dir = mainTarget.Position - Owner.Position; dir.y = 0f; dir = dir.normalized; var dis = Vector3.Distance(mainTarget.Position, Owner.Position); if(dis < 1f) { //不移动 EndPos = OriPos; } else if(dis > Info.MaxDis) { EndPos = OriPos + dir * Info.NoTargetDis; } else { EndPos = mainTarget.Position - dir * 1f; } } else { EndPos = OriPos + dir * Info.NoTargetDis; } } break; case SelfMoveType.TargetBack: { if (mainTarget != null) { dir = mainTarget.Position - Owner.Position; dir.y = 0f; dir = dir.normalized; var dis = Vector3.Distance(mainTarget.Position, Owner.Position); if (dis > Info.MaxDis) { EndPos = OriPos + dir * Info.NoTargetDis; } else { EndPos = mainTarget.Position + dir * 1f; } } else { EndPos = OriPos + dir * Info.NoTargetDis; } } break; case SelfMoveType.FixedDis: { if (mainTarget != null) { dir = mainTarget.Position - Owner.Position; dir.y = 0f; dir = dir.normalized; } EndPos = OriPos + dir * Info.MaxDis; } break; case SelfMoveType.MoveBack: { if (mainTarget != null) { dir = mainTarget.Position - Owner.Position; dir.y = 0f; dir = dir.normalized; } EndPos = OriPos - dir * Info.MaxDis; } break; } OwnerEntity.Roter.CurForward = EndPos - OriPos; } protected override void OnUpdate(float dt) { MoveTimer += dt; if(MoveTimer <= Info.MoveTime) { var lerpValue = MoveTimer / Info.MoveTime; Owner.Position = Vector3.Lerp(OriPos, EndPos, Info.MoveCurve.Evaluate(lerpValue)); } else { Stop(); } base.OnUpdate(dt); } protected override void OnStop() { Owner.Position = EndPos; base.OnStop(); } } //隐藏角色武器事件 public class EditorPlayHideWeaponEvent : SkillEditorBaseEvent { public PlayHideWeaponEventInfo Info { get; private set; } public EditorPlayHideWeaponEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlayHideWeapon, skillInfo, eventInfo, owner) { Info = BaseEventInfo as PlayHideWeaponEventInfo; } protected override void OnEnter() { base.OnEnter(); OwnerEntity.HideWeapon = true; } protected override void OnStop() { base.OnStop(); OwnerEntity.HideWeapon = false; } protected override void OnFrameUpdate(int frame) { base.OnFrameUpdate(frame); if (Info.HideFrame > 0) { if (frame - Info.EventFrame > Info.HideFrame) { Stop(); } } } } //链接伤害效果事件 public class EditorPlayLinkDamageEvent : SkillEditorBaseEvent { public PlayLinkDamageEventInfo Info { get; private set; } public EditorPlayLinkDamageEvent(SkillVisualInfo skillInfo, SkillBaseEventInfo eventInfo, EditorBaseObject owner) : base(SkillEventDefine.PlayLinkDamage, skillInfo, eventInfo, owner) { Info = BaseEventInfo as PlayLinkDamageEventInfo; } protected override void OnEnter() { base.OnEnter(); SkillEditorScene.PlayLinkEffect(OwnerEntity, Info); } } }