Apply() public method

Applies all the animation's timelines to the specified skeleton.
public Apply ( Skeleton skeleton, float lastTime, float time, bool loop, ExposedList events, float alpha, bool setupPose, bool mixingOut ) : void
skeleton Skeleton The skeleton to be posed.
lastTime float The last time the animation was applied.
time float The point in time in the animation to apply to the skeleton.
loop bool If true, time wraps within the animation duration.
events ExposedList Any triggered events are added. May be null.
alpha float The percentage between this animation's pose and the current pose.
setupPose bool If true, the animation is mixed with the setup pose, else it is mixed with the current pose. Passing true when alpha is 1 is slightly more efficient.
mixingOut bool True when mixing over time toward the setup or current pose, false when mixing toward the keyed pose. Irrelevant when alpha is 1.
return void
Ejemplo n.º 1
0
    public void SetGaugePercent(float x)
    {
        if (skeletonRenderer == null)
        {
            return;
        }
        var skeleton = skeletonRenderer.skeleton; if (skeleton == null)

        {
            return;
        }

        // Make super-sure that fillAnimation isn't null. Early exit if it is.
        if (fillAnimation == null)
        {
            fillAnimation = skeleton.Data.FindAnimation(fillAnimationName);
            if (fillAnimation == null)
            {
                return;
            }
        }

        fillAnimation.Apply(skeleton, 0, x, false, null);

        skeleton.Update(Time.deltaTime);
        skeleton.UpdateWorldTransform();
    }
Ejemplo n.º 2
0
        public static void PoseWithAnimation(this Skeleton skeleton, string animationName, float time, bool loop = false)
        {
            Animation animation = skeleton.data.FindAnimation(animationName);

            if (animation != null)
            {
                animation.Apply(skeleton, 0f, time, loop, null, 1f, MixPose.Setup, MixDirection.In);
            }
        }
 public void PreviewEditModePose(Playable playable, SkeletonAnimation spineComponent)
 {
     if (!Application.isPlaying && (spineComponent != null))
     {
         int inputCount = playable.GetInputCount <Playable>();
         int inputPort  = -1;
         for (int i = 0; i < inputCount; i++)
         {
             if (playable.GetInputWeight <Playable>(i) >= 1f)
             {
                 inputPort = i;
             }
         }
         if (inputPort != -1)
         {
             ScriptPlayable <SpineAnimationStateBehaviour> input = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput <Playable>(inputPort);
             SpineAnimationStateBehaviour behaviour = input.GetBehaviour();
             Skeleton skeleton = spineComponent.Skeleton;
             if ((behaviour.animationReference != null) && (spineComponent.SkeletonDataAsset.GetSkeletonData(true) != behaviour.animationReference.SkeletonDataAsset.GetSkeletonData(true)))
             {
                 object[] args = new object[] { spineComponent.SkeletonDataAsset, behaviour.animationReference.SkeletonDataAsset };
                 Debug.LogWarningFormat("SpineAnimationStateMixerBehaviour tried to apply an animation for the wrong skeleton. Expected {0}. Was {1}", args);
             }
             Spine.Animation from = null;
             float           time = 0f;
             bool            loop = false;
             if ((inputPort != 0) && (inputCount > 1))
             {
                 ScriptPlayable <SpineAnimationStateBehaviour> playable3 = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput <Playable>((inputPort - 1));
                 SpineAnimationStateBehaviour behaviour2 = playable3.GetBehaviour();
                 from = behaviour2.animationReference.Animation;
                 time = (float)playable3.GetTime <ScriptPlayable <SpineAnimationStateBehaviour> >();
                 loop = behaviour2.loop;
             }
             Spine.Animation animation   = behaviour.animationReference.Animation;
             float           num6        = (float)input.GetTime <ScriptPlayable <SpineAnimationStateBehaviour> >();
             float           mixDuration = behaviour.mixDuration;
             if (!behaviour.customDuration && (from != null))
             {
                 mixDuration = spineComponent.AnimationState.Data.GetMix(from, animation);
             }
             if (((from != null) && (mixDuration > 0f)) && (num6 < mixDuration))
             {
                 skeleton.SetToSetupPose();
                 float alpha = 1f - (num6 / mixDuration);
                 alpha = (alpha <= 0.5f) ? (alpha * 2f) : 1f;
                 from.Apply(skeleton, 0f, time, loop, null, alpha, MixPose.Setup, MixDirection.Out);
                 animation.Apply(skeleton, 0f, num6, behaviour.loop, null, num6 / mixDuration, MixPose.Current, MixDirection.In);
             }
             else
             {
                 skeleton.SetToSetupPose();
                 animation.PoseSkeleton(skeleton, num6, behaviour.loop);
             }
         }
     }
 }
Ejemplo n.º 4
0
 /// <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, MixPose.Setup, MixDirection.In);
 }
Ejemplo n.º 5
0
        public static void PoseWithAnimation(this Skeleton skeleton, string animationName, float time, bool loop)
        {
            Animation animation = skeleton.data.FindAnimation(animationName);

            if (animation == null)
            {
                return;
            }
            animation.Apply(skeleton, 0f, time, loop, null);
        }
Ejemplo n.º 6
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            time += gameTime.ElapsedGameTime.Milliseconds / 1000f;
            animation.Apply(skeleton, time, true);
            skeleton.UpdateWorldTransform();
            skeletonRenderer.Begin();
            skeletonRenderer.Draw(skeleton);
            skeletonRenderer.End();

            base.Draw(gameTime);
        }
Ejemplo n.º 7
0
    void Update()
    {
        var skeleton = skeletonRenderer.skeleton;

        if (skeleton == null)
        {
            return;
        }

        if (fillAnimation == null)
        {
            fillAnimation = skeleton.Data.FindAnimation(fillAnimationName);
            if (fillAnimation == null)
            {
                return;
            }
        }

        fillAnimation.Apply(skeleton, 0, fill, false, null);
        skeleton.Update(Time.deltaTime);
        skeleton.UpdateWorldTransform();
    }
Ejemplo n.º 8
0
 public void Apply(Skeleton skeleton)
 {
     if (Animation == null)
     {
         return;
     }
     if (previous != null)
     {
         previous.Apply(skeleton, previousTime, previousLoop);
         float alpha = mixTime / mixDuration;
         if (alpha >= 1)
         {
             alpha    = 1;
             previous = null;
         }
         Animation.Mix(skeleton, Time, Loop, alpha);
     }
     else
     {
         Animation.Apply(skeleton, Time, Loop);
     }
 }
Ejemplo n.º 9
0
 static int Apply(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 9);
         Spine.Animation obj  = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 1);
         Spine.Skeleton  arg0 = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 2);
         float           arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
         float           arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
         bool            arg3 = LuaDLL.luaL_checkboolean(L, 5);
         Spine.ExposedList <Spine.Event> arg4 = (Spine.ExposedList <Spine.Event>)ToLua.CheckObject <Spine.ExposedList <Spine.Event> >(L, 6);
         float              arg5 = (float)LuaDLL.luaL_checknumber(L, 7);
         Spine.MixPose      arg6 = (Spine.MixPose)ToLua.CheckObject(L, 8, typeof(Spine.MixPose));
         Spine.MixDirection arg7 = (Spine.MixDirection)ToLua.CheckObject(L, 9, typeof(Spine.MixDirection));
         obj.Apply(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 10
0
        protected void TrySetAnimation(Object o, bool multi)
        {
            var skeletonAnimation = o as SkeletonAnimation;

            if (skeletonAnimation == null)
            {
                return;
            }
            if (!skeletonAnimation.valid)
            {
                return;
            }

            if (!isInspectingPrefab)
            {
                if (wasAnimationNameChanged)
                {
                    if (modify_check_count <= 0)
                    {
                        modify_check_count = 3;
                    }

                    if (!Application.isPlaying)
                    {
                        if (skeletonAnimation.state != null)
                        {
                            skeletonAnimation.state.ClearTrack(0);
                        }
                        skeletonAnimation.skeleton.SetToSetupPose();
                    }

                    string lastAnimation = "";
                    if (skeletonAnimation.state != null && skeletonAnimation.state.GetCurrent(0) != null)
                    {
                        lastAnimation = skeletonAnimation.state.GetCurrent(0).Animation.Name;
                    }

                    Spine.Animation animationToUse = skeletonAnimation.skeleton.Data.FindAnimation(animationName.stringValue);

                    if (!Application.isPlaying)
                    {
                        if (animationToUse != null)
                        {
                            animationToUse.Apply(skeletonAnimation.skeleton, 0f, 0f, false, null, 1f, true, false);
                        }
                        skeletonAnimation.Update();
                        skeletonAnimation.LateUpdate();
                        requireRepaint = true;
                    }
                    else
                    {
                        if (animationToUse != null)
                        {
                            skeletonAnimation.state.SetAnimation(0, animationToUse, loop.boolValue);
                        }
                        else
                        {
                            skeletonAnimation.state.ClearTrack(0);
                        }
                    }

                    if (lastAnimation != animationName.stringValue || modify_check_count-- < 0)
                    {
                        wasAnimationNameChanged = false;
                        modify_check_count      = 0;
                    }
                }

                // Reflect animationName serialized property in the inspector even if SetAnimation API was used.
                if (!multi && Application.isPlaying)
                {
                    TrackEntry current = skeletonAnimation.state.GetCurrent(0);
                    if (current != null)
                    {
                        if (skeletonAnimation.AnimationName != animationName.stringValue)
                        {
                            animationName.stringValue = current.Animation.Name;
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>Resets Skeleton parts to Setup Pose according to a Spine.Animation's keyed items.</summary>
 public static void SetKeyedItemsToSetupPose(this Animation animation, Skeleton skeleton)
 {
     animation.Apply(skeleton, 0, 0, false, null, 0, MixPose.Setup, MixDirection.Out);
 }
Ejemplo n.º 12
0
 /// <summary>Pose a skeleton according to a given time in an animation.</summary>
 public static void PoseSkeleton(this Animation animation, Skeleton skeleton, float time, bool loop = false)
 {
     animation.Apply(skeleton, 0, time, loop, null, 1f, MixPose.Setup, MixDirection.In);
 }
Ejemplo n.º 13
0
		static void BakeBone (Bone bone, Spine.Animation animation, AnimationClip clip) {
			Skeleton skeleton = bone.Skeleton;
			bool inheritRotation = bone.Data.TransformMode.InheritsRotation();

			animation.Apply(skeleton, 0, 0, true, null, 1f, true, false);
			skeleton.UpdateWorldTransform();
			float duration = animation.Duration;

			AnimationCurve curve = new AnimationCurve();

			List<Keyframe> keys = new List<Keyframe>();

			float rotation = bone.AppliedRotation;
			if (!inheritRotation)
				rotation = GetUninheritedRotation(bone);

			keys.Add(new Keyframe(0, rotation, 0, 0));

			int listIndex = 1;

			float r = rotation;

			int steps = Mathf.CeilToInt(duration / bakeIncrement);

			float currentTime = 0;
			float lastTime = 0;
			float angle = rotation;

			for (int i = 1; i <= steps; i++) {
				currentTime += bakeIncrement;
				if (i == steps)
					currentTime = duration;

				animation.Apply(skeleton, lastTime, currentTime, true, null, 1f, true, false);
				skeleton.UpdateWorldTransform();

				int pIndex = listIndex - 1;

				Keyframe pk = keys[pIndex];

				pk = keys[pIndex];

				if (inheritRotation)
					rotation = bone.AppliedRotation;
				else {
					rotation = GetUninheritedRotation(bone);
				}

				angle += Mathf.DeltaAngle(angle, rotation);

				r = angle;

				float rOut = (r - pk.value) / (currentTime - pk.time);

				pk.outTangent = rOut;

				keys.Add(new Keyframe(currentTime, r, rOut, 0));

				keys[pIndex] = pk;

				listIndex++;
				lastTime = currentTime;
			}

			curve = EnsureCurveKeyCount(new AnimationCurve(keys.ToArray()));

			string path = GetPath(bone.Data);
			string propertyName = "localEulerAnglesBaked";

			EditorCurveBinding xBind = EditorCurveBinding.FloatCurve(path, typeof(Transform), propertyName + ".x");
			AnimationUtility.SetEditorCurve(clip, xBind, new AnimationCurve());
			EditorCurveBinding yBind = EditorCurveBinding.FloatCurve(path, typeof(Transform), propertyName + ".y");
			AnimationUtility.SetEditorCurve(clip, yBind, new AnimationCurve());
			EditorCurveBinding zBind = EditorCurveBinding.FloatCurve(path, typeof(Transform), propertyName + ".z");
			AnimationUtility.SetEditorCurve(clip, zBind, curve);
		}
Ejemplo n.º 14
0
 /// <summary>Resets Skeleton parts to Setup Pose according to a Spine.Animation's keyed items.</summary>
 public static void SetKeyedItemsToSetupPose(this Animation animation, Skeleton skeleton)
 {
     animation.Apply(skeleton, 0, 0, false, null, 0, true, true);
 }
Ejemplo n.º 15
0
 public static void Apply(this Spine.Animation animation, Skeleton skeleton, float lastTime, float time, bool loop, ExposedList <Event> events)
 {
     animation.Apply(skeleton, lastTime, time, loop, events, 1f, false, false);
 }
Ejemplo n.º 16
0
        protected override void DrawInspectorGUI()
        {
            base.DrawInspectorGUI();

            SkeletonAnimation component = (SkeletonAnimation)target;

            if (!component.valid)
            {
                return;
            }

            if (wasAnimationNameChanged)
            {
                if (!Application.isPlaying)
                {
                    if (component.state != null)
                    {
                        component.state.ClearTrack(0);
                    }
                    component.skeleton.SetToSetupPose();
                }

                Spine.Animation animationToUse = component.skeleton.Data.FindAnimation(animationName.stringValue);

                if (!Application.isPlaying)
                {
                    if (animationToUse != null)
                    {
                        animationToUse.Apply(component.skeleton, 0f, 0f, false, null);
                    }
                    component.Update();
                    component.LateUpdate();
                    SceneView.RepaintAll();
                }
                else
                {
                    if (animationToUse != null)
                    {
                        component.state.SetAnimation(0, animationToUse, loop.boolValue);
                    }
                    else
                    {
                        component.state.ClearTrack(0);
                    }
                }

                wasAnimationNameChanged = false;
            }

            // Reflect animationName serialized property in the inspector even if SetAnimation API was used.
            if (Application.isPlaying)
            {
                TrackEntry current = component.state.GetCurrent(0);
                if (current != null)
                {
                    if (component.AnimationName != animationName.stringValue)
                    {
                        animationName.stringValue = current.Animation.Name;
                    }
                }
            }

            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(animationName);
            wasAnimationNameChanged |= EditorGUI.EndChangeCheck();

            EditorGUILayout.PropertyField(loop);
            EditorGUILayout.PropertyField(timeScale);
            component.timeScale = Math.Max(component.timeScale, 0);

            EditorGUILayout.Space();

            if (!m_isPrefab)
            {
                if (component.GetComponent <SkeletonUtility>() == null)
                {
                    if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30)))
                    {
                        component.gameObject.AddComponent <SkeletonUtility>();
                    }
                }
            }
        }
Ejemplo n.º 17
0
        protected void TrySetAnimation(Object o)
        {
            var skeletonAnimation = o as SkeletonAnimation;

            if (skeletonAnimation == null)
            {
                return;
            }
            if (!skeletonAnimation.valid)
            {
                return;
            }

            if (!isInspectingPrefab)
            {
                if (wasAnimationNameChanged)
                {
                    if (!Application.isPlaying)
                    {
                        if (skeletonAnimation.state != null)
                        {
                            skeletonAnimation.state.ClearTrack(0);
                        }
                        skeletonAnimation.skeleton.SetToSetupPose();
                    }

                    Spine.Animation animationToUse = skeletonAnimation.skeleton.Data.FindAnimation(animationName.stringValue);

                    if (!Application.isPlaying)
                    {
                        if (animationToUse != null)
                        {
                            animationToUse.Apply(skeletonAnimation.skeleton, 0f, 0f, false, null);
                        }
                        skeletonAnimation.Update();
                        skeletonAnimation.LateUpdate();
                        requireRepaint = true;
                    }
                    else
                    {
                        if (animationToUse != null)
                        {
                            skeletonAnimation.state.SetAnimation(0, animationToUse, loop.boolValue);
                        }
                        else
                        {
                            skeletonAnimation.state.ClearTrack(0);
                        }
                    }

                    wasAnimationNameChanged = false;
                }

                // Reflect animationName serialized property in the inspector even if SetAnimation API was used.
                bool multi = animationName.serializedObject.isEditingMultipleObjects;
                if (!multi && Application.isPlaying)
                {
                    TrackEntry current = skeletonAnimation.state.GetCurrent(0);
                    if (current != null)
                    {
                        if (skeletonAnimation.AnimationName != animationName.stringValue)
                        {
                            animationName.stringValue = current.Animation.Name;
                        }
                    }
                }
            }
        }