Skip to content

Commit

Permalink
Fix: callback was not set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnulusGames committed Oct 24, 2023
1 parent 825b616 commit 38c6f3f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace MagicTween.Core
[UpdateInGroup(typeof(MagicTweenCallbackSystemGroup))]
public sealed partial class TweenCallbackSystem : SystemBase
{
public bool IsExecuting => _isExecuting;

bool _isExecuting;
EntityQuery query;

protected override void OnCreate()
Expand All @@ -21,9 +24,17 @@ protected override void OnCreate()

protected override void OnUpdate()
{
CompleteDependency();
var job = new SystemJob();
job.Run(query);
_isExecuting = true;
try
{
CompleteDependency();
var job = new SystemJob();
job.Run(query);
}
finally
{
_isExecuting = false;
}
}

partial struct SystemJob : IJobEntity
Expand Down
3 changes: 3 additions & 0 deletions MagicTween/Assets/MagicTween/Runtime/Core/TweenWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ public static void Initialize()
_world = World.DefaultGameObjectInjectionWorld;
_entityManager = _world.EntityManager;
_cleanupSystem = _world.GetExistingSystemManaged<TweenCleanupSystem>();
_callbackSystem = _world.GetExistingSystemManaged<TweenCallbackSystem>();
ArchetypeStorage.Create(Allocator.Persistent, out _archetypeStorage);
}

static World _world;
static EntityManager _entityManager;
static TweenCleanupSystem _cleanupSystem;
static TweenCallbackSystem _callbackSystem;
static ArchetypeStorage _archetypeStorage;

public static World World => _world;
public static EntityManager EntityManager => _entityManager;
public static ref EntityManager EntityManagerRef => ref _entityManager;
public static TweenCleanupSystem CleanupSystem => _cleanupSystem;
public static TweenCallbackSystem CallbackSystem => _callbackSystem;
internal static ref ArchetypeStorage ArchetypeStorageRef => ref _archetypeStorage;
}
}
13 changes: 10 additions & 3 deletions MagicTween/Assets/MagicTween/Runtime/TweenCallbackExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ internal static TweenCallbackActions GetOrAddComponent(in Entity entity)
}
else
{
// Use EntityCommandBuffer to avoid structural changes
var actions = new TweenCallbackActions();
var commandBuffer = TweenWorld.World.GetExistingSystemManaged<EndSimulationEntityCommandBufferSystem>().CreateCommandBuffer();
commandBuffer.AddComponent(entity, actions);
if (TweenWorld.CallbackSystem.IsExecuting)
{
// Use EntityCommandBuffer to avoid structural changes
var commandBuffer = TweenWorld.World.GetExistingSystemManaged<EndSimulationEntityCommandBufferSystem>().CreateCommandBuffer();
commandBuffer.AddComponent(entity, actions);
}
else
{
TweenWorld.EntityManager.AddComponentData(entity, actions);
}
return actions;
}
}
Expand Down

0 comments on commit 38c6f3f

Please sign in to comment.