Jump to content
loodakrawa

SpriterDotNet.Unity

Recommended Posts

I saw this code and animation have a event point
        if (animator == null)
        {
            animator = FindObjectOfType<SpriterDotNetBehaviour>().Animator;
            animator.EventTriggered += e => Debug.Log("Event Triggered. Source: " + animator.CurrentAnimation.Name + ". Value: " + e);
        }

and I want to add this code
    private void GiveDamage()
    {
        enemy.GetComponent<Enemy>().TakeDamage(10);
    }

How can I add this code to event point ,in animations.I check examples ,some animations play a audio clip but I didn't see anything about adding function :(

Thank you for all answer

Share this post


Link to post
Share on other sites
3 hours ago, poewang13 said:

animator.EventTriggered += e => Debug.Log("Event Triggered. Source: " + animator.CurrentAnimation.Name + ". Value: " + e);

This line literally is registering a function to the event.

Try

animator.EventTriggered += e => GiveDamage();

Btw, this is basic C# - I recommend reading about Delegates, Events, Actions and Funcs.

Share this post


Link to post
Share on other sites
On 17.11.2017 at 1:02 AM, loodakrawa said:

Btw, this is basic C# - I recommend reading about Delegates, Events, Actions and Funcs.

Sorry about that . I completely forgotten Delegate,my mistake :( Bu I have 2 event point in animation and I try this

animator.EventTriggered += e => ActiveObject();
animator.EventTriggered += e => DeActiveObject();

In unity, I see two functions same time but I want to see this two func. in different time.For Example in 100th Frame I must see ActiveObject func. ,1600th frame ,I must see DeActiveObject func.In the inspector I can see different Id but I don't understandt how can ı use them

another an questions I have 2 animations ,first animations have 2 event and second animationd has 1 event .How can I set this event my 3 functions ?

Thank you for answer

Sorry about my bad english :(

Share this post


Link to post
Share on other sites

Hi,

I got Spriter on Steam and I've been having fun creating some nice animations I really needed for some artwork that I have here. Having finished up I brought all to Unity and... the skins deformations are not showing... all invisible :( Am I missing something stupid here?

Share this post


Link to post
Share on other sites
59 minutes ago, Pino said:

Hi,

I got Spriter on Steam and I've been having fun creating some nice animations I really needed for some artwork that I have here. Having finished up I brought all to Unity and... the skins deformations are not showing... all invisible :( Am I missing something stupid here?

Skin mode es an unofficial experimental "proof of concept" feature and is not supported by any of the API-s or run-times. Your options are:
1) Don't use skin mode
2) Use skin mode as much as you want, but then export all animations as full frame sprite-sheets or sequential images and therefore not benifit as from tweening and modular animation related things like drastically reduced memory consumption.
3) come up with a clever work-flow that uses skin mode to pre-create some image-swapping animations for parts of your final Spriter animations... This requires two spriter projects... the first using skin mode, then a second with any skin mode animated thing replaced with sequential images exported from the skin mode version.

I used option number 3 to make the animated flags in the Dreamland Frontiers Art Pack.

 

Share this post


Link to post
Share on other sites

I've been using Spriter with Unity lately, and both the Spriter program itself and the Unity wrapper by loodakrawa are a joy to use. Performance-wise it seems to be a winner as well.

I use events and points a lot, in order to control a lot of custom sprite swapping and other jazz in Unity, and I've encountered a couple of bugs/oversights/"features":

1: A Spriter-point, when converted to a unity object, does not get the correct rotation (it's always at zero degrees). I've fixed this by adding the following line to UnityAnimator.ApplyPointTransform (at line 138 in my case):

pointTransform.localEulerAngles = new Vector3(0, 0, info.Angle);

2: A Spriter-point with limited duration (for instance it only exists at frame 60) will not be set if that particular frame is skipped in Unity. In my case the point was only visible/discovered by the system every tenth iteration or so. This is probably not a bug per-se, and easily circumvented when I know about it, but I thought I should at least mention it.

Cheers,

Einar

Share this post


Link to post
Share on other sites

Hi, I'm trying to do the following (in Unity):

  • pause a running animation
  • resume a paused animation
  • jump to a given key of an animation
  • hook to the end of an animation (in order to notify that the animation has stopped playing)

EDIT (some solutions): 

To hook to the end of an animation, see 'AnimationFinished' in Animator.cs

For jumping to the given key of an animation, here is a solution that works for my use case, I added the following function in Animator.cs (it's an adaptation of the 'Play' function)

/// <summary>
/// Go to key and stop
/// </summary>
public virtual void GoToKeyAndStop(SpriterAnimation animation, int keyRankFrom0)
{
    // Use the first timeline to get the keys
    SpriterTimeline spriterTimeLine = animation.Timelines[0];
    Time = spriterTimeLine.Keys[keyRankFrom0].Time;
    Speed = 0f; // will make the animation stop (=> you need to set 'Speed = 1f' in the 'Play' function)

    CurrentAnimation = animation;
    Name = animation.Name;

    NextAnimation = null;
    Length = CurrentAnimation.Length;
}

 

 

Share this post


Link to post
Share on other sites
On 12/11/2018 at 2:10 AM, Vincent Laugier said:

Hi, I'm trying to do the following (in Unity):

  • pause a running animation
  • resume a paused animation
  • jump to a given key of an animation
  • hook to the end of an animation (in order to notify that the animation has stopped playing)

EDIT (some solutions): 

To hook to the end of an animation, see 'AnimationFinished' in Animator.cs

For jumping to the given key of an animation, here is a solution that works for my use case, I added the following function in Animator.cs (it's an adaptation of the 'Play' function)

 

Hi,

As you already figured out you can pause and resume by setting the Speed property. For the end of the animation - Animator.cs exposes the AnimationFinished event which you can subscribe to.

As for jumping to specific keys - what's the use case for that? Could you achieve the same effect by splitting the animation into several smaller ones and then just switch animations instead of jumping to different keys?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...