Instructions for using TimeLine

1. About TimeLine

Timeline is a timeline-based multi-track animation system that supports visual editing and real-time preview.

Compared with other animation systems, the biggest difference between this technology is,

Timeline can make a series of animations for multiple game objects, mainly used for the production of cutscenes to achieve movie-level splitting effect.

2. Install Timeline

Open Package Manager, install TimeLine, and update it through Package Manager.

3. Create a Timeline

Click on the navigation bar at the top: window - Sequencing - TimeLine , and the Timeline window will open, which prompts you to select a GameObject

 In the Hierarchy view panel, select a node, and a Create button will appear in the Timeline window

Click the Create button to create a Timeline resource (the format is .playable), I named it: BeforeBattleTimeline.playable
 

We will also find that the object we selected automatically hangs the Playable Director and Animator components, and automatically references the Timeline resource
 

Four: Button Description on TimeLine
 

1. Move to the initial position button, click this button to move the time axis to the initial position

2. Move to previous frame button to move the timeline to the previous frame

3. Play button. After clicking the play button, Timeline will be played, and the animation effect can be previewed in the scene. The shortcut key is space. After entering play mode:

Plays from the current timeline position until the end. If the range play button is enabled, playback will be limited to the specified time zone.

The timeline will move along with it during playback, and the area of ​​the timeline will display the current time or frame number, depending on the Timeline settings.

4. Click to move to the next frame

5. Click to move to the last frame of Timeline

6. Range play button, after enabling the range play button, you can preview and play within the specified range. Note that it only takes effect when previewing in the Timeline window, and the range setting will be ignored in the running mode.

The start and end positions will be displayed on the time axis, and you can drag the start or end small icon to modify the range.

Five: Timeline

The timeline in the Timeline window shows the current preview position. The current frame number or time is displayed on the time axis. In addition, there is also a small white vertical line on the scroll bar, which represents the position of the time axis. As shown below:

6. Various Track introductions and instructions for use

In the right-click menu on the left column of the Timeline window, you can create various tracks

track description

Track Group classifies different tracks, which is equivalent to the folder function

Activation Track controls the display and hiding of objects

Animation Track adds animation to the object, which can conveniently record animation in the scene, or it can be an already produced Animation Clip

Audio Track adds sound effects to animations, and can easily cut and manipulate sound effects

Control Track Particle effects can be added to this track, and sub-Timelines can also be added for nesting

Signal Track signal track, which can send a signal and trigger a function call in response to the signal

Playable Track In this track, users can add custom playback functions

Before adding a track, first select the BeforeBattle node, the small lock on the right side of the TimeLine panel, click it, and lock it.

Activation Track

This track is to control the display and hiding of objects, and the Character_Heavy_Male_Ax node is visible in the Active timeline.

Animation Track

Create Animation Track on timeLine panel 

When dragging an object into the object slot of the Animation Track, if the object does not have an Animator component, it will prompt to hang an Animator component for the object


Then click the red button on the left panel of TimeLine to start recording and record the initial position coordinate information. We can also right-click on the track menu - Edit in Animation Window to open the Animation window to edit the animation

 

Add animation directly. Right-click on the track menu - Add From Animation Clip, select the Animation animation that the art colleagues have made and drag it directly into the track.  Audio Tracks

Add sound effects to the animation, and perform simple cutting and manipulation on the sound effects, select the sound effect resources, and drag them directly

 Control Track

It can be used to control the particle effect. The prefab Rain has been made in advance, and the Particle System component has been added to its Inspector panel, and the Rain Prefab is dragged into the Hierarchy.

Add Control Track to TimeLine to control Particle.

 Control Track 

You can also nest TimeLine, first use GO node to create a subTimeLine, then create a Control Track in BeforeBattleTYimeline, drag GO down directly, so as to realize TimeLine nesting

Signal Track

Signals can be sent to trigger function calls that respond to signals

Create an empty object in Hierachy and name it SignalReceiver. In addition, create a script named SignalTest.cs and hang it on SignalReceiver (the SignalReceiver component will be automatically bound) to respond to the signal

code show as below:

using UnityEngine;
using UnityEngine.Timeline;
[RequireComponent(typeof(SignalReceiver))]
public class SignalTest : MonoBehaviour 
{
    // 信号的响应函数
    public void OnReceiveSignal()
    {
        Debug.Log("OnReceiveSignal: Hello Signal");
    }
}

 Add the SignalTest.cs component to the Inspector panel of the SignalReceiver node, which will automatically add the Signal Receive component,

Create a Signal Track track, set the response object to create a Signal Track signal track in Timeline 

 Create a signal transmitter Signal Emitter

In the right-click menu of the Project view, select - Create - Signal, and create a signal emitter resource (Signal Emitter) named: TestSignalEmiter.signal

Drag the signal transmitter to the track, as shown in the figure: white arrow style
 to set the response function for the signal transmitter: click the signal transmitter on the track, the signal information will be displayed in the Inspector view, Add Reaction button, add the response function of the signal

The default signal monitoring object is the object where the SignalReceiver component is located.
 Click No Function to list the components on the object and all public properties and methods in the component. Here we set the response function as the OnReceiverSignal function of the SignalTest script.

Start and run the project, the time axis goes to the arrow, the event is fired, the output is monitored, and the output is normal.
 

Playable Track

You can add custom playback functions. PlayableAsset and PlayableBehaviour scripts need to write two classes, one inherits PlayableAsset and the other inherits PlayableBehaviour

MoveObjPlayableAsset.cs file:
 

using UnityEngine;
using UnityEngine.Playables;
public class MoveObjPlayableAsset : PlayableAsset
{
    public GameObject go;
    public Vector3 pos;
    
    public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    {
        var bhv = new MoveObjPlayableBehaviour();
        bhv.go = go;
        bhv.pos = pos;
        return ScriptPlayable<MoveObjPlayableBehaviour>.Create(graph, bhv);    
    }
    
}

 The MoveObjPlayableBehaviour.cs code is as follows:
 

using UnityEngine;
using UnityEngine.Playables;

public class MoveObjPlayableBehaviour : PlayableBehaviour
{
    public GameObject go;
    public Vector3 pos;

    public override void OnGraphStart(Playable playable)
    {
        base.OnGraphStart(playable);

        Debug.Log("OnGraphStart=======================");
    }

    public override void OnGraphStop(Playable playable)
    {
        base.OnGraphStop(playable);
        Debug.Log("OnGraphStop=======================");
    }

    public override void OnBehaviourPlay(Playable playable, FrameData info)
    {
        // 这里的逻辑是改变物体的坐标,具体逻辑就看具体需求
        base.OnBehaviourPlay(playable, info);
        Debug.Log("OnBehaviourPlay=======================");
        if (null != go)
        {
            go.transform.position = pos;
        }
    }

    public override void OnBehaviourPause(Playable playable, FrameData info)
    {
        base.OnBehaviourPause(playable, info);
        Debug.Log("OnBehaviourPause=======================");
        if (null != go)
        {
            go.transform.position = Vector3.zero;
        }
    }

    public override void OnBehaviourDelay(Playable playable, FrameData info)
    {
        base.OnBehaviourDelay(playable, info);
        Debug.Log("OnBehaviourDelay=======================");
    }
}

 Drag the PlayableAsset onto the track

Drag the MoveObjPlayableAsset script directly onto the PlayableTrack track. The specific script logic is implemented in MoveObjPlayableBehaviour. This example is to set the coordinates of the object

Dynamically set PlayableAsset parameters

Now, we write another script ( Runner.cs ) to dynamically set the GO object for MoveObjPlayableAsset when running.

First, we change the track name to PlayableTrackTest1, because the following code needs to get the track object by name.

Hang the Runner.cs script on the Timeline object, and assign the Timeline variable and the Cube variable, as follows

 Runner.cs code is as follows:
 

using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;

public class Runner : MonoBehaviour
{
    public PlayableDirector timelinePlayer;
    public GameObject cube;

    void Start()
    {
        var timeline = timelinePlayer.playableAsset;
        foreach (var binding in timeline.outputs)
        {
            // 轨道名
            var trackName = binding.streamName;
            if ("PlayableTrackTest1" == trackName)
            {
                // 轨道
                var track = binding.sourceObject as TrackAsset;
                // 轨道上的片段,每个片段都是PlayableAsset的子类
                var clipList = track.GetClips();
                foreach (var clip in clipList)
                {
                    if (clip.asset is MoveObjPlayableAsset)
                    {
                        var moveObjPlableAsset = clip.asset as MoveObjPlayableAsset;
                        // 动态设置go对象的坐标
                        moveObjPlableAsset.go = cube;
                        moveObjPlableAsset.pos = new Vector3(-4.91f, 0, 0);
                        break;
                    }
                }
            }
        }
    }
}

 Recorder Track

 Start the project directly to record, and the recorded path will be displayed on the Inspector panel

The output is as follows
 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/jiuzhouhi/article/details/131208696