⌚
Timeflow
  • ⌚Introduction
  • 📗User Guide
    • â–ļī¸Getting Started
      • ✅Requirements
      • âŦ‡ī¸Installation
      • 🚀Quick Start
      • âœī¸Workflow
      • đŸŽŦRender Pipeline
      • â¯ī¸Editor vs Runtime
      • đŸĻŋHow it Works
      • â›‘ī¸Potential Issues
      • ⚡Optimization
      • 🔨3rd Party Tools
      • đŸ”ĸUpgrading Guide
    • â„šī¸Timeflow Editor
      • đŸŽ›ī¸Menu Bar
      • â˛ī¸Time
      • Local Time Scope
      • 🧰Work Area
      • âš™ī¸Settings
      • âŗUpdate Settings
      • đŸ“ēDisplay Lists
      • đŸ”ģMarkers
      • đŸ”ĩObject
      • 🏭Managed Objects
      • ⚡Quick Select Objects
      • âš’ī¸Tools
    • đŸŽŦTimeflow View
      • 🔩Toolbar
        • 🔑Auto Keyframing
        • â¯ī¸Play Controls
        • đŸĨ…Work Area
        • â¯ī¸Current Time
        • đŸŽŧMusical Timing
        • 🌐Grid and Snap
        • 🔸Keyframe Values
        • đŸ”ģMarkers
      • â˛ī¸Timeline
      • 📐Time Navigation
      • Local Time Scope
      • 🎏Track View
      • â†˜ī¸Selection
      • 📰Object Panel
      • đŸ“ēDisplay Lists
      • 🍱Channels
      • đŸŖProperties
      • 🔗Channel Link
      • đŸšĨSwitches
      • 📅Values Column
      • đŸ›¤ī¸Tracks
      • 🔸Keyframes
      • đŸ“ļAlignment Tools
      • ⌛Time Offset
      • đŸ”ĸInfo Panel
      • 📉Graph View
      • âœ‚ī¸Keyframe Tools
    • 🍰Menus & Shortcuts
      • 📃Context Menus
        • â†–ī¸Select Menu
        • 📰Object Menu
        • 🍱Channel Menu
        • đŸ›¤ī¸Tracks Menu
        • 🔸Keyframes Menu
        • đŸ”ģMarkers Menu
        • 📰View Menu
        • 📰Events Menu
        • đŸĨ…Work Area Menu
      • đŸ—ƒī¸File Menu
      • âš’ī¸Timeflow Menu
        • đŸ•ēAdd Behavior
        • đŸ”ļAnimation
        • 🍱Composition
        • đŸ“ēDisplay
        • ⏊Jump To
        • 👨‍đŸ‘Ļ‍đŸ‘ĻHierarchy
        • 🌐Mesh
        • 👉Select
        • 📚Tracks
        • 🌈Track Colors
        • â†”ī¸Transform
        • đŸ‘ī¸Visibility
        • đŸ› ī¸Editor
      • đŸ”ĩGame Objects Menu
      • đŸŽ›ī¸Presets
      • âš™ī¸Preferences
        • Assets
        • ⌛Time
        • đŸŗī¸â€đŸŒˆTracks
        • âšĒObjects
        • 🧮Channels
        • đŸ”ļKeyframes
        • 🔠Input
        • đŸ“ĨImport
        • đŸ–ŧī¸Rendering
        • đŸŽ›ī¸Overrides
        • 🍱Extras
      • *ī¸âƒŖKeyboard Shortcuts
        • Managing Shortcuts
      • âœ´ī¸Quick Menu
  • Reference
    • đŸ”ĩTimeflow Object
      • đŸĸTracks
      • 🏭Behaviors
      • ⏰Events
      • đŸ—ƒī¸Channels
    • 💃Timeflow Controller
      • đŸŽžī¸Timeflow Playback
    • đŸĒ„Behaviors
      • đŸŽžī¸Animation
        • 🔸Keyframer
        • â†”ī¸Tween
        • 🔀Blend
        • đŸŽĸMotion Path
        • đŸ‘¯Animation Clips
        • 🌴Animator Blend Trees
        • 😁Blend Shapes
      • 🤖Automation
        • 🛸Auto Bank
        • 🧭Auto Rotate
        • 📐Distance
        • ⏰Event
        • đŸ›Šī¸Flyby
        • 🏃Follow
        • 👀Look At
        • đŸŽ¯Look At Target
        • 🎲Noise
        • 🚊Place On Path
        • đŸī¸Place On Surface
      • 🔊Audio
        • 🔊Audio Track
        • đŸŽŧAudio Spectrum
        • đŸŽĩAudio Sample
        • đŸŽ™ī¸Audio Reactive
      • 🎹MIDI
        • 🎹Midi File
        • đŸĨMidi Tween
        • 📡Midi Receiver
          • đŸŽ›ī¸Minis Setup (New Input System)
          • đŸšĨMidiJack Setup (Legacy Input)
      • 🏁Rendering
        • đŸŽžī¸Render To Disk
        • 📋Render Queue
        • đŸ“Ŋī¸Video Encoding
        • 💡Tips & Optimizations
        • âēī¸Unity Recorder
      • 🔧Tools
        • â„šī¸Animator Info
        • 🧮Align Children
        • đŸ’ŦComment
        • #ī¸âƒŖFPS Counter
        • 📈Graph
        • 🔗Property Link
        • 🔄Rotator
        • ✨Particle System Update
        • 🌈Trail Renderer Update
        • đŸ“ēVideo Player Update
    • đŸ—ƒī¸Precomposing
    • 🏭Prefabs
    • đŸŽ›ī¸Editor Overrides
      • 🏹Transform Editor Override
    • 🔌Integrations
      • đŸ§™â€â™‚ī¸Adventure Creator
      • đŸŽ›ī¸MIDI Jack | Minis
      • đŸ¤ēSpine Animation
      • đŸ“Ŋī¸Unity Timeline
      • ➰Unity Splines
    • đŸĒSamples
      • đŸ•šī¸Demo App
      • đŸŽžī¸Cutscenes
      • 🏓Physics
      • 🍧Shader Properties
      • ⚡Visual Effect Graph (VFX)
    • 📖Glossary
    • 📗Scripting
    • đŸ“ŖPublished Works
    • âš ī¸Known Issues
    • 🆘Support
    • đŸ§ĒBeta
    • Roadmap
    • đŸ”ĸVersion History
    • ÂŠī¸Terms & Privacy
Powered by GitBook
On this page
  • Timeflow Parent
  • Callback Methods
  • Register and Unregister
  1. Reference
  2. Timeflow Controller

Timeflow Playback

Playback integration for custom scripts

This is a base class providing a general API for implementing custom playback logic. The API is defined by the interface ITimeflowPlayback, implemented abstractly by TimeflowPlaybackBase and concretely by TimeflowPlayback for convenience.

Timeflow Parent

This assigns the Timeflow instance to observe playback events. If none is specified explicitly, it defaults to the current active Timeflow in the scene.

Callback Methods

The following methods may be overridden to implement custom logic:

  • OnPlay() : Called when playback starts or resumes

  • OnStop() : Called when playback stops or is paused

  • OnUpdate() : Called each frame playback updates - only while playing

  • OnRewind() : Called whenever time jumps backward

  • OnLoop() : Called whenever looping occurs during playback

To get the current time, use TimeflowParent.CurrentTime

Register and Unregister

It is important that each script that implements ITimeflowPlayback registers itself globally, otherwise it will not receive the above event callbacks. And each script should Unregister itself when destroyed or deactivated.

The base class OnEnable and OnDisable automatically perform Register and Unregister, so in derived classes be sure to call base.OnEnable() and base.OnDisable() when these methods are overridden.

// Copyright 2024 Axon Genesis. All rights reserved.
// AxonGenesis.com
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.

using UnityEngine;

namespace AxonGenesis
{
    /// <summary>
    /// A simple example showing how to use the ITimeflowPlayback interface to add
    /// Timeflow playback events to any script. This can also be used on 
    /// ScriptableObject types and does not have to be a MonoBehaviour.
    /// ---
    /// IMPORTANT: For your script to work in edit mode, be sure to set ExecuteInEditMode
    /// </summary>
    [ExecuteInEditMode]
    public class TimeflowPlayback : TimeflowPlaybackBase
    {
        /// <summary>
        /// Registers an object to receive playback events. If a game object is specified, it will
        /// be used to try to find the Timeflow parent in the hierarchy above. 
        /// </summary>
        /// <param name="playback">Reference to the object that imlements ITimeflowPlayback</param>
        /// <param name="obj">The game object, or may be null</param>
        static public void Register(ITimeflowPlayback playback, GameObject obj = null)
        {
            if (playback.TimeflowParent == null && obj != null) {
                playback.TimeflowParent = ObjectUtil.GetComponentInSelfOrAncestors<Timeflow>(obj);
            }
            if (playback.TimeflowParent == null) playback.TimeflowParent = Timeflow.Active;
            if (playback.TimeflowParent == null) return;
            playback.TimeflowParent.RegisterPlaybackListener(playback);
        }

        /// <summary>
        /// Any script which calls Register must also call Unregster (preferably OnDisable) otherwise
        /// null reference errors may occur if objects are destroyed while Timeflow is playing.
        /// </summary>
        /// <param name="playback"></param>
        static public void Unregister(ITimeflowPlayback playback)
        {
            if (playback == null || playback.TimeflowParent == null) return;
            playback.TimeflowParent.UnregisterPlaybackListener(playback);
        }

        [Tooltip("Assign the Timeflow instance or leave unassigned to automatically work with the first active Timeflow instance in the scene.")]
        [SerializeField]
        private Timeflow _Timeflow = null;

        public override Timeflow TimeflowParent {
            get {
                return _Timeflow;
            }
            set {
                if (_Timeflow == null) _Timeflow = Timeflow.Active;
                _Timeflow = value;
            }
        }

        protected override void OnEnable()
        {
            base.OnEnable();
            // This object must be registered to receive event callbacks
            if (DebugEnabled) Debug.Log($"ITimeflowPlayback.Register:{name}");
            TimeflowPlayback.Register(this, gameObject);
        }

        protected override void OnDisable()
        {
            // Always be sure to unregister objects or null reference errors may occur
            if (DebugEnabled) Debug.Log($"ITimeflowPlayback.Unregister:{name}");
            TimeflowPlayback.Unregister(this);           
            base.OnDisable();
        }

        public override void OnPlay()
        {
            if (DebugEnabled) Debug.Log("OnPlay");
        }

        public override void OnLoop()
        {
            if (DebugEnabled) Debug.Log("OnLoop");
        }

        public override void OnRewind()
        {
            if (DebugEnabled) Debug.Log("OnRewind");
        }

        public override void OnStop()
        {
            if (DebugEnabled) Debug.Log("OnStop");
        }

        public override void OnUpdate()
        {
            if (DebugEnabled) Debug.Log($"OnUpdate:{TimeflowParent.CurrentTime}");
        }
    }
}
PreviousTimeflow ControllerNextBehaviors

Last updated 5 months ago

💃
đŸŽžī¸