cloudcamaleoniv

Hello, can I control my spine animation opacity throught unity? I meah, the alpha channel of the color?

If yes, how may I do this throught the editor and throught code?

Thanks.
cloudcamaleoniv
  • Сообщения: 20

karlozalb

I use this to change the color of a group of slots.
public class SpineSlotColorChanger : MonoBehaviour {

public string groupName;
public List<string> slots = new List<string>();
public Color color = new Color(0,0,0,1);

void Start () {
changeColor();
}

void Update () {
if (Application.isEditor){
changeColor();
}
}

void changeColor(){
SkeletonAnimation anim = GetComponent<SkeletonAnimation>();

foreach (string slotname in slots){
foreach (Spine.Slot slot in anim.skeleton.slots){
if (slotname.Equals(slot.data.name)){
slot.R = color.r;
slot.G = color.g;
slot.B = color.b;
slot.A = color.a;
}
}
}
}

public List<string> getList(){
return slots;
}
}
You can add the slot names to the list via inspector and then change the color using the ColorChanger. Of course, yo can do this at runtime too :)

Note that if you do an alpha change inside Spine (a fade in/out effect for example) you won't be able to change the color or alpha, because the color change is forced inside the json in "design" time.
karlozalb
  • Сообщения: 24

Pharan

If you want to change the color of the whole skeleton, use SkeletonAnimation's skeleton.
The Skeleton class has r, g, b and a fields. you can change at run time.

Note that the Skeleton object is a Spine-C# class and not a Spine-Unity class so it has no knowledge of the UnityEngine.Color type.
So you can/need to change those fields individually.

r, g, b and a are just plain float fields. They normally take values between 0f to 1f.

**For example:**
To make the skeleton 50% opaque, your code could say:
Spine.Skeleton skeleton = GetComponent<SkeletonAnimation>().skeleton;
skeleton.a = 0.5f;
This doesn't need to be done every Update().

Note that fading out a whole character comprised of many parts using this will still fade out the parts individually. So depending on the style, things may look weird at 50% opacity. Try it out to see what I mean.
Аватара пользователя
Pharan
  • Сообщения: 5366

AoF

Pharan писал(а):If you want to change the color of the whole skeleton, use SkeletonAnimation's skeleton.
The Skeleton class has r, g, b and a fields. you can change at run time.

Note that the Skeleton object is a Spine-C# class and not a Spine-Unity class so it has no knowledge of the UnityEngine.Color type.
So you can/need to change those fields individually.

r, g, b and a are just plain float fields. They normally take values between 0f to 1f.

**For example:**
To make the skeleton 50% opaque, your code could say:
Spine.Skeleton skeleton = GetComponent<SkeletonAnimation>().skeleton;
skeleton.a = 0.5f;
Is there a way to expose this field in the editor so I can do it as a unity animation instead of in code?
Note that fading out a whole character comprised of many parts using this will still fade out the parts individually. So depending on the style, things may look weird at 50% opacity. Try it out to see what I mean.
Can you give an example of why that would look weird? Is it because some slots might look correct at 25%, but when you fade this way, it'll temporarily increase the opacity?
AoF
  • Сообщения: 49

Harald

This thread shows an example of what it looks like if you apply transparency to a character - parts in the back that are usually hidden by overlapping parts in front of it shine through:
Help plz! How do I make my character translucent in Unity?

So in many cases, you don't really want to have this kind of 50% transparency result.
The render-to-texture solution described in the above forum thread would yield the correct result. We will provide an example scene in the future that demonstrates how to properly set things up with render textures, etc.
Аватара пользователя
Harald

Harri
  • Сообщения: 1028

AoF

Harald писал(а):This thread shows an example of what it looks like if you apply transparency to a character - parts in the back that are usually hidden by overlapping parts in front of it shine through:
Help plz! How do I make my character translucent in Unity?

So in many cases, you don't really want to have this kind of 50% transparency result.
The render-to-texture solution described in the above forum thread would yield the correct result. We will provide an example scene in the future that demonstrates how to properly set things up with render textures, etc.
Unless I'm misunderstanding, that solution is in korean. Is there an english version?
AoF
  • Сообщения: 49

Harald

The relevant postings by us are bilingual. Each paragraph is a pair of Korean text above and English text right below, with identical content.
Аватара пользователя
Harald

Harri
  • Сообщения: 1028


Вернуться в Runtimes