Exemple #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();
    }
 public float GetMix(Animation from, Animation to)
 {
     KeyValuePair<Animation, Animation> key = new KeyValuePair<Animation, Animation>(from, to);
     float duration;
     animationToMixTime.TryGetValue(key, out duration);
     return duration;
 }
Exemple #3
0
    static int _CreateSpine_Animation(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3)
            {
                string arg0 = ToLua.CheckString(L, 1);
                Spine.ExposedList <Spine.Timeline> arg1 = (Spine.ExposedList <Spine.Timeline>)ToLua.CheckObject <Spine.ExposedList <Spine.Timeline> >(L, 2);
                float           arg2 = (float)LuaDLL.luaL_checknumber(L, 3);
                Spine.Animation obj  = new Spine.Animation(arg0, arg1, arg2);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: Spine.Animation.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
		public void SetMix (Animation from, Animation to, float duration) {
			if (from == null) throw new ArgumentNullException("from cannot be null.");
			if (to == null) throw new ArgumentNullException("to cannot be null.");
			KeyValuePair<Animation, Animation> key = new KeyValuePair<Animation, Animation>(from, to);
			animationToMixTime.Remove(key);
			animationToMixTime.Add(key, duration);
		}
    private void Update()
    {
        // Animation
        // Determine target animation.

        Vector2 _temp = new Vector2(teddy.transform.position.x, gameObject.transform.position.y);

        gameObject.transform.position = _temp;

        if (teddyView.input.x == 0)
        {
            targetAnimation = idle;
        }
        else
        {
            targetAnimation = walk;
        }



        // Handle change in target animation.
        if (previousTargetAnimation != targetAnimation)
        {
            Spine.Animation transition = null;

            skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true);
        }
        previousTargetAnimation = targetAnimation;

        // Face intended direction.
        if (teddyView.input.x != 0)
        {
            skeletonAnimation.Skeleton.FlipX = teddyView.input.x > 0;
        }
    }
Exemple #6
0
    float GetJumpLength(Spine.Animation anim)
    {
        float begin = -1;
        float end   = -1;

        for (int i = 0; i < anim.timelines.Count; i++)
        {
            //Check if it's an event timeline
            if (anim.timelines.Items [i] is Spine.EventTimeline)
            {
                Spine.EventTimeline ev = anim.timelines.Items [i] as Spine.EventTimeline; //casting Timeline to EventTimeline
                for (int j = 0; j < ev.Events.Length; j++)                                //Read through events in the timeline
                {
                    float timing = ev.Events [j].Time;
                    if (ev.Events [j].data.Name == "start" || ev.Events [j].data.Name == "jump_start")
                    {
                        begin = timing;
                    }
                    else if (ev.Events [j].data.Name == "end" || ev.Events [j].data.Name == "jump_end")
                    {
                        end = timing;
                    }
                }
            }
        }
        return(end - begin);
    }
Exemple #7
0
    void HandleEvent_Start(Spine.TrackEntry trackEntry)
    {
        //Debug.Log("Spine_AnimationStart:" + trackEntry.Animation.Name);

        Spine.Animation CurAni = skeletonAnimation.state.GetCurrent(0).animation;

        LuaManager.GetInstance().CallLuaFunction(Lua_StartCall, trackEntry.Animation.Name);
    }
Exemple #8
0
    public float GetAnimatorTime(GameObject gm, string animName = "animation")
    {
        SkeletonAnimation skAnim = gm.GetComponent <SkeletonAnimation>();

        skAnim.AnimationName = animName;
        Spine.Animation anim = skAnim.skeletonDataAsset.GetAnimationStateData().skeletonData.FindAnimation(animName);
        return(anim.duration);
    }
Exemple #9
0
    void Start()
    {
        if (!skeletonAnimation)
        {
            return;
        }

        Spine.Animation anim = skeletonAnimation.Skeleton.Data.FindAnimation(animationName);
    }
Exemple #10
0
 /// <summary>
 /// Play selected animation
 /// </summary>
 /// <param name="animation">animation to play</param>
 /// <param name="lastTime">the last time the animation was applied</param>
 /// <param name="time">the time in duration to start animation at</param>
 /// <param name="isLoop">should animation loop</param>
 /// <param name="trackIndex">track to play animation in</param>
 /// <param name="individualTimeScale">time scale of this animation</param>
 public void Play(SpineAnimationsEnum animation, float lastTime = 0, float time = 0, bool isLoop = false, int trackIndex = 0, float individualTimeScale = 1f)
 {
     if (currentAnimation == animation)
     {
         return;
     }
     lastAnimation    = currentAnimation;
     currentAnimation = animation;
     //if (animation != Animations.hit)
     //{
     //    if (currentAnimation == animation)
     //        return;
     //    lastAnimation = currentAnimation;
     //    currentAnimation = animation;
     //}
     //else
     //{
     //    if (currentAnimation != Animations.idle || currentAnimation != Animations.move || currentAnimation != Animations.up_move)
     //        return;
     //}
     //Spine.Animation curAnimation = null;
     //if (lastAnimation != currentAnimation) {
     //    if (spine.state.GetCurrent(trackIndex) != null) {
     //        spine.state.GetCurrent(trackIndex).Loop = false;
     //        curAnimation = spine.state.GetCurrent(trackIndex).Animation;
     //    }
     //} else return;
     Spine.Animation loadedAnim = getSpineAnimation(animation);
     //loadedAnim.Name(spine.Skeleton, lastTime, time, isLoop, null, alphaMix);
     if (lastAnimation != currentAnimation)
     {
         //if (lastAnimation != Animations.idle
         //    && lastAnimation != Animations.move
         //    && lastAnimation != Animations.knock_back
         //    && lastAnimation != Animations.knock_down
         //    && lastAnimation != Animations.stand_up)
         spine.Skeleton.SetToSetupPose();
     }
     //if (trackIndex == Constant.DEFAULT_TRACK_INDEX) {
     spine.state.ClearTrack(trackIndex);
     //}
     //if (curAnimation != null) {
     //    if (lastAnimation == Animations.idle
     //        || lastAnimation == Animations.move
     //        /*|| lastAnimation == Animations.knock_down*/
     //        /*|| lastAnimation == Animations.stand_up*/
     //        /*|| lastAnimation == Animations.stunned*/) {
     //        curAnimation.Apply(spine.skeleton, 0f, 0f, false, null);
     //        spine.state.AddAnimation(trackIndex, curAnimation, false, 0f);
     //    }
     //}
     spine.state.AddAnimation(trackIndex, loadedAnim, isLoop, Time.deltaTime);
     spine.state.GetCurrent(trackIndex).TimeScale = individualTimeScale;
 }
Exemple #11
0
    // Use this for initialization
    void Start()
    {
        BattleFactory.AddUnitToLayer(gameObject, layer);

        _skeleton = GetComponentInChildren <SkeletonAnimation>();
        if (_skeleton != null)
        {
            _skeleton.state.TimeScale = speed;
            _animation = _skeleton.Skeleton.Data.FindAnimation(_skeleton.AnimationName);
            _palyTime  = _animation.Duration;
        }
    }
Exemple #12
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);
 }
	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();
	}
 static int Pop(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
         Spine.Animation o = obj.Pop();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int Add(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
         Spine.Animation arg0 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 2);
         obj.Add(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #16
0
 public Spine.Animation getSpineAnimation(SpineAnimationsEnum animation)
 {
     // check in cached
     Spine.Animation load = cachedAnimations.Find(a => a.Name == animation.ToString());
     if (load == null)
     {
         // load from spine
         load = spine.Skeleton.Data.FindAnimation(animation.ToString());
         if (load == null)
         {
             throw new ArgumentNullException("Can not find animation '" + animation.ToString() + "'" + " on " + name);
         }
     }
     return(load);
 }
Exemple #17
0
 static int FindAnimation(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.SkeletonData obj  = (Spine.SkeletonData)ToLua.CheckObject <Spine.SkeletonData>(L, 1);
         string             arg0 = ToLua.CheckString(L, 2);
         Spine.Animation    o    = obj.FindAnimation(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #18
0
 public void SetAnimation(Animation animation, bool loop)
 {
     previous = null;
     if (animation != null && Animation != null) {
         mixDuration = Data.GetMix(Animation, animation);
         if (mixDuration > 0) {
             mixTime = 0;
             previous = Animation;
             previousTime = Time;
             previousLoop = Loop;
         }
     }
     Animation = animation;
     Loop = loop;
     Time = 0;
 }
 static int FindLast(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.ExposedList <Spine.Animation> obj  = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
         System.Predicate <Spine.Animation>  arg0 = (System.Predicate <Spine.Animation>)ToLua.CheckDelegate <System.Predicate <Spine.Animation> >(L, 2);
         Spine.Animation o = obj.FindLast(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int Remove(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
         Spine.Animation arg0 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 2);
         bool            o    = obj.Remove(arg0);
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int Insert(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
         int             arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         Spine.Animation arg1 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 3);
         obj.Insert(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #22
0
    static int get_Duration(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.Animation obj = (Spine.Animation)o;
            float           ret = obj.Duration;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Duration on a nil value"));
        }
    }
Exemple #23
0
    void Init(GameObject inst)
    {
        anim = inst.GetComponent <SpineAnimation> ();

        Spine.SkeletonData data = anim.skeleton.skeleton.data;

        Spine.Animation up = data.FindAnimation("jump_up");

        Spine.Animation dn = data.FindAnimation("jump_down");

        jumpFlightTime = GetJumpLength(up);
        fallFlightTime = GetJumpLength(dn);

        //Subscribe to events
        anim.skeleton.state.Event    += HandleCustomEvent;
        anim.skeleton.state.Complete += OnJumpEnd;
    }
    static int get_Animation(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.TrackEntry obj = (Spine.TrackEntry)o;
            Spine.Animation  ret = obj.Animation;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index Animation on a nil value" : e.Message));
        }
    }
Exemple #25
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();
	}
Exemple #26
0
    static int get_Timelines(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.Animation obj = (Spine.Animation)o;
            Spine.ExposedList <Spine.Timeline> ret = obj.Timelines;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Timelines on a nil value"));
        }
    }
Exemple #27
0
    static int get_Name(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.Animation obj = (Spine.Animation)o;
            string          ret = obj.Name;
            LuaDLL.lua_pushstring(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Name on a nil value"));
        }
    }
Exemple #28
0
    static int set_Timelines(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.Animation obj = (Spine.Animation)o;
            Spine.ExposedList <Spine.Timeline> arg0 = (Spine.ExposedList <Spine.Timeline>)ToLua.CheckObject <Spine.ExposedList <Spine.Timeline> >(L, 2);
            obj.Timelines = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Timelines on a nil value"));
        }
    }
Exemple #29
0
    static int set_Duration(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.Animation obj  = (Spine.Animation)o;
            float           arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
            obj.Duration = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Duration on a nil value"));
        }
    }
    protected void OnProcessActionGUI(Process process)
    {
        var role = process.binderObject as Role;

        if (null != role && process.eProcessType == ProcessType.PT_ANIMATION)
        {
            GUI.color = Color.green;
            EditorGUILayout.LabelField("[角色动作]:", GUILayout.MaxWidth(60));
            GUI.color = Color.white;
            bool isActionValid = !string.IsNullOrEmpty(process.actionName);

            Spine.Animation action = null;
            if (isActionValid)
            {
                action = process.getAction();
            }
            isActionValid = null != action;

            var content = isActionValid ? process.actionName : "Invalid Action";
            if (GUILayout.Button(content, "GV Gizmo DropDown", GUILayout.MaxWidth(80)))
            {
                if (null != role.animations && null != role.animations.Items)
                {
                    GenericMenu menu = new GenericMenu();
                    for (int i = 0; i < role.animations.Items.Length; ++i)
                    {
                        var actionName = role.animations.Items[i].Name;
                        menu.AddItem(new GUIContent(actionName), string.Equals(actionName, process.actionName), OnRoleActionSelected, new object[]
                        {
                            process, actionName
                        });
                    }
                    menu.ShowAsContext();
                }
            }

            if (null != action)
            {
                GUI.color = Color.magenta;
                var lengthDesc = string.Format("[时长:{0:F3}秒]", action.Duration);
                EditorGUILayout.LabelField(lengthDesc, GUILayout.Width(100));
                GUI.color = Color.white;
            }
        }
    }
    static int BinarySearch(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
                Spine.Animation arg0 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 2);
                int             o    = obj.BinarySearch(arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 3)
            {
                Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
                Spine.Animation arg0 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 2);
                System.Collections.Generic.IComparer <Spine.Animation> arg1 = (System.Collections.Generic.IComparer <Spine.Animation>)ToLua.CheckObject <System.Collections.Generic.IComparer <Spine.Animation> >(L, 3);
                int o = obj.BinarySearch(arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 5)
            {
                Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
                int             arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int             arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                Spine.Animation arg2 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 4);
                System.Collections.Generic.IComparer <Spine.Animation> arg3 = (System.Collections.Generic.IComparer <Spine.Animation>)ToLua.CheckObject <System.Collections.Generic.IComparer <Spine.Animation> >(L, 5);
                int o = obj.BinarySearch(arg0, arg1, arg2, arg3);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Spine.ExposedList<Spine.Animation>.BinarySearch"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemple #32
0
    private void Update()
    {
        // Animation
        // Determine target animation.

        if (input.x == 0)
        {
            targetAnimation = idle;
        }
        else
        {
            targetAnimation = Mathf.Abs(input.x) > 0.3f ? run : walk;
        }



        // Handle change in target animation.
        if (previousTargetAnimation != targetAnimation)
        {
            Spine.Animation transition = null;
            //if (transitions != null && previousTargetAnimation != null)
            //{
            //transition = transitions.GetTransition(previousTargetAnimation, targetAnimation);
            //}

            if (transition != null)
            {
                skeletonAnimation.AnimationState.SetAnimation(0, transition, false).MixDuration = 0.05f;
                skeletonAnimation.AnimationState.AddAnimation(0, targetAnimation, true, 0f);
            }
            else
            {
                skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true);
            }
        }
        previousTargetAnimation = targetAnimation;

        // Face intended direction.
        if (input.x != 0)
        {
            skeletonAnimation.Skeleton.FlipX = input.x > 0;
        }
    }
    static int LastIndexOf(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
                Spine.Animation arg0 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 2);
                int             o    = obj.LastIndexOf(arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 3)
            {
                Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
                Spine.Animation arg0 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 2);
                int             arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                int             o    = obj.LastIndexOf(arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 4)
            {
                Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1);
                Spine.Animation arg0 = (Spine.Animation)ToLua.CheckObject <Spine.Animation>(L, 2);
                int             arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                int             arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                int             o    = obj.LastIndexOf(arg0, arg1, arg2);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Spine.ExposedList<Spine.Animation>.LastIndexOf"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        public Spine.Animation getAction()
        {
            if (eProcessType != ProcessType.PT_ANIMATION)
            {
                return(null);
            }

            var role = binderObject as Role;

            if (null == role)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(actionName))
            {
                return(null);
            }

            Spine.Animation action         = null;
            var             animationState = role.animation.skeletonDataAsset.GetAnimationStateData();

            if (null != animationState)
            {
                var animations = animationState.SkeletonData.Animations;
                if (null != animations && null != animations.Items)
                {
                    for (int i = 0; i < animations.Items.Length; ++i)
                    {
                        var item = animations.Items[i];
                        if (null != item && string.Equals(item.Name, actionName))
                        {
                            action = item;
                            break;
                        }
                    }
                }
            }

            return(action);
        }
Exemple #35
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();
    }
Exemple #36
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));
     }
 }
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
            Atlas atlas = new Atlas(GraphicsDevice, "data/goblins.atlas");
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.readSkeletonData("goblins", File.ReadAllText("data/goblins.json")));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose();
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Exemple #38
0
        public void LoadContent(ContentManager content, GraphicsDevice graphicsDevice)
        {
            blankTex = content.Load<Texture2D>("blank");

            skeletonRenderer = new SkeletonRenderer(graphicsDevice);
            Atlas atlas = new Atlas(graphicsDevice, Path.Combine(content.RootDirectory, "spineboy.atlas"));
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.readSkeletonData("spineboy", File.ReadAllText(Path.Combine(content.RootDirectory, "spineboy.json"))));
            skeleton.SetSkin("default");
            skeleton.SetSlotsToBindPose();
            walkAnimation = skeleton.Data.FindAnimation("walk");
            jumpAnimation = skeleton.Data.FindAnimation("jump");
            crawlAnimation = skeleton.Data.FindAnimation("crawl");
            fallAnimation = skeleton.Data.FindAnimation("fall");
            grabAnimation = skeleton.Data.FindAnimation("grab");
            climbAnimation = skeleton.Data.FindAnimation("climb");

            skeleton.RootBone.X = Position.X;
            skeleton.RootBone.Y = Position.Y;
            skeleton.UpdateWorldTransform();
        }
        /// <summary>Adds an animation to be played delay seconds after the current or last queued animation.</summary>
        /// <param name="delay">May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay.</param>
        public TrackEntry AddAnimation(int trackIndex, Animation animation, bool loop, float delay)
        {
            TrackEntry entry = new TrackEntry();
            entry.animation = animation;
            entry.loop = loop;
            entry.time = 0;
            entry.endTime = animation.Duration;

            TrackEntry last = ExpandToIndex(trackIndex);
            if (last != null) {
                while (last.next != null)
                    last = last.next;
                last.next = entry;
            } else
                tracks[trackIndex] = entry;

            if (delay <= 0) {
                if (last != null)
                    delay += last.endTime - data.GetMix(last.animation, animation);
                else
                    delay = 0;
            }
            entry.delay = delay;

            return entry;
        }
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            this.atlas = new Atlas("Content/crab.atlas", new XnaTextureLoader(GraphicsDevice));

            SkeletonJson json = new SkeletonJson(atlas);
            this.skeleton = new Skeleton(json.ReadSkeletonData("Content/crab-skeleton.json"));
            this.animationWalk = skeleton.Data.FindAnimation ("WalkLeft");
            this.animationJump = skeleton.Data.FindAnimation ("Jump");

            this.skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin.

            this.animation = 0;
            this.SetSkeletonStartPosition ();

            // used for debugging - draw the bones
            this.lineTexture = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            this.lineTexture.SetData(new[]{Color.White});
            this.textureMaps.Add(lineTexture);

            base.LoadContent ();
        }
 public void AddAnimation(Animation animation, bool loop)
 {
     AddAnimation(animation, loop, 0);
 }
 public void ClearAnimation()
 {
     previous = null;
     current = null;
     queue.Clear();
 }
 /** Set the current animation. Any queued animations are cleared and the current animation time is set to 0.
  * @param animation May be null.
  * @param listener May be null. */
 public void SetAnimation(Animation animation, bool loop)
 {
     queue.Clear();
     SetAnimationInternal(animation, loop, null);
 }
        private void SetAnimationInternal(Animation animation, bool loop, QueueEntry entry)
        {
            previous = null;
            if (current != null) {
                if (currentQueueEntry != null) currentQueueEntry.OnEnd(this);
                if (End != null) End(this, EventArgs.Empty);

                if (animation != null) {
                    mixDuration = data.GetMix(current, animation);
                    if (mixDuration > 0) {
                        mixTime = 0;
                        previous = current;
                        previousTime = currentTime;
                        previousLoop = currentLoop;
                    }
                }
            }
            current = animation;
            currentLoop = loop;
            currentTime = 0;
            currentLastTime = 0;
            currentQueueEntry = entry;

            if (currentQueueEntry != null) currentQueueEntry.OnStart(this);
            if (Start != null) Start(this, EventArgs.Empty);
        }
Exemple #45
0
 public void ClearAnimation()
 {
     previous = null;
     Animation = null;
 }
Exemple #46
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
            Atlas atlas = new Atlas(GraphicsDevice, "data/spineboy.atlas");
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.readSkeletonData("spineboy", File.ReadAllText("data/spineboy.json")));
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Exemple #47
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            Atlas atlas = new Atlas("data/goblins.atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json"));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose(); // Without this the skin attachments won't be attached. See SetSkin.
            skeleton.SetAttachment("left hand item", "spear");
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
        /** Adds an animation to be played delay seconds after the current or last queued animation.
         * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */
        public QueueEntry AddAnimation(Animation animation, bool loop, float delay)
        {
            QueueEntry entry = new QueueEntry();
            entry.animation = animation;
            entry.loop = loop;

            if (delay <= 0) {
                Animation previousAnimation = queue.Count == 0 ? current : queue[queue.Count - 1].animation;
                if (previousAnimation != null)
                    delay = previousAnimation.duration - data.GetMix(previousAnimation, animation) + delay;
                else
                    delay = 0;
            }
            entry.delay = delay;

            queue.Add(entry);
            return entry;
        }
Exemple #49
0
        public override void Render(SkeletonRenderer skeletonRenderer, EntityWorld world, Entity entity, Renderable position)
        {
            ActivityComponent activityCom = null;
            DirectionComponent directionCom = null;

            foreach (IComponent com in world.EntityManager.GetComponents(entity)) {
                if (com is ActivityComponent)
                    activityCom = com as ActivityComponent;
                else if (com is DirectionComponent)
                    directionCom = com as DirectionComponent;
            }

            if (activityCom != null && activityCom.Activity != _activity) {
                _activity = activityCom.Activity;

                string animationKey = null;
                if (!_record.ActivityMap.TryGetValue(activityCom.Activity, out animationKey))
                    animationKey = _record.DefaultAnimation;

                string animation = "";
                bool flipX = false;
                bool flipY = false;

                if (animationKey != null) {
                    if (directionCom != null && _record.DirectedAnimationMap.ContainsKey(animationKey)) {
                        if (_record.DirectedAnimationMap[animationKey].ContainsKey(directionCom.Direction)) {
                            ISpineDirectionElement element = _record.DirectedAnimationMap[animationKey][directionCom.Direction];
                            animation = element.Animation;
                            flipX = element.FlipX;
                            flipY = element.FlipY;
                        }
                        else if (_record.DefaultAnimationMap.ContainsKey(animationKey))
                            animation = _record.DefaultAnimationMap[animationKey];
                    }
                    else if (_record.DefaultAnimationMap.ContainsKey(animationKey))
                        animation = _record.DefaultAnimationMap[animationKey];
                }

                if (_animation == null || animation != _animation.Name) {
                    _animation = _skeleton.Data.FindAnimation(animation);
                    _time = 0;
                }

                if (_animation == null && _skeleton.Data.Animations.Count > 0) {
                    _animation = _skeleton.Data.Animations[0];
                    _time = 0;
                }

                _skeleton.FlipX = flipX;
                _skeleton.FlipY = flipY;
            }

            if (_animation != null) {
                _time += (float)world.GameTime.ElapsedGameTime.TotalSeconds;
                _animation.Apply(_skeleton, _time, true);
            }

            _skeleton.RootBone.X = (float)position.RenderX;
            _skeleton.RootBone.Y = (float)position.RenderY;
            _skeleton.UpdateWorldTransform();

            skeletonRenderer.Draw(_skeleton);
        }
 public QueueEntry AddAnimation(Animation animation, bool loop)
 {
     return AddAnimation(animation, loop, 0);
 }
 public void ClearAnimation()
 {
     previous = null;
     Animation = null;
     queue.Clear();
 }
Exemple #52
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            Texture2D texture = Util.LoadTexture(GraphicsDevice, "data/goblins.png");
            Atlas atlas = new Atlas("data/goblins.atlas", texture, texture.Width, texture.Height);
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json"));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose(); // Without this the skin attachments won't be attached. See SetSkin.
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Exemple #53
0
		/// <summary>Set the current animation. Any queued animations are cleared.</summary>
		public TrackEntry SetAnimation (int trackIndex, Animation animation, bool loop) {
			if (animation == null) throw new ArgumentException("animation cannot be null.");
			TrackEntry entry = new TrackEntry();
			entry.animation = animation;
			entry.loop = loop;
			entry.time = 0;
			entry.endTime = animation.Duration;
			SetCurrent(trackIndex, entry);
			return entry;
		}
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            this.skeletonRenderer = new SkeletonRegionRenderer(GraphicsDevice);

            var atlas = new Atlas(@"Assets\crab.atlas", new XnaTextureLoader(GraphicsDevice));
            var json = new SkeletonJson(atlas);

            this.skeleton = new Skeleton(json.ReadSkeletonData(@"Assets\skeleton.json"));
            this.animation = this.skeleton.Data.FindAnimation("Walk");

            this.skeleton.X = 750;
            this.skeleton.Y = 700;
        }
 /// <summary>Set the current animation. Any queued animations are cleared.</summary>
 public TrackEntry SetAnimation(int trackIndex, Animation animation, bool loop)
 {
     TrackEntry entry = new TrackEntry();
     entry.animation = animation;
     entry.loop = loop;
     entry.time = 0;
     entry.endTime = animation.Duration;
     SetCurrent(trackIndex, entry);
     return entry;
 }
 // --- Animations.
 public void AddAnimation(Animation animation)
 {
     if (animation == null) throw new ArgumentNullException("animation cannot be null.");
     animations.Add(animation);
 }