diff --git a/CHANGELOG.md b/CHANGELOG.md index f50bc69..c2e59d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.8.12] 2023.03.28 + +### Fixed +- Timelines should now properly wait for previous tweens (of the same type) to be cleaned up before trying to play the new one. +- Timeline Id generation now using more unique hashcodes. + ## [0.8.11] 2023.03.23 ### Changed diff --git a/README.md b/README.md index 4c5deb4..b0f920e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ![GitHub](https://img.shields.io/github/license/dyonng/dots-tween) ![GitHub repo size](https://img.shields.io/github/repo-size/dyonng/dots-tween) -Entity compatible tween library for Unity ECS/DOTS. +Tweening library for Unity ECS/DOTS 1.0 Now uses Entities Graphics library from Unity. ## Table of Contents diff --git a/Runtime/Timelines/Components/TimelineComponent.cs b/Runtime/Timelines/Components/TimelineComponent.cs index e18ca94..af8899d 100644 --- a/Runtime/Timelines/Components/TimelineComponent.cs +++ b/Runtime/Timelines/Components/TimelineComponent.cs @@ -165,7 +165,7 @@ public uint Play(ref EntityCommandBuffer entityCommandBuffer) { var e = entityCommandBuffer.CreateEntity(); - SetupPlaybackId(ref e, e.GetHashCode()); + SetupPlaybackId(ref e, World.DefaultGameObjectInjectionWorld.Unmanaged.Time.ElapsedTime.GetHashCode()); entityCommandBuffer.AddComponent(e, this); return PlaybackId; } @@ -179,8 +179,8 @@ public uint Play(ref EntityCommandBuffer entityCommandBuffer) [BurstCompile] public uint Play(EntityManager entityManager, ref EntityCommandBuffer entityCommandBuffer) { - var e = entityCommandBuffer.CreateEntity(); - SetupPlaybackId(ref e, entityManager.GetHashCode()); + var e = entityManager.CreateEntity(); + SetupPlaybackId(ref e, entityManager.WorldUnmanaged.Time.ElapsedTime.GetHashCode()); entityCommandBuffer.AddComponent(e, this); return PlaybackId; } @@ -190,7 +190,7 @@ public uint Play(ref EntityCommandBuffer.ParallelWriter parallelWriter, in int s { var e = parallelWriter.CreateEntity(sortKey); - SetupPlaybackId(ref e, sortKey); + SetupPlaybackId(ref e, sortKey ^ World.DefaultGameObjectInjectionWorld.Unmanaged.Time.ElapsedTime.GetHashCode()); parallelWriter.AddComponent(sortKey, e, this); return PlaybackId; } @@ -200,7 +200,7 @@ public uint Play(EntityManager entityManager, ref EntityCommandBuffer.ParallelWr { var e = entityManager.CreateEntity(); - SetupPlaybackId(ref e, sortKey); + SetupPlaybackId(ref e, sortKey ^ entityManager.WorldUnmanaged.Time.ElapsedTime.GetHashCode()); parallelWriter.AddComponent(sortKey, e, this); return PlaybackId; } @@ -228,7 +228,7 @@ public JobHandle Dispose(JobHandle inputDeps) } [BurstCompile] - internal void SetupPlaybackId(ref Entity e, in int extraHash = 0) + internal void SetupPlaybackId(ref Entity e, in int extraHash) { unchecked { diff --git a/Runtime/Timelines/Components/TimelineElement.cs b/Runtime/Timelines/Components/TimelineElement.cs index 0205a10..06256b5 100644 --- a/Runtime/Timelines/Components/TimelineElement.cs +++ b/Runtime/Timelines/Components/TimelineElement.cs @@ -45,6 +45,7 @@ private static uint GenerateId(in Entity target, in float startTime, in float en hashCode = (hashCode * 1091) ^ tweenParams.StartDelay.GetHashCode(); hashCode = (hashCode * 1091) ^ tweenParams.TimelineStartPosition.GetHashCode(); hashCode = (hashCode * 1091) ^ tweenParams.TimelineEndPosition.GetHashCode(); + hashCode = (hashCode * 1091) ^ tweenParams.Id.GetHashCode(); return (uint)hashCode; } } diff --git a/Runtime/Timelines/Systems/TimelineDestroySystem.cs b/Runtime/Timelines/Systems/TimelineDestroySystem.cs index 5835ba0..4ec38fb 100644 --- a/Runtime/Timelines/Systems/TimelineDestroySystem.cs +++ b/Runtime/Timelines/Systems/TimelineDestroySystem.cs @@ -27,7 +27,10 @@ protected override void OnUpdate() while (!bufferReader.EndOfBuffer && index < timelineRef.ValueRO.Size) { var timelineElement = TimelineSystemCommandTypeHelper.DereferenceNextTimelineElement(timelineRef.ValueRO.GetTimelineElementType(index), ref bufferReader); - Tween.Controls.Stop(ref ecb, timelineElement.GetTargetEntity(), timelineElement.GetTweenId()); + if (timelineRef.ValueRO.IsTimelineElementActive(timelineElement.GetId())) + { + Tween.Controls.Stop(ref ecb, timelineElement.GetTargetEntity(), timelineElement.GetTweenId()); + } ++index; } diff --git a/Runtime/Timelines/Systems/TimelinePlaybackSystem.cs b/Runtime/Timelines/Systems/TimelinePlaybackSystem.cs index 95af740..e07a464 100644 --- a/Runtime/Timelines/Systems/TimelinePlaybackSystem.cs +++ b/Runtime/Timelines/Systems/TimelinePlaybackSystem.cs @@ -84,7 +84,8 @@ private void TryToStartPlayingTimelineElement(in ComponentType componentType, re var hasAlreadyPlayed = timelineElement.GetEndTime() <= timeline.CurrentTime; if (!pastStartTime || alreadyPlaying || hasAlreadyPlayed) return; - + if (TimelineSystemCommandTypeHelper.AlreadyHasInfoComponent(timelineElement.GetTargetEntity(), componentType, EntityManager)) return; + timeline.AddTimelineElementIdToActive(timelineElement.GetId()); TimelineSystemCommandTypeHelper.Add(ref ecb, componentType, ref timelineElement); } diff --git a/Runtime/Timelines/Systems/TimelineSystemCommandTypeHelper.cs b/Runtime/Timelines/Systems/TimelineSystemCommandTypeHelper.cs index 9c28548..da50a7b 100644 --- a/Runtime/Timelines/Systems/TimelineSystemCommandTypeHelper.cs +++ b/Runtime/Timelines/Systems/TimelineSystemCommandTypeHelper.cs @@ -179,5 +179,49 @@ internal static void Add(ref EntityCommandBuffer ecb, in ComponentType component if (componentType == SplineMovement) { ecb.AddComponent(target, (TweenSplineMovementCommand)command); return; } #endif } + + [BurstDiscard] + internal static bool AlreadyHasInfoComponent(in Entity target, in ComponentType componentType, in EntityManager entityManager) + { + if (componentType == Translation) return entityManager.HasComponent(target); + if (componentType == Scale) return entityManager.HasComponent(target); + if (componentType == Rotation) return entityManager.HasComponent(target); + if (componentType == NonUniformScale) return entityManager.HasComponent(target); +#if DOTS_TWEEN_URP + if (componentType == URPTint) return entityManager.HasComponent(target); + if (componentType == URPFade) return entityManager.HasComponent(target); + if (componentType == URPBumpScale) return entityManager.HasComponent(target); + if (componentType == URPCutoff) return entityManager.HasComponent(target); + if (componentType == URPEmissionColor) return entityManager.HasComponent(target); + if (componentType == URPMetallic) return entityManager.HasComponent(target); + if (componentType == URPOcclusionStrength) return entityManager.HasComponent(target); + if (componentType == URPSmoothness) return entityManager.HasComponent(target); + if (componentType == URPSpecularColor) return entityManager.HasComponent(target); +#elif DOTS_TWEEN_HDRP + if (componentType == HDRPAlphaCutoff) return entityManager.HasComponent(target); + if (componentType == HDRPAmbientOcclusionRemapMax) return entityManager.HasComponent(target); + if (componentType == HDRPAmbientOcclusionRemapMin) return entityManager.HasComponent(target); + if (componentType == HDRPDetailAlbedoScale) return entityManager.HasComponent(target); + if (componentType == HDRPDetailNormalScale) return entityManager.HasComponent(target); + if (componentType == HDRPDetailSmoothnessScale) return entityManager.HasComponent(target); + if (componentType == HDRPDiffusionProfileHash) return entityManager.HasComponent(target); + if (componentType == HDRPEmissiveColor) return entityManager.HasComponent(target); + if (componentType == HDRPMetallic) return entityManager.HasComponent(target); + if (componentType == HDRPSmoothness) return entityManager.HasComponent(target); + if (componentType == HDRPSmoothnessRemapMax) return entityManager.HasComponent(target); + if (componentType == HDRPSmoothnessRemapMin) return entityManager.HasComponent(target); + if (componentType == HDRPSpecularColor) return entityManager.HasComponent(target); + if (componentType == HDRPThickness) return entityManager.HasComponent(target); + if (componentType == HDRPThicknessRemap) return entityManager.HasComponent(target); + if (componentType == HDRPTint) return entityManager.HasComponent(target); + if (componentType == HDRPTintUnlit) return entityManager.HasComponent(target); + if (componentType == HDRPFade) return entityManager.HasComponent(target); + if (componentType == HDRPFadeUnlit) return entityManager.HasComponent(target); +#endif +#if DOTS_TWEEN_SPLINES + if (componentType == SplineMovement) return entityManager.HasComponent(target); +#endif + return false; + } } } \ No newline at end of file diff --git a/package.json b/package.json index 30c6d76..ef21443 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.dyonng.dotstween", - "version": "0.8.11", + "version": "0.8.12", "displayName": "DOTS Tween", "description": "Tween library for Unity ECS/DOTS.", "unity": "2022.2",