From 9dd1340c5ae02e887e75adab6595efa566b87335 Mon Sep 17 00:00:00 2001 From: cd <-> Date: Sun, 28 May 2023 15:59:23 +0800 Subject: [PATCH] =?UTF-8?q?fix=20timeline=20=E6=8E=89=E5=B8=A7=E6=9C=89?= =?UTF-8?q?=E6=A6=82=E7=8E=87=E8=B7=B3=E8=BF=87clip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Generated/ArticyEditorSettings.asset | 2 +- .../Scripts/ECS/Component/SkillComponent.cs | 3 +- .../Game/Scripts/ECS/System/MoveSystem.cs | 2 +- .../Game/Scripts/ECS/System/PauseSystem.cs | 2 +- .../Game/Scripts/ECS/System/TimelineSystem.cs | 71 ++++++++++++------- .../Timeline/TimelineClip/TimelineClipBase.cs | 15 +++- .../TimelineClip/TimelineClipPoolManager.cs | 1 + .../Game/Scripts/Timeline/TimelineManager.cs | 33 +++++---- 8 files changed, 82 insertions(+), 47 deletions(-) diff --git a/client/Assets/ArticyImporter/Content/Generated/ArticyEditorSettings.asset b/client/Assets/ArticyImporter/Content/Generated/ArticyEditorSettings.asset index 25efc68..a7091f4 100644 --- a/client/Assets/ArticyImporter/Content/Generated/ArticyEditorSettings.asset +++ b/client/Assets/ArticyImporter/Content/Generated/ArticyEditorSettings.asset @@ -21,6 +21,6 @@ MonoBehaviour: mLastUsedPackagesHash: 1177269412 mLastUsedPackagesCount: 1 mLastBuildCode: 1 - mLastEditorStartupTimeTicks: 638207960909662303 + mLastEditorStartupTimeTicks: 638207960920283677 mNewVersionAvailable: 1 mLastAttachedFlowPlayerValue: 0 diff --git a/client/Assets/Game/Scripts/ECS/Component/SkillComponent.cs b/client/Assets/Game/Scripts/ECS/Component/SkillComponent.cs index b1bd037..c8bf900 100644 --- a/client/Assets/Game/Scripts/ECS/Component/SkillComponent.cs +++ b/client/Assets/Game/Scripts/ECS/Component/SkillComponent.cs @@ -88,7 +88,8 @@ namespace Game CastSkill(entity, skillCfg.TechnicalName, skillTimeline, castDir); } - public static void CastSkillBullet(GameEntity entity) + + private static void CastSkillBullet(GameEntity entity) { if (!entity.hasBullet) { diff --git a/client/Assets/Game/Scripts/ECS/System/MoveSystem.cs b/client/Assets/Game/Scripts/ECS/System/MoveSystem.cs index 4f63257..6d1414c 100644 --- a/client/Assets/Game/Scripts/ECS/System/MoveSystem.cs +++ b/client/Assets/Game/Scripts/ECS/System/MoveSystem.cs @@ -132,7 +132,7 @@ public class MoveSystem : IExecuteSystem, IInitializeSystem move.IsFlowing = false; //触地特效 Util.CastGroundStaticEffect(GameConst.EffectHitGround2, entity.ID()); - Util.AddStaggerBuff(entity.ID(), 0.2f); + Util.AddStaggerBuff(entity.ID(), 2f); //缩放 Util.EntityScale(entity, Vector3.right * 3); } diff --git a/client/Assets/Game/Scripts/ECS/System/PauseSystem.cs b/client/Assets/Game/Scripts/ECS/System/PauseSystem.cs index 7061234..4bea063 100644 --- a/client/Assets/Game/Scripts/ECS/System/PauseSystem.cs +++ b/client/Assets/Game/Scripts/ECS/System/PauseSystem.cs @@ -137,7 +137,7 @@ public class PauseSystem : IExecuteSystem, IInitializeSystem return; timeline.IsPause = isPause; - foreach (var clip in timeline.Timeline.MClips) + foreach (var clip in timeline.Timeline.Clips) { var clipReal = clip.Clip; if (clipReal.IsAlive) diff --git a/client/Assets/Game/Scripts/ECS/System/TimelineSystem.cs b/client/Assets/Game/Scripts/ECS/System/TimelineSystem.cs index ec62e10..5294ae4 100644 --- a/client/Assets/Game/Scripts/ECS/System/TimelineSystem.cs +++ b/client/Assets/Game/Scripts/ECS/System/TimelineSystem.cs @@ -1,63 +1,84 @@ using Entitas; using UnityEngine; using Game; + public class TimelineSystem : IExecuteSystem, IInitializeSystem { private IGroup _entities; + public void Initialize() { _entities = Util.GetGroup(GameMatcher.Timeline); } + public void Execute() { foreach (var entity in _entities) { var timeline = entity.timeline; - if (!timeline.IsRunning) - continue; if (timeline.IsPause) continue; + if (!timeline.IsRunning) + continue; UpdateCheckEnd(entity); + if (!timeline.IsRunning) + continue; UpdateTimeline(timeline); } } - public void UpdateCheckEnd(GameEntity entity) + + private static void UpdateCheckEnd(GameEntity entity) { var timeline = entity.timeline; timeline.TimePast += Time.deltaTime; if (timeline.TimePast >= timeline.TimeMax) { Util.EndSkillTimeline(entity); - return; } } - public void UpdateTimeline(TimelineComponent timeline) + + private static void UpdateTimeline(TimelineComponent timeline) { - // if (timeline.timePast == 0) - // { - // return; - // } - foreach (var clip in timeline.Timeline.MClips) - { - var clipReal = clip.Clip; - var isOpenTime = timeline.TimePast >= clipReal.StartTime && timeline.TimePast < clipReal.EndTime; - if (clipReal.IsAlive && !isOpenTime) - { - clipReal.OnLeave(); - clipReal.IsAlive = false; - } - } - foreach (var clip in timeline.Timeline.MClips) + foreach (var clip in timeline.Timeline.Clips) { var clipReal = clip.Clip; - var isOpenTime = timeline.TimePast >= clipReal.StartTime && timeline.TimePast < clipReal.EndTime; - if (!clipReal.IsAlive && isOpenTime) + var t = timeline.TimePast; + var t1 = clipReal.StartTime; + var t2 = clipReal.EndTime; + + //没有到激活时间的 + if (t < t1) continue; + //已经执行完毕的 + if (clipReal.HasRun) continue; + + if (t >= t2) { - clipReal.OnEnter(); - clipReal.IsAlive = true; + //超过结束时间的 + if (clipReal.IsAlive) + { + //从激活状态退出的 + clipReal.OnLeave(); + clipReal.IsAlive = false; + } + else + { + //没有激活过 直接退出的 + clipReal.OnEnter(); + clipReal.OnStay(); + clipReal.OnLeave(); + } + + clipReal.HasRun = true; } - if (clipReal.IsAlive && isOpenTime) + else { + //case2 到激活时间、未到结束时间的 + if (!clipReal.IsAlive) + { + clipReal.OnEnter(); + clipReal.IsAlive = true; + } + clipReal.OnStay(); } } diff --git a/client/Assets/Game/Scripts/Timeline/TimelineClip/TimelineClipBase.cs b/client/Assets/Game/Scripts/Timeline/TimelineClip/TimelineClipBase.cs index 32bf1bd..90cea6b 100644 --- a/client/Assets/Game/Scripts/Timeline/TimelineClip/TimelineClipBase.cs +++ b/client/Assets/Game/Scripts/Timeline/TimelineClip/TimelineClipBase.cs @@ -6,11 +6,13 @@ namespace Game public class TimelineClipBase { public bool IsAlive; + public bool HasRun; public double StartTime; public double EndTime; protected double Speed; protected GameEntity Owner; protected Object Asset; + public void Create(TimelineClip clip, GameEntity owner) { Owner = owner; @@ -18,22 +20,29 @@ namespace Game StartTime = clip.start; EndTime = clip.end; Speed = clip.timeScale; + Reset(); + } + + public void Reset() + { IsAlive = false; + HasRun = false; } + public virtual void OnEnter() { } + public virtual void OnStay() { - } + public virtual void OnLeave() { - } + public virtual void OnPause(bool isPause) { - } } } \ No newline at end of file diff --git a/client/Assets/Game/Scripts/Timeline/TimelineClip/TimelineClipPoolManager.cs b/client/Assets/Game/Scripts/Timeline/TimelineClip/TimelineClipPoolManager.cs index 9ad9097..fa78676 100644 --- a/client/Assets/Game/Scripts/Timeline/TimelineClip/TimelineClipPoolManager.cs +++ b/client/Assets/Game/Scripts/Timeline/TimelineClip/TimelineClipPoolManager.cs @@ -48,6 +48,7 @@ namespace Game { item.Clip = new T(); }); + ret.Clip.Reset(); return ret; } } diff --git a/client/Assets/Game/Scripts/Timeline/TimelineManager.cs b/client/Assets/Game/Scripts/Timeline/TimelineManager.cs index d2183e9..2fa481b 100644 --- a/client/Assets/Game/Scripts/Timeline/TimelineManager.cs +++ b/client/Assets/Game/Scripts/Timeline/TimelineManager.cs @@ -5,17 +5,13 @@ namespace Game { public class TimelineObject { - public List MClips = new List(); + public readonly List Clips = new List(); } + public class TimelineManager : ManagerBase { - private static readonly string MSkillTimelinePathRoot = "Timeline/"; - public TimelineManager() - { - } - public override void OnCreate() - { - } + private const string SkillTimelinePathRoot = "Timeline/"; + public void RunSkillTimeline(GameEntity entity, string skillName) { var entityTimeline = entity.timeline.Timeline; @@ -28,49 +24,56 @@ namespace Game clips.Clear(); foreach (var clip in track.GetClips()) { - var clipReal = TimelineClipPoolManager.Instance.CreateByClipType(clip.asset.GetType(), clip, entity); + var clipReal = + TimelineClipPoolManager.Instance.CreateByClipType(clip.asset.GetType(), clip, entity); if (clipReal == null) { continue; } + clips.Add(clipReal); if (clipReal.Clip.EndTime > timeMax) { timeMax = clipReal.Clip.EndTime; } } + //这里需要按时间排序 同类型clip时序问题 - clips.Sort((a, b) => (int)(a.Clip.EndTime - b.Clip.EndTime)); - entityTimeline.MClips.AddRange(clips); + clips.Sort((a, b) => (int)((a.Clip.EndTime - b.Clip.EndTime) * 1000)); + entityTimeline.Clips.AddRange(clips); } entity.timeline.TimePast = 0; entity.timeline.TimeMax = timeMax; entity.timeline.IsRunning = true; } + public void EndSkillTimeline(GameEntity entity) { var timeline = entity.timeline; if (timeline.Timeline != null) { - foreach (var clip in timeline.Timeline.MClips) + foreach (var clip in timeline.Timeline.Clips) { var clipReal = clip.Clip; if (clipReal.IsAlive) { clipReal.OnLeave(); } + clip.Destroy(); } - timeline.Timeline.MClips.Clear(); + + timeline.Timeline.Clips.Clear(); } + timeline.IsRunning = false; timeline.IsPause = false; - } + public TimelineAsset EnsureGetSkillTimeline(string path) { - var pathReal = $"{MSkillTimelinePathRoot}{path}"; + var pathReal = $"{SkillTimelinePathRoot}{path}"; return Util.Load(pathReal); } }