();
animationState.Init(this._armature, animationData, animationConfig);
this._animationDirty = true;
this._armature._cacheFrameIndex = -1;
if (this._animationStates.Count > 0)
{
var added = false;
for (int i = 0, l = this._animationStates.Count; i < l; ++i)
{
if (animationState.layer > this._animationStates[i].layer)
{
added = true;
this._animationStates.Insert(i, animationState);
break;
}
else if (i != l - 1 && animationState.layer > this._animationStates[i + 1].layer)
{
added = true;
this._animationStates.Insert(i + 1, animationState);
break;
}
}
if (!added)
{
this._animationStates.Add(animationState);
}
}
else
{
this._animationStates.Add(animationState);
}
// Child armature play same name animation.
foreach (var slot in this._armature.GetSlots())
{
var childArmature = slot.childArmature;
if (childArmature != null &&
childArmature.inheritAnimation &&
childArmature.animation.HasAnimation(animationName) &&
childArmature.animation.GetState(animationName) == null)
{
childArmature.animation.FadeIn(animationName); //
}
}
if (!this._lockUpdate)
{
if (animationConfig.fadeInTime <= 0.0f)
{
// Blend animation state, update armature.
this._armature.AdvanceTime(0.0f);
}
}
this._lastAnimationState = animationState;
return animationState;
}
///
/// - Play a specific animation.
///
/// - The name of animation data. (If not set, The default animation will be played, or resume the animation playing from pause status, or replay the last playing animation)
/// - Playing repeat times. [-1: Use default value of the animation data, 0: No end loop playing, [1~N]: Repeat N times] (default: -1)
/// The playing animation state.
///
/// TypeScript style, for reference only.
///
/// armature.animation.play("walk");
///
///
/// DragonBones 3.0
/// en_US
///
/// - 播放指定动画。
///
/// - 动画数据名称。 (如果未设置,则播放默认动画,或将暂停状态切换为播放状态,或重新播放之前播放的动画)
/// - 循环播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)
/// 播放的动画状态。
///
/// TypeScript 风格,仅供参考。
///
/// armature.animation.play("walk");
///
///
/// DragonBones 3.0
/// zh_CN
public AnimationState Play(string animationName = null, int playTimes = -1)
{
this._animationConfig.Clear();
this._animationConfig.resetToPose = true;
this._animationConfig.playTimes = playTimes;
this._animationConfig.fadeInTime = 0.0f;
this._animationConfig.animation = animationName != null ? animationName : "";
if (animationName != null && animationName.Length > 0)
{
this.PlayConfig(this._animationConfig);
}
else if (this._lastAnimationState == null)
{
var defaultAnimation = this._armature.armatureData.defaultAnimation;
if (defaultAnimation != null)
{
this._animationConfig.animation = defaultAnimation.name;
this.PlayConfig(this._animationConfig);
}
}
else if (!this._lastAnimationState.isPlaying && !this._lastAnimationState.isCompleted)
{
this._lastAnimationState.Play();
}
else
{
this._animationConfig.animation = this._lastAnimationState.name;
this.PlayConfig(this._animationConfig);
}
return this._lastAnimationState;
}
///
/// - Fade in a specific animation.
///
/// - The name of animation data.
/// - The fade in time. [-1: Use the default value of animation data, [0~N]: The fade in time (In seconds)] (Default: -1)
/// - playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
/// - The blending layer, the animation states in high level layer will get the blending weights with high priority, when the total blending weights are more than 1.0, there will be no more weights can be allocated to the other animation states. (Default: 0)
/// - The blending group name, it is typically used to specify the substitution of multiple animation states blending. (Default: null)
/// - The fade out mode, which is typically used to specify alternate mode of multiple animation states blending. (Default: AnimationFadeOutMode.SameLayerAndGroup)
/// The playing animation state.
///
/// TypeScript style, for reference only.
///
/// armature.animation.fadeIn("walk", 0.3, 0, 0, "normalGroup").resetToPose = false;
/// armature.animation.fadeIn("attack", 0.3, 1, 0, "attackGroup").resetToPose = false;
///
///
/// DragonBones 4.5
/// en_US
///
/// - 淡入播放指定的动画。
///
/// - 动画数据名称。
/// - 淡入时间。 [-1: 使用动画数据默认值, [0~N]: 淡入时间 (以秒为单位)] (默认: -1)
/// - 播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)
/// - 混合图层,图层高的动画状态会优先获取混合权重,当混合权重分配总和超过 1.0 时,剩余的动画状态将不能再获得权重分配。 (默认: 0)
/// - 混合组名称,该属性通常用来指定多个动画状态混合时的相互替换关系。 (默认: null)
/// - 淡出模式,该属性通常用来指定多个动画状态混合时的相互替换模式。 (默认: AnimationFadeOutMode.SameLayerAndGroup)
/// 播放的动画状态。
///
/// TypeScript 风格,仅供参考。
///
/// armature.animation.fadeIn("walk", 0.3, 0, 0, "normalGroup").resetToPose = false;
/// armature.animation.fadeIn("attack", 0.3, 1, 0, "attackGroup").resetToPose = false;
///
///
/// DragonBones 4.5
/// zh_CN
public AnimationState FadeIn(string animationName, float fadeInTime = -1.0f, int playTimes = -1,
int layer = 0, string group = null,
AnimationFadeOutMode fadeOutMode = AnimationFadeOutMode.SameLayerAndGroup)
{
this._animationConfig.Clear();
this._animationConfig.fadeOutMode = fadeOutMode;
this._animationConfig.playTimes = playTimes;
this._animationConfig.layer = layer;
this._animationConfig.fadeInTime = fadeInTime;
this._animationConfig.animation = animationName;
this._animationConfig.group = group != null ? group : "";
return this.PlayConfig(this._animationConfig);
}
///
/// - Play a specific animation from the specific time.
///
/// - The name of animation data.
/// - The start time point of playing. (In seconds)
/// - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
/// The played animation state.
/// DragonBones 4.5
/// en_US
///
/// - 从指定时间开始播放指定的动画。
///
/// - 动画数据名称。
/// - 播放开始的时间。 (以秒为单位)
/// - 循环播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)
/// 播放的动画状态。
/// DragonBones 4.5
/// zh_CN
public AnimationState GotoAndPlayByTime(string animationName, float time = 0.0f, int playTimes = -1)
{
this._animationConfig.Clear();
this._animationConfig.resetToPose = true;
this._animationConfig.playTimes = playTimes;
this._animationConfig.position = time;
this._animationConfig.fadeInTime = 0.0f;
this._animationConfig.animation = animationName;
return this.PlayConfig(this._animationConfig);
}
///
/// - Play a specific animation from the specific frame.
///
/// - The name of animation data.
/// - The start frame of playing.
/// - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
/// The played animation state.
/// DragonBones 4.5
/// en_US
///
/// - 从指定帧开始播放指定的动画。
///
/// - 动画数据名称。
/// - 播放开始的帧数。
/// - 播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)
/// 播放的动画状态。
/// DragonBones 4.5
/// zh_CN
public AnimationState GotoAndPlayByFrame(string animationName, uint frame = 0, int playTimes = -1)
{
this._animationConfig.Clear();
this._animationConfig.resetToPose = true;
this._animationConfig.playTimes = playTimes;
this._animationConfig.fadeInTime = 0.0f;
this._animationConfig.animation = animationName;
var animationData = this._animations.ContainsKey(animationName) ? this._animations[animationName] : null;
if (animationData != null)
{
this._animationConfig.position = animationData.duration * frame / animationData.frameCount;
}
return this.PlayConfig(this._animationConfig);
}
///
/// - Play a specific animation from the specific progress.
///
/// - The name of animation data.
/// - The start progress value of playing.
/// - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
/// The played animation state.
/// DragonBones 4.5
/// en_US
///
/// - 从指定进度开始播放指定的动画。
///
/// - 动画数据名称。
/// - 开始播放的进度。
/// - 播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)
/// 播放的动画状态。
/// DragonBones 4.5
/// zh_CN
public AnimationState GotoAndPlayByProgress(string animationName, float progress = 0.0f, int playTimes = -1)
{
this._animationConfig.Clear();
this._animationConfig.resetToPose = true;
this._animationConfig.playTimes = playTimes;
this._animationConfig.fadeInTime = 0.0f;
this._animationConfig.animation = animationName;
var animationData = this._animations.ContainsKey(animationName) ? this._animations[animationName] : null;
if (animationData != null)
{
this._animationConfig.position = animationData.duration * (progress > 0.0f ? progress : 0.0f);
}
return this.PlayConfig(this._animationConfig);
}
///
/// - Stop a specific animation at the specific time.
///
/// - The name of animation data.
/// - The stop time. (In seconds)
/// The played animation state.
/// DragonBones 4.5
/// en_US
///
/// - 在指定时间停止指定动画播放
///
/// - 动画数据名称。
/// - 停止的时间。 (以秒为单位)
/// 播放的动画状态。
/// DragonBones 4.5
/// zh_CN
public AnimationState GotoAndStopByTime(string animationName, float time = 0.0f)
{
var animationState = this.GotoAndPlayByTime(animationName, time, 1);
if (animationState != null)
{
animationState.Stop();
}
return animationState;
}
///
/// - Stop a specific animation at the specific frame.
///
/// - The name of animation data.
/// - The stop frame.
/// The played animation state.
/// DragonBones 4.5
/// en_US
///
/// - 在指定帧停止指定动画的播放
///
/// - 动画数据名称。
/// - 停止的帧数。
/// 播放的动画状态。
/// DragonBones 4.5
/// zh_CN
public AnimationState GotoAndStopByFrame(string animationName, uint frame = 0)
{
var animationState = this.GotoAndPlayByFrame(animationName, frame, 1);
if (animationState != null)
{
animationState.Stop();
}
return animationState;
}
///
/// - Stop a specific animation at the specific progress.
///
/// - The name of animation data.
/// - The stop progress value.
/// The played animation state.
/// DragonBones 4.5
/// en_US
///
/// - 在指定的进度停止指定的动画播放。
///
/// - 动画数据名称。
/// - 停止进度。
/// 播放的动画状态。
/// DragonBones 4.5
/// zh_CN
public AnimationState GotoAndStopByProgress(string animationName, float progress = 0.0f)
{
var animationState = this.GotoAndPlayByProgress(animationName, progress, 1);
if (animationState != null)
{
animationState.Stop();
}
return animationState;
}
///
/// - Get a specific animation state.
///
/// - The name of animation state.
///
/// TypeScript style, for reference only.
///
/// armature.animation.play("walk");
/// let walkState = armature.animation.getState("walk");
/// walkState.timeScale = 0.5;
///
///
/// DragonBones 3.0
/// en_US
///
/// - 获取指定的动画状态
///
/// - 动画状态名称。
///
/// TypeScript 风格,仅供参考。
///
/// armature.animation.play("walk");
/// let walkState = armature.animation.getState("walk");
/// walkState.timeScale = 0.5;
///
///
/// DragonBones 3.0
/// zh_CN
public AnimationState GetState(string animationName)
{
var i = this._animationStates.Count;
while (i-- > 0)
{
var animationState = this._animationStates[i];
if (animationState.name == animationName)
{
return animationState;
}
}
return null;
}
///
/// - Check whether a specific animation data is included.
///
/// - The name of animation data.
///
/// DragonBones 3.0
/// en_US
///
/// - 检查是否包含指定的动画数据
///
/// - 动画数据名称。
///
/// DragonBones 3.0
/// zh_CN
public bool HasAnimation(string animationName)
{
return this._animations.ContainsKey(animationName);
}
///
/// - Get all the animation states.
///
/// DragonBones 5.1
/// en_US
///
/// - 获取所有的动画状态
///
/// DragonBones 5.1
/// zh_CN
public List GetStates()
{
return this._animationStates;
}
///
/// - Check whether there is an animation state is playing
///
///
/// DragonBones 3.0
/// en_US
///
/// - 检查是否有动画状态正在播放
///
///
/// DragonBones 3.0
/// zh_CN
public bool isPlaying
{
get
{
foreach (var animationState in this._animationStates)
{
if (animationState.isPlaying)
{
return true;
}
}
return false;
}
}
///
/// - Check whether all the animation states' playing were finished.
///
///
/// DragonBones 3.0
/// en_US
///
/// - 检查是否所有的动画状态均已播放完毕。
///
///
/// DragonBones 3.0
/// zh_CN
public bool isCompleted
{
get
{
foreach (var animationState in this._animationStates)
{
if (!animationState.isCompleted)
{
return false;
}
}
return this._animationStates.Count > 0;
}
}
///
/// - The name of the last playing animation state.
///
///
/// DragonBones 3.0
/// en_US
///
/// - 上一个播放的动画状态名称
///
///
/// DragonBones 3.0
/// zh_CN
public string lastAnimationName
{
get { return this._lastAnimationState != null ? this._lastAnimationState.name : ""; }
}
///
/// - The name of all animation data
///
/// DragonBones 4.5
/// en_US
///
/// - 所有动画数据的名称
///
/// DragonBones 4.5
/// zh_CN
public List animationNames
{
get { return this._animationNames; }
}
///
/// - All animation data.
///
/// DragonBones 4.5
/// en_US
///
/// - 所有的动画数据。
///
/// DragonBones 4.5
/// zh_CN
public Dictionary animations
{
get { return this._animations; }
set
{
if (this._animations == value)
{
return;
}
this._animationNames.Clear();
this._animations.Clear();
foreach (var k in value)
{
this._animationNames.Add(k.Key);
this._animations[k.Key] = value[k.Key];
}
}
}
///
/// - An AnimationConfig instance that can be used quickly.
///
///
/// DragonBones 5.0
/// en_US
///
/// - 一个可以快速使用的动画配置实例。
///
///
/// DragonBones 5.0
/// zh_CN
public AnimationConfig animationConfig
{
get
{
this._animationConfig.Clear();
return this._animationConfig;
}
}
///
/// - The last playing animation state
///
///
/// DragonBones 3.0
/// en_US
///
/// - 上一个播放的动画状态
///
///
/// DragonBones 3.0
/// zh_CN
public AnimationState lastAnimationState
{
get { return this._lastAnimationState; }
}
}
}