dothem

I've searching for an solution to change the color (images) of my player (green, red, and so far). The look is the same, just the color is changed. I'm using spine for the character animation. The easiest way would be to change the whole atlas image. But I haven't find out how to do this, because its splitted in slices.

I have two approaches. The first ist using the native spine export (json skeleton). There are skins available. The negativ thing is, I can't use the statemaschine of unity? (or can I use it? I don't know why, because these arent native animations/clips). Because of this, I bought the this plugin to use native animations: https://www.assetstore.unity3d.com/en/#!/content/48096

There are no support for skins. And for the change of colors, I only found that every bone has his own sliced image with an spriterenderer. Do I have to change the sprite in spriterenderer? Or are there easier ways?

The best would be, to change the color/skin/image with an fade effect.

Thanks you!
dothem
  • Сообщения: 32

Pharan

If you're only using one texture, and want to change ALL the parts, the easiest way to do this is to set the MaterialPropertyBlock for the Renderer.

The code would look like this
void Start () {
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
mpb.SetTexture("_MainTex", myTextureToUse);
GetComponent<MeshRenderer>().SetPropertyBlock(mpb);
}
More info here: https://github.com/pharan/spine-unity-docs/blob/master/Rendering.md#setting-material-properties-per-instance
Note that this will not work if your atlas requires more than one page.

Otherwise, you can always use Spine's skins feature.

If you want to use Mecanim state machines, you can use SkeletonAnimator "Instantiate (Mecanim)" instead of native SkeletonAnimation.
It creates dummy Unity AnimationClips and it will work with Mecanim and Animator components. We only recommend using this if you really want to use Mecanim and are familiar with its quirks. There are other people in the forums who use it.

Beyond that, we can't offer much support for unofficial code (Spine2Unity). This one in particular not only works very differently from the official runtime, it's also closed-source. So you'll have to contact that person who made it for support there. Sorry.
Аватара пользователя
Pharan
  • Сообщения: 5366

dothem

Thanks for your fast reply.

For clarification. I know how to change the texture / material. My problem is, that I can't blending this for a smooth effect.
I know to use the skin feature, but is it possible to blending these skins? My character looks the same, I only want to change the color.

@StateMachine
My goal is a smooth animation blending between different animations (e.g. from walk to jump) without hard transition. If this is available in SkeletonAnimation I'll use this.

Yes, sorry. I stop using this for now, for native spine support.
dothem
  • Сообщения: 32

Pharan

SkeletonAnimation can crossfade between animations.

If you select your SkeletonData asset (the file with the spine icon in your project view) you'll see the inspector has a field called "Default Mix". This is the default number of seconds it uses to mix all animations between each other every time you call SetAnimation.

But alpha blending from one texture to another doesn't exist.
You probably need to have two instances that are posed similarly. Fade-out the one with the previous color, or fade-in the one with next color.
But note that things don't fade as a whole. In the middle of fading, you will see the overlaps between image parts.
All of this is just how alpha blending works with sprite-based systems that use 3D graphics (like Unity).
Аватара пользователя
Pharan
  • Сообщения: 5366

dothem

Thanks, I'll take a look at the SleketonAnimation.

Yes, this approach was in my mind too. But I thought about the performance, because the whole playercontroller have to be twice. But I'll test it. It's a little bit scary that no one used this befor (fading between colors) in spine or unity ;)

One another approach I've tested yesterday is to work with normal map and lights. But the result isn't the same, as native graphics for the colorswapping.
dothem
  • Сообщения: 32


Вернуться в Unity