AnyPortrait > Script > Animation
You can play the animation as a script.
If you enter the animation clip name as a parameter, it automatically switches to the root unit corresponding to it.
Multiple animation clips can be layered and played simultaneously.
You can give a fade effect when switching animation.
Play the animation clip right away.
Playback starts without waiting time or fade effect.
The PlayAt function allows you to start playback at a specific frame.
string animClipName : Name of Animation clip
apAnimPlayData animPlayData : Target animation data
int frame : The frame you want to start in the PlayAt function
int layer : Layer on which the animation plays (Default is 0)
apAnimPlayUnit.BLEND_METHOD blendMethod : Layered animation blend method (Default is BLEND_METHOD.Interpolation)
apAnimPlayManager.PLAY_OPTION playOption : How to end other animations that are playing (Default is PLAY_OPTION.StopSameLayer)
bool isAutoEndIfNotloop : Whether to terminate automatically if an animation clip has no Loop option (Default is false)
apAnimPlayData : Data of animation clip being played (if no animation clip is requested, null)
When the animation clip played on the currently requested layer ends, it plays immediately.
If no animation is playing on the layer, playback will begin immediately.
If the animation clip being played does not end with the Loop option, the function will not be processed and will be ignored.
The PlayQueuedAt function allows you to start playback at a specific frame.
(Same as Play(), PlayAt() except PLAY_OPTION playOption)
apAnimPlayData : Data of animation clip being played (If the requested animation clip does not exist or is Loop, null)
Animation clips playback including fade effects.
It is similar to the Play function, but with a fade effect as fadeTime, it starts slowly and naturally.
The CrossFadeAt function allows you to start playback at a specific frame.
float fadeTime : The time at which the animated smoothly changing fade effect is applied (Default is 0.3f)
(The rest is the same as the Play(), PlayAt())
apAnimPlayData : Data of animation clip being played (if no animation clip is requested, null)
As with PlayQueued, when the animation being played ends, it plays continuously.
The fade effect is added by fadeTime based on the end time and playback begins.
The CrossFadeAt function allows you to start playback at a specific frame.
(Same as CrossFade(), CrossFadeAt() except PLAY_OPTION playOption)
apAnimPlayData : Data of animation clip being played (If the requested animation clip does not exist or is Loop, null)
Stop all animations on the requested layer.
int layer : Layer to be stopped
float fadeTime : Time at which the animation ends smoothly by fading (Default is 0)
Stop all animations.
float fadeTime : Time at which the animation ends smoothly by fading (Default is 0)
Pause all animations in the requested layer.
int layer : Layer to be paused
Pause all animations.
Plays the paused animations of the requested layer again.
int layer : Layer to be resumed
Plays all paused animations.
Queries if the animation clip you requested is playing.
string animClipName : Target animation clip name
bool : Returns true if the animation is playing (returns false if it is not playing or is not present)
The manager that plays the animation.
Controls playback, stop, etc. from inside.
You can refer to the animated clip information that is baked.
public List<apAnimPlayData> PlayDataList : List containing animated clip information
Registers a listener to receive animation events.
For more information on how to create and invoke animation events, see the related page.
MonoBehaviour listenerObject : The MonoBehaviour object from which the animation event will be invoked
Sets the playback speed of the animation.
The default value is 1.0f, and you can also set a negative number.
Like other functions, it does not work when using mecanim.
If you do not specify animClipName, sets the speed of all animations.
string animClipName : The name of the animation clip for which you want to set the speed. Target all animation clips when not set
float speed : Playback speed ratio. The default is 1.0f
Reverts the playback speed of all animations to their default values.
Returns a list of apAnimPlayData with playback information for the animation.
You can see the playable animation data directly.
List<apAnimPlayData> : A list of playable apAnimPlayData
Queries the apAnimPlayData object with animation playback information by name.
string animClipName : Target animation clip name
apAnimPlayData : A playable apAnimPlayData object. Return null if not
Get the playback status of the animation by the name.
The result value of "None, Playing, Paused, Ended" is returned in Enum format.
Provides more granular state values than the IsPlaying () function.
string animClipName : Target animation clip name
apAnimPlayData.AnimationPlaybackStatus : The playback state of the animation
The values of the Blend Method and Play Option variable, which are included in the playback functions, have the following meanings.
apAnimPlayUnit.BLEND_METHOD blendMethod : Layered animation blend method
BLEND_METHOD.Interpolation : Merges in an overwrite interpolation compared to the animation on the lower layer.
BLEND_METHOD.Additive : Add and merge values to animations in lower layers.
apAnimPlayManager.PLAY_OPTION playOption : How to end another animation that is playing
PLAY_OPTION.StopSameLayer : Stop only the animation of the requested layer.
PLAY_OPTION.StopAllLayers : Stop all animations, including other layers.
The class that is returned when the animation play function is called.
apAnimPlayData has animation playback information.
You can control the speed using the function of the returned apAnimPlayData instance.
Ex) portrait.Play("Idle").SetSpeed(2);
public void SetSpeed(float speed)
: Speed is controlled by speed. The default value is 1.0f, which can be negative.
public AnimationPlaybackStatus PlaybackStatus
: Returns the current playing state. The playback status has the following values.
- AnimationPlaybackStatus.None : The data is invalid or is not currently playing.
- AnimationPlaybackStatus.Playing : It is Playing.
- AnimationPlaybackStatus.Paused : It has been played but is currently paused.
- AnimationPlaybackStatus.Ended : When it is not a loop animation, it is played until the last frame.
public string Name
: The name of the animation clip.
public int CurrentFrame
: This is the current frame being played. It is returned as an integer value, but it is operated as a float value internally. -1 is returned if the animation is not in a valid state.
public int StartFrame
: This is the start frame of this animation. If invalid, -1 is returned.
public int EndFrame
: This is the end frame of this animation. If invalid, -1 is returned.
public float NormalizedTime
: Returns how long the animation has played relative to the total animation length, as a value between 0.0 and 1.0. -1 is returned if this animation is invalid.
using UnityEngine;
using AnyPortrait;
public class AnimationTest : MonoBehaviour
{
// Target AnyPortrait Object
public apPortrait portrait;
void Start () { }
void Update ()
{
// CrossFade "Idle" Animation Clip
if(Input.GetKeyDown(KeyCode.I))
{
if(portrait.CrossFade("Idle", 0.4f) == null)
{
Debug.LogError("Faild [Idle]");
}
Debug.Log("CrossFade [Idle]");
}
// Play "Action" Animation Clip
if(Input.GetKeyDown(KeyCode.A))
{
if(portrait.Play("Action") == null)
{
Debug.LogError("Faild [Action]");
}
Debug.Log("Play [Action]");
}
// Pause Animations in All Layers
if(Input.GetKeyDown(KeyCode.P))
{
portrait.PauseAll();
Debug.Log("Pause All");
}
// Stop Animations in All Layers
if(Input.GetKeyDown(KeyCode.S))
{
portrait.StopAll(0.3f);
Debug.Log("Stop All");
}
// Resume Animations in All Layers
if(Input.GetKeyDown(KeyCode.R))
{
portrait.ResumeAll();
Debug.Log("Resume All");
}
}
}