Demo Scene

v1.0

The demo scene provides two objects, a Sphere and a Cube, which move through two TimeZone areas. There are sliders for the global timescale and for the timescale that affects only the Cube.

Zones

The two zones use the TimeZone component from Magic Time. The OnObjectEnter and OnObjectExit unity events call methods on the ZoneActions class, passing TimeZoneEventData along with it.

The methods, like HandleOnEnter, will ensure the object is a MagicalObject, and call HandleZoneTransition on that component β€” again, we're going to pass pertinent detials along, which came from the TimeZoneEventData.

// ZoneActions.cs
public void HandleOnEnter(TimeZoneEventData eventData)
{
    var magicalObject = eventData.gameObject.GetComponent<MagicalObject>();
    if (magicalObject == null)
        return;
    
    magicalObject.HandleZoneTransition(true, eventData.contactPoint, particlePrefab, ZoneColor);
    onEnterActions.Execute(this);
}

HandleZoneTransition

The MagicalObject class, which inherits from MagicTimeUser, is on the Sphere and Cube. The single point of entry is split into HandleEnterZone and HandleExitZone. This custom script passes the TimeZoneEventData from the TimeZone itself, all the way to our Action Executors on the objects.

// MagicalObject.cs
private void HandleExitZone(Vector3 contactPoint, GameObject particlePrefab, Color zoneColor)
{
    OverrideExitParticle(particlePrefab);
    OverrideExitParticleRotation();
    OverrideExitParticleSpawnPosition(contactPoint);
    
    zoneEnterActions.StopAllActions();
    zoneExitActions.Execute(this);
}

First we will override the values of specific Action objects. This allows us to use the same Action Executor but have slightly different results. In the code above, we're setting the required values to spawn our "Exit Particle" where we exited the TimeZone, and rotate it properly.

Then we Execute().

The first Action in each of the Action Executors is the StopActionSequenceAction, and we have that set to "All Sequences in Class", with "Exclude this Sequence" toggled true.

Using StopActionSequenceAction, we are able to ensure that only one of these is active at once β€” both affect the same things on the object, and would conflict otherwise.

Last updated