Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit f8fd81e

Browse files
authored
Merge pull request #14 from AnnulusGames/v0.1.9
v0.1.9
2 parents ce25b7f + 3427ab1 commit f8fd81e

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

MagicTween/Assets/MagicTween/Runtime/Core/Systems/TweenCallbackSystem.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace MagicTween.Core
99
[UpdateInGroup(typeof(MagicTweenCallbackSystemGroup))]
1010
public sealed partial class TweenCallbackSystem : SystemBase
1111
{
12+
public bool IsExecuting => _isExecuting;
13+
14+
bool _isExecuting;
1215
EntityQuery query;
1316

1417
protected override void OnCreate()
@@ -21,9 +24,17 @@ protected override void OnCreate()
2124

2225
protected override void OnUpdate()
2326
{
24-
CompleteDependency();
25-
var job = new SystemJob();
26-
job.Run(query);
27+
_isExecuting = true;
28+
try
29+
{
30+
CompleteDependency();
31+
var job = new SystemJob();
32+
job.Run(query);
33+
}
34+
finally
35+
{
36+
_isExecuting = false;
37+
}
2738
}
2839

2940
partial struct SystemJob : IJobEntity

MagicTween/Assets/MagicTween/Runtime/Core/TweenFactory.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,20 @@ static void CreateTweenEntity(ref EntityManager entityManager, in EntityArchetyp
339339
entityManager.SetComponentData(entity, new TweenControllerReference(controllerId));
340340
}
341341

342+
[BurstCompile]
343+
static void SetStartAndEndValue<TValue>(in Entity entity, in TValue startValue, in TValue endValue)
344+
where TValue : unmanaged
345+
{
346+
EntityManagerRef.SetComponentData(entity, new TweenStartValue<TValue>() { value = startValue });
347+
EntityManagerRef.SetComponentData(entity, new TweenEndValue<TValue>() { value = endValue });
348+
}
349+
342350
static void InitializeLambdaTweenComponents<TValue, TPlugin>(
343351
in Entity entity, in TValue startValue, in TValue endValue, TweenGetter<TValue> getter, TweenSetter<TValue> setter)
344352
where TValue : unmanaged
345353
where TPlugin : unmanaged, ITweenPlugin<TValue>
346354
{
347-
EntityManagerRef.SetComponentData(entity, new TweenStartValue<TValue>() { value = startValue });
348-
EntityManagerRef.SetComponentData(entity, new TweenEndValue<TValue>() { value = endValue });
355+
SetStartAndEndValue(entity, startValue, endValue);
349356
EntityManagerRef.SetComponentData(entity, new TweenPropertyAccessor<TValue>(getter, setter));
350357
}
351358

@@ -355,15 +362,15 @@ static void InitializeUnsafeLambdaTweenComponents<TObject, TValue, TPlugin>(
355362
where TValue : unmanaged
356363
where TPlugin : unmanaged, ITweenPlugin<TValue>
357364
{
358-
EntityManagerRef.SetComponentData(entity, new TweenStartValue<TValue>() { value = startValue });
359-
EntityManagerRef.SetComponentData(entity, new TweenEndValue<TValue>() { value = endValue });
365+
SetStartAndEndValue(entity, startValue, endValue);
360366
EntityManagerRef.SetComponentData(entity, new TweenPropertyAccessorUnsafe<TValue>(
361367
target,
362368
UnsafeUtility.As<TweenGetter<TObject, TValue>, TweenGetter<object, TValue>>(ref getter),
363369
UnsafeUtility.As<TweenSetter<TObject, TValue>, TweenSetter<object, TValue>>(ref setter)
364370
));
365371
}
366372

373+
[BurstCompile]
367374
static void InitializeEntityTweenComponents<TValue, TTranslator>(
368375
ref EntityManager entityManager, in Entity entity, in TValue startValue, in TValue endValue, in Entity target)
369376
where TValue : unmanaged
@@ -372,10 +379,10 @@ static void InitializeEntityTweenComponents<TValue, TTranslator>(
372379
var translator = default(TTranslator);
373380
translator.TargetEntity = target;
374381

375-
entityManager.SetComponentData(entity, new TweenStartValue<TValue>() { value = startValue });
376-
entityManager.SetComponentData(entity, new TweenEndValue<TValue>() { value = endValue });
382+
SetStartAndEndValue(entity, startValue, endValue);
377383
entityManager.SetComponentData(entity, translator);
378384
}
385+
[BurstCompile]
379386

380387
static void InitializeEntityTweenComponents<TValue, TTranslator>(
381388
ref EntityManager entityManager, in Entity entity, in TValue endValue, in Entity target)

MagicTween/Assets/MagicTween/Runtime/Core/TweenWorld.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ public static void Initialize()
1010
_world = World.DefaultGameObjectInjectionWorld;
1111
_entityManager = _world.EntityManager;
1212
_cleanupSystem = _world.GetExistingSystemManaged<TweenCleanupSystem>();
13+
_callbackSystem = _world.GetExistingSystemManaged<TweenCallbackSystem>();
1314
ArchetypeStorage.Create(Allocator.Persistent, out _archetypeStorage);
1415
}
1516

1617
static World _world;
1718
static EntityManager _entityManager;
1819
static TweenCleanupSystem _cleanupSystem;
20+
static TweenCallbackSystem _callbackSystem;
1921
static ArchetypeStorage _archetypeStorage;
2022

2123
public static World World => _world;
2224
public static EntityManager EntityManager => _entityManager;
2325
public static ref EntityManager EntityManagerRef => ref _entityManager;
2426
public static TweenCleanupSystem CleanupSystem => _cleanupSystem;
27+
public static TweenCallbackSystem CallbackSystem => _callbackSystem;
2528
internal static ref ArchetypeStorage ArchetypeStorageRef => ref _archetypeStorage;
2629
}
2730
}

MagicTween/Assets/MagicTween/Runtime/TweenCallbackExtensions.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ internal static TweenCallbackActions GetOrAddComponent(in Entity entity)
1616
}
1717
else
1818
{
19-
// Use EntityCommandBuffer to avoid structural changes
2019
var actions = new TweenCallbackActions();
21-
var commandBuffer = TweenWorld.World.GetExistingSystemManaged<EndSimulationEntityCommandBufferSystem>().CreateCommandBuffer();
22-
commandBuffer.AddComponent(entity, actions);
20+
if (TweenWorld.CallbackSystem.IsExecuting)
21+
{
22+
// Use EntityCommandBuffer to avoid structural changes
23+
var commandBuffer = TweenWorld.World.GetExistingSystemManaged<EndSimulationEntityCommandBufferSystem>().CreateCommandBuffer();
24+
commandBuffer.AddComponent(entity, actions);
25+
}
26+
else
27+
{
28+
TweenWorld.EntityManager.AddComponentData(entity, actions);
29+
}
2330
return actions;
2431
}
2532
}

MagicTween/Assets/MagicTween/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.annulusgames.magic-tween",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"displayName": "Magic Tween",
55
"description": "Extremely fast tween library implemented with Unity ECS",
66
"unity": "2022.1",

MagicTween/ProjectSettings/ProjectSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ PlayerSettings:
133133
vulkanEnableLateAcquireNextImage: 0
134134
vulkanEnableCommandBufferRecycling: 1
135135
loadStoreDebugModeEnabled: 0
136-
bundleVersion: 0.1.8
136+
bundleVersion: 0.1.9
137137
preloadedAssets: []
138138
metroInputSource: 0
139139
wsaTransparentSwapchain: 0

0 commit comments

Comments
 (0)