RyanRothweiler

  • 25 апр 2017
  • Регистрация: 21 апр 2017

    The scale / width / height / position values are the same as what is initially in the atlas.
    Changing the values when creating a new attachment, even to the same values as what is in the atlas, breaks the alignment.

    This must mean I'm doing something wrong, possibly in the wrong order? Any thoughts on something that might point me in the right direction?

    Here is the code.

    Sprite spriteFromServer = Sprite.Create(newAsset.texture,
                                            new Rect(newAsset.x, newAsset.texture.height - newAsset.h - newAsset.y, newAsset.w, newAsset.h),
                                            new Vector2(0.5f, 1.0f),
                                            135f);
    spriteFromServer.name = newAsset.name + "_" + newAsset.placeholder;
    
    RegionAttachment newWeapon = spriteFromServer.ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton"));
    
    newWeapon.X = newAsset.attachmentData.x;
    newWeapon.Y = newAsset.attachmentData.y;
    newWeapon.ScaleX = newAsset.attachmentData.scaleX;
    newWeapon.ScaleY = newAsset.attachmentData.scaleY;
    newWeapon.Rotation = newAsset.attachmentData.rotation;
    newWeapon.Width = newAsset.attachmentData.w;
    newWeapon.Height = newAsset.attachmentData.h;
    newWeapon.UpdateOffset();
    
    int weaponSlotIndex = skeleton.FindSlotIndex(slotName);
    clonedSkin.AddAttachment(weaponSlotIndex, attachmentName, newWeapon);
    
    skeleton.SetSkin(clonedSkin);
    skeleton.SetToSetupPose();
    skeleton.SetAttachment(slotName, attachmentName);
    
    

    I'm not repacking the skin, because I can't find how to mark a texture loaded from the web as readable. That shouldn't be a problem, but still.

    Thanks again for all the help.

    Great, thanks for the help!
    I was able to get the attachments working. I had the wrong attachment name, I was using the file name not the attachment name.

    Next question. Does there need to be any unit conversion between unity and the web? I'm setting the attachment transform info like so, but they aren't aligning correctly. The newAsset.attachmentData comes straight from the web app.

    newWeapon.ScaleX = newAsset.attachmentData.scaleX;
    newWeapon.ScaleY = newAsset.attachmentData.scaleY;
    newWeapon.Rotation = newAsset.attachmentData.rotation;
    newWeapon.X = newAsset.attachmentData.x;
    newWeapon.Y = newAsset.attachmentData.y;
    newWeapon.UpdateOffset();
    
    

    Thanks for the help!

    Hi Pharan,
    I'm a unity dev brought in to help with this. I know Unity, but I don't have any experience with Spine.

    I think I have the hard part done. I can load in sprites from a web server, create attachments with them, and add that into an existing slot. During runtime (with unity paused), I can manually enable the new attachment in the inspector and everything works just great. When unity is unpaused, the game then selects the original attachment. I assume the animation data is referencing the original attachment, not the new ones. The animations are done by cycling through the attachments like frames.
    Is there a way to update existing attachments? Maybe instead it's best to remove the old attachments? Do I need to update the animation references?

    The MixAndMatch example doesn't help here because the attachments in it aren't being controlled by animation data.

    Thanks for the help. Feel free to correct me if my Spine knowledge is wrong.