Jump to content

SpriterDotNet.Unity


loodakrawa

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

Link to comment
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.

Link to comment
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 :(

Link to comment
Share on other sites

  • 2 months later...

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?

Link to comment
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.

 

Link to comment
Share on other sites

  • 5 months later...
  • 2 months later...

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

Link to comment
Share on other sites

  • 2 months later...

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;
}

 

 

Link to comment
Share on other sites

  • 1 month later...
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?

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...
  • 11 months later...
On 8/5/2020 at 12:32 AM, SquigglyFrog said:

Not to necro, but still looking for a solution. I have tried setting the animator.speed to 0f, and it continues to animate. If i set it to 0.25f, it definitely slows down, but setting it to 0 seems to do nothing. 

Sorry that at the moment we can't offer any first part support for the Unity run-time or importer. We'll try to resolve that as soon as we can, but it might not happen until after the next few Spriter update builds are released. In the meantime, can you confirm you're using SpriterDotNet.Unity with the latest build of Unit and it's mostly working, but you can't find the way to completely pause animations?

Link to comment
Share on other sites

yes, definitely using spriterdotnet.unity with unity 2017, 2018, and now 2019.4.8f1.  So mostly figured it out, I didnt change my code at all, but upgrading to a diff ver of unity did fix that issue. Now if only unity and spritedotnet would play nicely together - same issue as BlooberryPi3 above. Once imported, click any of the prefabs and its a constant jump back and forth between pointer and hourglass, like its constantly searching for any updates in the spriter file, which slows the editor down tremendously. Tested that on 3 different machines here and multiple unity versions, and they all do it.

 

Link to comment
Share on other sites

  • 1 month later...

@SquigglyFrog @BlooberryPi3 I'm not sure if this is still relevant for you, but I was able to fix both of those bugs (flickering pointer/hourglass when prefab is selected and import not working at all in later unity versions).  If you'd like to use them while waiting for them to be merged into the main repository, you can download the package here:
https://github.com/lucidspriter/SpriterDotNet/blob/develop/SpriterDotNet.Unity/SpriterDotNet.Unity.unitypackage

Link to comment
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...