theslap

  • 11 janv. 2018
  • Inscrit 27 mars 2015
  • Thank you! Works perfectly!


    28 Sep 2017, 12:58


    Pharan a écrit

    This will make a new attachment but it won't have any alignment data so you have align it yourself by setting the x, y, rotation, scaleX, scaleY yourself, and update the verts after.

    How do I update the verts of an attachment? I'm not seeing any methods available to the attachment itself.

    Also, have you guys looking into streamlining the new UnityEngine.SpriteAtlas into the Spine-Unity runtime? It would be fantastic if I could just covert the spriteAtlas into a spine atlas and it would retain all the pivot points of the sprites in the spriteAtlas. At the moment, I am feel I am forced to use unity sprites/atlas since the spine atlas doesn't hold pivot point data (at least when using the texture packer feature).

  • Is there a way that I can grab the sprite from a spine atlas rather than Unity for the examples above?

  • I'm trying to use a spine atlas asset in Unity to attach a region to a slot. The skeleton.SetAttachments has no overload method that takes an attachment only "string, string". I'm sure this has been answered before but after looking around for an hour or so I can't seem to get the attachment to render on screen.

    My code:

    public static void LinkSprite(Skeleton skeleton, string targetSlot, string spriteName ) {
            LoadAtlas();
            RegionAttachment attachment = GetAttachment( spriteName );
            skeleton.FindSlot( targetSlot ).attachment = attachment;
    
    }
    
    static RegionAttachment GetAttachment(string spriteName ) {
        string path = "Equipment/" + spriteName;
        AtlasRegion region = equipmentAtlas.GetAtlas().FindRegion( path );
        if ( region == null ) throw new System.ArgumentException( string.Format( "Region not found in atlas: {0} (region attachment: {1})", path, spriteName ) );
        RegionAttachment attachment = new RegionAttachment( path );
        attachment.RendererObject = region;
        attachment.SetUVs( region.u, region.v, region.u2, region.v2, region.rotate );
        attachment.regionOffsetX = region.offsetX;
        attachment.regionOffsetY = region.offsetY;
        attachment.regionWidth = region.width;
        attachment.regionHeight = region.height;
        attachment.regionOriginalWidth = region.originalWidth;
        attachment.regionOriginalHeight = region.originalHeight;
        return attachment;
    }
    

    Is there an easier built-in method to convert an AtlasRegion to Attachment to Slot?

  • avrahamy a écrit

    Hi guys,

    Thanks a bunch Pharan, your code sample is great!
    Is there a way to use Unity Sprites instead of Spine atlas assets?

    I tried to mash together your code with the SpriteAttacher code, but had no luck so far.
    I think I could create a RegionAttachment, like the SpriteAttacher does and then copy the UVs and other properties to get it to work, but I'm sure there is a cleaner way...

    BTW, I also got the "not a MeshAttachment" error but it was because I used the wrong skin :giggle:

    Resurrecting this thread to say I too would also like to know if it would be possible to use Unity Sprites instead of Spine Atlas assets?

    Any other new solutions available to swap mesh images at runtime in Unity?

  • Pharan a écrit

    The fix
    The change you want is likely on this line: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-csharp/src/Skeleton.cs#L252
    Just remove the if conditional so it'll change the attachment even if it's null.
    Similar logic can be found here: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-csharp/src/Skin.cs#L84
    But I don't know if you need to change that.

    @Pharan: Can I get an updated fix for the lines you are mentioning (the links are dead)? I've tried L407 on Skeleton.cs and the L95 in Skin.cs and a few other if (null) lines but I'm getting wonky results. It seems like once the attachment is set to null it will not be set again when switch to another skin. Using Spine-Unity btw if it matters.

    Mitch a écrit

    I feel like this could be solved in the runtimes by adding an optional bool parameter or an enum of options in the SetSkin function like "SkinMode.StartFresh" or something.

    I feel like this is an excellent solution from Mitch. Skin swapping, in my opinion, should at least have the option to act like they do within Spine Editor. If I swap skins there, I expect null skin placeholders to become null.

  • I didn't translate the meshes per say. I translated the objects in the hierarchy menu by typing 0,0 in the "translate" tool box at the bottom of the screen. I've done this before and even tested it in the same project and it worked just fine. I haven't looked at the json file and I'm not sure I'd know how to read that. Perhaps I'll send the file over just for bug testing purposes. At this stage, I'm just going to redo it and hope it doesn't happen again.

  • Pharan a écrit

    That's odd. Were they meshes?

    Yes. All meshes cut from a single sprite atlas. In fact, when I click on the mesh and click "Edit Mesh" it still shows the properly cut mesh in the correct position in relation to the 0,0 origin but when I click out of it, the sprite disappears again.

  • The best way to animate a walk cycle is to animate the character in one place. You don't want to actually translate the character. Literally animate the character as if they are walking on a treadmill. Do this with virtually all animations. Have an origin and animate from there.

  • Hi,

    So I selected only about 15 objects from the hierarchy (all first children of the "root") and translated them to 0,0. Their graphics then disappear and I just see an empty widget at 0,0. I tried CTRL+Z but it wouldn't let me undo at all. Now when I try to move one with translate tool (manually or with mouse) they revert back to 0,0. I've tried turning them off in Draw Order and nothing works.

    Please help! Any clue what could cause this? It seems I have to start all over...

    PS. Yes Images are enabled. In fact, the reference image (in low opacity) is the only one that I didn't move and I can still see it and move it around freely.

  • Thanks guys!

  • Hi guys,

    Now that I've finally got the runtime working nicely on PC, I decided to start testing on Android. I'm using the LG G3 for initial testing.

    I'm getting some seriously bad alpha artifacting on the Spine models. Is there some way to fix this? I've tried various settings in the Unity export but nothing has helped so far. Do I need to re-export the PNGs using a different setting from Photoshop or change the settings in Spine export?

    I've attached a screen shot of what I mean. Help! :sweat:

    Thanks ahead of time

  • I think I've got it working now. Thanks.


    Well now I'm getting the following error: Assets/Scripts/test.js(5,35): BCE0120: 'Spine.Skeleton.a' is inaccessible due to its protection level.

    Here is the code for test.js:
    function Start () {
    var skeletonRenderer : SkeletonRenderer = gameObject.GetComponent("SkeletonRenderer");
    skeletonRenderer.skeleton.a = 0.5;
    }

    The test.js script is attached to an instantiated SkeletonAnimation in the heirarchy. The SkeletonUtility/Editor folder and spine-unity/Editor folder are in their own separate folders while everything else is in the Assets/Plugins folder.

    I'm so sad =(

  • Mitch a écrit

    You should learn C#.

    srsly tho

    var skeletonRenderer : SkeletonRenderer = gameObject.GetComponent("SkeletonRenderer");
    skeletonRenderer.skeleton

    I really need to but unfortunately I don't have the time to translate the whole project over to C# at this moment.

    That reference is working now but now I'm having problems with the SkeletonAnimationInspector not being created when I move the runtime to the plugins folder. In order to import the namespace into the JS script, Unity requires that all the C# scripts be in the Plugins folder so that they are compiled first.

    Here's the error:
    Instance of SkeletonAnimationInspector couldn't be created. The script class needs to derive from ScriptableObject and be placed in the Assets/Editor folder.

    Any workaround for this? I understand your support is focused on C# users so it's no big deal if it can't be helped. In the meantime, I'll continue :bang: :bang: :bang: until I have the time to sort this out.

  • Mitch a écrit

    skeleton is member variable of a SkeletonRenderer.

    gameObject.GetComponent<SkeletonRenderer>().skeleton

    Thanks so much Mitch. Is there any way to access this via unity javascript or does it need to be in C# to call?

  • @[supprimé]

    Thanks for the help, but how do I reference the skeleton? If I instantiate the skeleton from SkeletonData this creates a GameObject. Could you give me a quick example code of how I would reference the skeleton and its RGBA values?

    Sorry for being such a plebian but code is not my forté.