public override bool Stop() { if (!IsRunning) { return(false); } stopCalled = true; for (var i = 0; i < targetSkeletons.Length; ++i) { Spine.Animation anim = targetSkeletons[i].skeleton.Data.FindAnimation(animationName.value); if (anim == null || anim != targetSkeletons[i].state.GetCurrent(trackNumber.value).Animation) // chosen animation not playing { continue; } if (resetPoseOnStop.value) { targetSkeletons[i].AnimationState.SetEmptyAnimation(trackNumber.value, 0); } else { targetSkeletons[i].AnimationState.ClearTrack(trackNumber.value); } } return(base.Stop()); }
public KeyValuePair <Spine.Animation, float> GetActiveAnimationAndTime(int layer) { if (layer >= layerClipInfos.Length) { return(new KeyValuePair <Spine.Animation, float>(null, 0)); } var layerInfos = layerClipInfos[layer]; bool isInterruptionActive = layerInfos.isInterruptionActive; AnimationClip clip = null; Spine.Animation animation = null; AnimatorStateInfo stateInfo; if (isInterruptionActive && layerInfos.interruptingClipInfoCount > 0) { clip = layerInfos.interruptingClipInfos[0].clip; stateInfo = layerInfos.interruptingStateInfo; } else { clip = layerInfos.clipInfos[0].clip; stateInfo = layerInfos.stateInfo; } animation = GetAnimation(clip); float time = AnimationTime(stateInfo.normalizedTime, clip.length, clip.isLooping, stateInfo.speed < 0); return(new KeyValuePair <Animation, float>(animation, time)); }
public void SetGaugePercent(float percent) { if (skeletonRenderer == null) { return; } var skeleton = skeletonRenderer.skeleton; if (skeleton == null) { return; } // Make super-sure that fillAnimation isn't null. if (fillAnimation == null) { fillAnimation = skeleton.Data.FindAnimation(fillAnimationName); if (fillAnimation == null) { return; } } fillAnimation.Apply(skeleton, 0, percent, false, null, 1f, MixPose.Setup, MixDirection.In); skeleton.Update(Time.deltaTime); skeleton.UpdateWorldTransform(); }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { CacheAnimator(animator); float blendTime = 0.0f; if (animator.IsInTransition(layerIndex)) { AnimatorTransitionInfo trans = animator.GetAnimatorTransitionInfo(layerIndex); switch (trans.durationUnit) { case DurationUnit.Fixed: { blendTime = trans.duration; } break; case DurationUnit.Normalized: { Animation animation = _animator.GetChannelPrimaryAnimation(layerIndex); blendTime = trans.duration * (animation != null ? animation.Duration : 0.0f); } break; } } StartAnimation(stateInfo, layerIndex, blendTime); }
protected void OnChangeSpine(string propertyName) { if (_spineAnimation == null) { return; } if (propertyName == "color") { _spineAnimation.skeleton.R = _color.r; _spineAnimation.skeleton.G = _color.g; _spineAnimation.skeleton.B = _color.b; return; } var skeletonData = _spineAnimation.skeleton.Data; var state = _spineAnimation.AnimationState; Spine.Animation animationToUse = !string.IsNullOrEmpty(_animationName) ? skeletonData.FindAnimation(_animationName) : null; if (animationToUse != null) { var trackEntry = state.GetCurrent(0); if (trackEntry == null || trackEntry.Animation.Name != _animationName || trackEntry.IsComplete && !trackEntry.Loop) { trackEntry = state.SetAnimation(0, animationToUse, _loop); } else { trackEntry.Loop = _loop; } if (_playing) { trackEntry.TimeScale = 1; } else { trackEntry.TimeScale = 0; trackEntry.TrackTime = Mathf.Lerp(0, trackEntry.AnimationEnd - trackEntry.AnimationStart, _frame / 100f); } } else { state.ClearTrack(0); } var skin = !string.IsNullOrEmpty(skinName) ? skeletonData.FindSkin(skinName) : skeletonData.DefaultSkin; if (skin == null && skeletonData.Skins.Count > 0) { skin = skeletonData.Skins.Items[0]; } if (_spineAnimation.skeleton.Skin != skin) { _spineAnimation.skeleton.SetSkin(skin); _spineAnimation.skeleton.SetSlotsToSetupPose(); } }
public override void Init() { m_lastStatus = RoleStatus.None; m_animationState = m_dock.Anime.AnimationState; m_skeleton = m_dock.Anime.skeleton; m_hangAnime = m_skeleton.Data.FindAnimation(m_dock.HangAnimeName); m_moveAnime = m_skeleton.Data.FindAnimation(m_dock.MoveAnimeName); m_landAnime = m_skeleton.Data.FindAnimation(m_dock.LandAnimeName); }
/// <summary> /// Shortcut for posing a skeleton at a specific time. Time is in seconds. (frameNumber / 30f) will give you seconds. /// If you need to do this often, you should get the Animation object yourself using skeleton.data.FindAnimation. and call Apply on that.</summary> /// <param name = "skeleton">The skeleton to pose.</param> /// <param name="animationName">The name of the animation to use.</param> /// <param name = "time">The time of the pose within the animation.</param> /// <param name = "loop">Wraps the time around if it is longer than the duration of the animation.</param> public static void PoseWithAnimation(this Skeleton skeleton, string animationName, float time, bool loop = false) { // Fail loud when skeleton.data is null. Spine.Animation animation = skeleton.data.FindAnimation(animationName); if (animation == null) { return; } animation.Apply(skeleton, 0, time, loop, null, 1f, MixBlend.Setup, MixDirection.In); }
void DoExtraStuff(SkeletonAnimation sa, Spine.Animation spineAnimation) { sa.transform.localPosition = Random.insideUnitCircle * 6f; sa.transform.SetParent(this.transform, false); if (spineAnimation != null) { sa.Initialize(false); sa.AnimationState.SetAnimation(0, spineAnimation, true); } }
public float GetAnimTime(string animName) { Spine.Animation animationToUse = m_SkeletonAnimation.skeleton.Data.FindAnimation(animName); if (animationToUse != null) { return(animationToUse.duration / m_SkeletonAnimation.timeScale); } return(0f); }
private void OnClipAppliedCallback(Spine.Animation clip, AnimatorStateInfo stateInfo, int layerIndex, float time, bool isLooping, float weight) { float speedFactor = stateInfo.speedMultiplier * stateInfo.speed; float lastTime = time - (Time.deltaTime * speedFactor); if (isLooping && clip.duration != 0) { time %= clip.duration; lastTime %= clip.duration; } _OnClipApplied(clip, layerIndex, weight, time, lastTime, speedFactor < 0); }
public void SetSpinePlayAnim(string animName, bool isLoop = true, float speed = 1f) { Spine.Animation animationToUse = m_SkeletonAnimation.skeleton.Data.FindAnimation(animName); if (animationToUse != null) { m_SkeletonAnimation.state.SetAnimation(0, animationToUse, isLoop); } else { m_SkeletonAnimation.state.ClearTrack(0); } m_SkeletonAnimation.timeScale = speed; }
public Animation GetChannelPrimaryAnimation(int channel) { for (int i = 0; i < _renderer._animationSets.Length; i++) { Animation animation = _renderer._animationSets[i]._animatior.GetChannelPrimaryAnimation(channel); if (animation != null) { return(animation); } } return(null); }
/// <summary>播放一次非循环动画,然后继续播放状态动画。</summary> public void PlayOneShot(Spine.Animation oneShot, int layerIndex) { var state = skeletonAnimation.AnimationState; state.SetAnimation(0, oneShot, false); // 播放一次动画 var transition = TryGetTransition(oneShot, TargetAnimation); if (transition != null) { state.AddAnimation(0, transition, false, 0f); // 播放过度动画 } state.AddAnimation(0, this.TargetAnimation, true, 0f); // 播放目标动画 }
Spine.Animation TryGetTransition(Spine.Animation from, Spine.Animation to) { foreach (var transition in transitions) { if (transition.from.Animation == from && transition.to.Animation == to) { return(transition.transition.Animation); } } return(null); //Spine.Animation foundTransition = null; //transitionDictionary.TryGetValue(new AnimationStateData.AnimationPair(from, to), out foundTransition); //return foundTransition; }
public void SetGaugePercent (float percent) { if (skeletonRenderer == null) return; var skeleton = skeletonRenderer.skeleton; if (skeleton == null) return; // Make super-sure that fillAnimation isn't null. if (fillAnimation == null) { fillAnimation = skeleton.Data.FindAnimation(fillAnimationName); if (fillAnimation == null) return; } fillAnimation.Apply(skeleton, 0, percent, false, null, 1f, true, false); skeleton.Update(Time.deltaTime); skeleton.UpdateWorldTransform(); }
public void Reset() { this.next = null; this.mixingFrom = null; this.animation = null; this.timelineData.Clear(true); this.timelineDipMix.Clear(true); this.timelinesRotation.Clear(true); this.Start = null; this.Interrupt = null; this.End = null; this.Dispose = null; this.Complete = null; this.Event = null; }
void OnClipApplied(Spine.Animation animation, int layerIndex, float weight, float time, float lastTime, bool playsBackward) { if (((mecanimLayerFlags & 1 << layerIndex) == 0) || weight == 0) { return; } if (!playsBackward) { movementDelta += weight * GetAnimationRootMotion(lastTime, time, animation); } else { movementDelta -= weight * GetAnimationRootMotion(time, lastTime, animation); } }
void OnClipApplied(Spine.Animation clip, int layerIndex, float weight, float time, float lastTime, bool playsBackward) { if (((mecanimLayerFlags & 1 << layerIndex) == 0) || weight == 0) { return; } var timeline = clip.FindTranslateTimelineForBone(rootMotionBoneIndex); if (timeline != null) { if (!playsBackward) { movementDelta += weight * GetTimelineMovementDelta(lastTime, time, timeline, clip); } else { movementDelta -= weight * GetTimelineMovementDelta(time, lastTime, timeline, clip); } } }
/// <summary>播放动画。如果定义了过渡动画,则在播放目标动画之前播放过渡动画。</summary> public void PlayNewAnimation(Spine.Animation target, int layerIndex) { Spine.Animation transition = null; // 过度动画 Spine.Animation current = null; // 当前动画 current = GetCurrentAnimation(layerIndex); if (current != null) { transition = TryGetTransition(current, target); // 设置过度动画 } if (transition != null) // 有过度动画 { skeletonAnimation.AnimationState.SetAnimation(layerIndex, transition, false); // 播放过度动画 skeletonAnimation.AnimationState.AddAnimation(layerIndex, target, true, 0f); // 添加目标动画在过渡动画之后 } else // 无过度动画 { skeletonAnimation.AnimationState.SetAnimation(layerIndex, target, true); // 播放目标动画 } this.TargetAnimation = target; // 更新目标动画 }
/// <summary>Play an animation. If a transition animation is defined, the transition is played before the target animation being passed.</summary> public void PlayNewAnimation(Spine.Animation target, int layerIndex) { Spine.Animation transition = null; Spine.Animation current = null; current = GetCurrentAnimation(layerIndex); if (current != null) { transition = TryGetTransition(current, target); } if (transition != null) { skeletonAnimation.AnimationState.SetAnimation(layerIndex, transition, false); skeletonAnimation.AnimationState.AddAnimation(layerIndex, target, true, 0f); } else { skeletonAnimation.AnimationState.SetAnimation(layerIndex, target, true); } this.TargetAnimation = target; }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { var trackBinding = playerData as SkeletonAnimation; if (trackBinding == null) { return; } if (!Application.isPlaying) { #if SPINE_EDITMODEPOSE PreviewEditModePose(playable, trackBinding); #endif return; } int inputCount = playable.GetInputCount(); if (this.lastInputWeights == null || this.lastInputWeights.Length < inputCount) { this.lastInputWeights = new float[inputCount]; for (int i = 0; i < inputCount; i++) { this.lastInputWeights[i] = 0f; } } var lastInputWeights = this.lastInputWeights; for (int i = 0; i < inputCount; i++) { float lastInputWeight = lastInputWeights[i]; float inputWeight = playable.GetInputWeight(i); bool trackStarted = inputWeight > lastInputWeight; lastInputWeights[i] = inputWeight; if (trackStarted) { ScriptPlayable <SpineAnimationStateBehaviour> inputPlayable = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(i); SpineAnimationStateBehaviour input = inputPlayable.GetBehaviour(); Spine.Animation animation = trackBinding.Skeleton.Data.FindAnimation(input.animationName); if (animation != null) { Spine.TrackEntry trackEntry = trackBinding.AnimationState.SetAnimation(0, input.animationName, input.loop); trackEntry.EventThreshold = input.eventThreshold; trackEntry.DrawOrderThreshold = input.drawOrderThreshold; trackEntry.AttachmentThreshold = input.attachmentThreshold; if (input.customDuration) { trackEntry.MixDuration = input.mixDuration; } } else if (string.IsNullOrEmpty(input.animationName)) { float mixDuration = input.customDuration ? input.mixDuration : trackBinding.AnimationState.Data.DefaultMix; trackBinding.AnimationState.SetEmptyAnimation(0, mixDuration); continue; } // else { // Debug.LogWarningFormat("Animation named '{0}' not found", input.animationName); // } } } }