public static IEnumerator IEPlay(this SkeletonAnimation skeleton, string animationToSet, bool isLoop,
                                         Spine.AnimationState.TrackEntryDelegate OnComplete   = null,
                                         Spine.AnimationState.TrackEntryEventDelegate OnEvent = null)
        {
            TrackEntry trackEntry;

            if (skeleton.AnimationName != animationToSet)
            {
                skeleton.AnimationName = animationToSet;
                skeleton.AnimationState.ClearTrack(0);
                trackEntry = skeleton.AnimationState.SetAnimation(0, animationToSet, isLoop);
            }
            else
            {
                trackEntry = skeleton.AnimationState.AddAnimation(0, animationToSet, isLoop, 0);
            }

            if (OnEvent != null)
            {
                trackEntry.Event += OnEvent;
            }
            if (OnComplete != null)
            {
                trackEntry.Complete += OnComplete;
            }

            yield return(new WaitForSeconds(trackEntry.AnimationTime));
        }
        public static void Play(this SkeletonAnimation skeleton, string animationToSet, bool isLoop,
                                Spine.AnimationState.TrackEntryDelegate OnComplete   = null,
                                Spine.AnimationState.TrackEntryEventDelegate OnEvent = null)
        {
            TrackEntry trackEntry;

            if (skeleton.AnimationName != animationToSet)
            {
                skeleton.AnimationName = animationToSet;
                skeleton.AnimationState.ClearTrack(0);
                trackEntry = skeleton.AnimationState.SetAnimation(0, animationToSet, isLoop);
            }
            else
            {
                trackEntry = skeleton.AnimationState.AddAnimation(0, animationToSet, isLoop, 0f);
            }

            if (OnEvent != null)
            {
                trackEntry.Event += OnEvent;
            }
            if (OnComplete != null)
            {
                trackEntry.Complete += OnComplete;
            }
        }
        public static void PlayFromStart(this SkeletonGraphic skeleton, string animationToSet, bool isLoop,
                                         Spine.AnimationState.TrackEntryDelegate OnComplete   = null,
                                         Spine.AnimationState.TrackEntryEventDelegate OnEvent = null)
        {
            TrackEntry trackEntry;

            if (skeleton.AnimationState != null)
            {
                if (skeleton.Skeleton == null)
                {
                    skeleton.Initialize(true);
                }

                skeleton.startingAnimation = animationToSet;
                skeleton.AnimationState.ClearTrack(0);
                trackEntry = skeleton.AnimationState.SetAnimation(0, animationToSet, isLoop);

                if (OnEvent != null)
                {
                    trackEntry.Event += OnEvent;
                }
                if (OnComplete != null)
                {
                    trackEntry.Complete += OnComplete;
                }
            }
        }
Example #4
0
 void Start()
 {
     skel = GetComponent <SkeletonAnimation>();
     act  = (x) => { Debug.Log("event"); };
     act += (x) => { Debug.Log("Part deux"); };
     skel.AnimationState.Complete += act;
 }
    static int set_Complete(IntPtr L)
    {
        try
        {
            Spine.TrackEntry obj  = (Spine.TrackEntry)ToLua.CheckObject(L, 1, typeof(Spine.TrackEntry));
            EventObject      arg0 = null;

            if (LuaDLL.lua_isuserdata(L, 2) != 0)
            {
                arg0 = (EventObject)ToLua.ToObject(L, 2);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "The event 'Spine.TrackEntry.Complete' can only appear on the left hand side of += or -= when used outside of the type 'Spine.TrackEntry'"));
            }

            if (arg0.op == EventOp.Add)
            {
                Spine.AnimationState.TrackEntryDelegate ev = (Spine.AnimationState.TrackEntryDelegate)arg0.func;
                obj.Complete += ev;
            }
            else if (arg0.op == EventOp.Sub)
            {
                Spine.AnimationState.TrackEntryDelegate ev = (Spine.AnimationState.TrackEntryDelegate)arg0.func;
                obj.Complete -= ev;
            }

            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int set_Dispose(IntPtr L)
    {
        try
        {
            Spine.TrackEntry obj  = (Spine.TrackEntry)ToLua.CheckObject(L, 1, typeof(Spine.TrackEntry));
            EventObject      arg0 = null;

            if (LuaDLL.lua_isuserdata(L, 2) != 0)
            {
                arg0 = (EventObject)ToLua.ToObject(L, 2);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "The event 'Spine.TrackEntry.Dispose' can only appear on the left hand side of += or -= when used outside of the type 'Spine.TrackEntry'"));
            }

            if (arg0.op == EventOp.Add)
            {
                Spine.AnimationState.TrackEntryDelegate ev = (Spine.AnimationState.TrackEntryDelegate)DelegateFactory.CreateDelegate(typeof(Spine.AnimationState.TrackEntryDelegate), arg0.func);
                obj.Dispose += ev;
            }
            else if (arg0.op == EventOp.Sub)
            {
                Spine.AnimationState.TrackEntryDelegate ev = (Spine.AnimationState.TrackEntryDelegate)LuaMisc.GetEventHandler(obj, typeof(Spine.TrackEntry), "Dispose");
                Delegate[] ds    = ev.GetInvocationList();
                LuaState   state = LuaState.Get(L);

                for (int i = 0; i < ds.Length; i++)
                {
                    ev = (Spine.AnimationState.TrackEntryDelegate)ds[i];
                    LuaDelegate ld = ev.Target as LuaDelegate;

                    if (ld != null && ld.func == arg0.func)
                    {
                        obj.Dispose -= ev;
                        state.DelayDispose(ld.func);
                        break;
                    }
                }

                arg0.func.Dispose();
            }

            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #7
0
 public TrackEntry Play(int trackIndex, string animName, bool loop, Spine.AnimationState.TrackEntryDelegate onFinish)
 {
     tempTrackInfo = armature.AnimationState.SetAnimation(trackIndex, animName, loop);
     if (tempTrackInfo != null)
     {
         tempTrackInfo.Complete += onFinish;
     }
     else
     {
         if (onFinish != null)
         {
             onFinish(null);
         }
     }
     return(tempTrackInfo);
 }
        //===============================================================

        #region Skeleton Graphic Animation

        public static void Play(this SkeletonGraphic skeleton, string animationToSet, bool isLoop,
                                Spine.AnimationState.TrackEntryDelegate OnComplete   = null,
                                Spine.AnimationState.TrackEntryEventDelegate OnEvent = null)
        {
            TrackEntry trackEntry;

            if (skeleton.AnimationState != null)
            {
                if (skeleton.Skeleton == null)
                {
                    skeleton.Initialize(true);
                }

                bool hasAnim = false;
                foreach (var anim in skeleton.Skeleton.Data.Animations)
                {
                    if (anim.Name == animationToSet)
                    {
                        hasAnim = true;
                    }
                }
                if (!hasAnim)
                {
                    return;
                }

                if (skeleton.startingAnimation != animationToSet)
                {
                    skeleton.startingAnimation = animationToSet;
                    skeleton.AnimationState.ClearTrack(0);
                    trackEntry = skeleton.AnimationState.SetAnimation(0, animationToSet, isLoop);
                }
                else
                {
                    trackEntry = skeleton.AnimationState.AddAnimation(0, animationToSet, isLoop, 0f);
                }

                if (OnEvent != null)
                {
                    trackEntry.Event += OnEvent;
                }
                if (OnComplete != null)
                {
                    trackEntry.Complete += OnComplete;
                }
            }
        }
Example #9
0
        bool stopCalled;         // In some situations Spine will fire multiple events when the animation is done (End / Complete distinction) but we only need one

        public override Deferred Run(CATContext context)
        {
            if (IsRunning)
            {
                return(base.Run(context));
            }
            stopCalled = false;
            Deferred dfrd = base.Run(context);

            HashSet <SkeletonAnimation> uniqueSkeletons = new HashSet <SkeletonAnimation>();

            target.WithTargets(context, delegate(GameObject obj)
            {
                var skels = includeChildren.value ?
                            obj.GetComponentsInChildren <SkeletonAnimation>() :
                            new SkeletonAnimation[] { obj.GetComponent <SkeletonAnimation>() };
                for (var i = 0; i < skels.Length; ++i)
                {
                    if (skels[i] == null)
                    {
                        continue;
                    }
                    uniqueSkeletons.Add(skels[i]);
                }
            });

            targetSkeletons = new SkeletonAnimation[uniqueSkeletons.Count];
            uniqueSkeletons.CopyTo(targetSkeletons);

            for (var i = 0; i < targetSkeletons.Length; ++i)
            {
                targetSkeletons[i].AnimationState.SetEmptyAnimation(trackNumber.value, 0);
                targetSkeletons[i].AnimationState.SetAnimation(trackNumber.value, animationName.value, loop.value);
            }


            /* Stop this action in animation callbacks. See http://esotericsoftware.com/spine-unity-events
             * TODO: Presently, this game doesn't need to be able to account for multiple targets with animations potentially finishing at different times,
             * so I am going to just stop on the first one's callback. This should be changed for a release of CAT. Also should consider the case that the
             * skeletons could be destroyed before the callback is called. Also, might the provided animationName change while the CAT is running?
             * Not sure about that last one.
             */
            var aniState = targetSkeletons[0].AnimationState;

            animationEnd = (trackEntry) =>
            {
                if (stopCalled)
                {
                    return;
                }
                Debug.Log("animationEnd entered. " + trackEntry.Animation.Name);
                // Ignore events on non-targeted tracks
                if (trackEntry.TrackIndex != trackNumber.value)
                {
                    return;
                }

                // See above TODO; for CAT release, don't just stop based on the first one
                if (targetSkeletons[0] == null)
                {
                    //Debug.Log("Stop! No SkeletonAnimator on target.");
                    Stop();
                }
                else if (trackEntry.Animation.Name == animationName.value)
                {
                    //Debug.Log("Stop! Animation ended.");
                    Stop();
                }
            };
            animationEnd += (trackentry) =>
            {
                aniState.End -= animationEnd;
            };
            animationComplete = (trackEntry) =>
            {
                if (stopCalled)
                {
                    return;
                }
                Debug.Log("animationComplete entered. " + trackEntry.Animation.Name);
                if (trackEntry.TrackIndex != trackNumber.value)
                {
                    return;
                }

                //Debug.Log("Stop! Animation complete.");
                Stop();
            };
            animationComplete += (trackEntry) =>
            {
                aniState.Complete -= animationComplete;
            };

            aniState.End += animationEnd;
            if (!loop.value)
            {
                aniState.Complete += animationComplete;
            }


            return(dfrd);
        }
 public TrackEntry PlayAnimation(int trackIndex, string animName, bool loop, Spine.AnimationState.TrackEntryDelegate onFinish = null)
 {
     return(armatureControl.Play(trackIndex, animName, loop, onFinish));
 }