Dharengo / Spriter2UnityDX

Converts Spriter .scml files to Unity prefabs
155 stars 41 forks source link

Handle Sprite swapping using the default way in Unity #12

Closed Mazku closed 7 years ago

Mazku commented 7 years ago

Use Unity’s default way of tracking Sprite swapping by adding ObjectReferenceCurves containing ObjectReferenceKeyframes.

Mazku commented 7 years ago

I didn't remove these obsolete methods, but these can be removed if my commit is accepted.

private void SetKeys(AnimationCurve curve, TimeLine timeLine, ref Sprite[] sprites, Animation animation)

private int GetIndexOrAdd(ref Sprite[] sprites, Sprite sprite)

Mazku commented 7 years ago

The main reason for me getting into making these changes was with animation blending. When using additive blended animation layers the TextureController.DisplayedSprite value was also calculated by adding all animations' values together. This caused wrong sprites to be shown or even index overflow in TextureController.Update (DisplayedSprite > Sprites.Length).

Dharengo commented 7 years ago

If it works for you the way you want it to, you are encouraged to keep using it in such a way. I will however not merge it into the main project because it conflicts with my intent in NOT using AnimationCurves for the swapping of sprite parts.

Unless you manage to make it into a toggle that the user can choose to use.

Mazku commented 7 years ago

Just to be clear: this implementation will create keyframes for swapping sprites similar to when changing the sprite in Unity Editor while in animation record mode.

If this is something that is not wanted I understand it. But what is an alternative way of implementing sprite swapping and what is the reason for it?

Dharengo commented 7 years ago

It's because animation curves are a bitch to modify at runtime. The SpriteSwapper, or TextureController or w/e I used to call it, can control every part of the sprite at runtime.

Again, if you can turn it into a toggle that the user can turn on and off, it'll be fine.

Mazku commented 7 years ago

I implement a support for user to opt in this feature with a toggle in ScmlImportOptionsWindow.

Dharengo commented 7 years ago

Excellent, I'll add it right away.