Hey so I've looked pretty much all over the forums and found a bunch of posts on this already but I am having a small problem.
First what I'm trying to do: At the start I want to randomly pick a head and body for a character. That's it
So I've read through these:
http://esotericsoftware.com/forum/Costumizable-itens-with-more-than-one-view-slot-UNITY-4662?p=27521#p27521
http://esotericsoftware.com/forum/tk2d-Creating-skin-programmatically-1470
http://esotericsoftware.com/forum/Sprite-Attacher-Some-Problem-6990?p=32189&hilit=attachment+null#p32189
http://esotericsoftware.com/forum/Combining-Skins-Additive-6507?p=29904&hilit=mix+match+skins#p29904
And I am using something similar to what Pharan wrote for the Mix and Match stuff but when I run it, it tells me that my Attachment is null.
Here is the code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Spine;
using Spine.Unity;
using Spine.Unity.Modules;
public class RandomVillagerSkin : MonoBehaviour {
public SkeletonAnimation skeletonAnim;
Skeleton skeleton;
SkeletonData data;
string[] headSlots = new string[] {
"ear", "ear_ring", "face",
"hair", "hair_2", "hair_3",
"mounth",
};
void Start () {
skeleton = skeletonAnim.skeleton;
data = skeleton.Data;
selectVillagerSkin();
}
void selectVillagerSkin() {
Skin randomSkin = new Skin("Random Skin");
int randomBody = Random.Range(0, 2);
int randomHead = Random.Range(0, 2);
string currentHeadName = "Villager_1";
if (randomHead == 1) {
currentHeadName = "Villager_2";
} else if (randomHead == 2) {
currentHeadName = "Villager_3";
}
for (int i = 0; i < headSlots.Length; i++) {
int slotIndex = skeleton.FindSlotIndex(headSlots[i]);
Skin attachmentSource = data.FindSkin(currentHeadName);
randomSkin.AddAttachment(slotIndex, headSlots[i], attachmentSource.GetAttachment(slotIndex, headSlots[i]));
}
skeleton.SetSkin(randomSkin);
skeleton.SetSlotsToSetupPose();
}
}
08 Sep 2016, 16:34
So I actually figured part of it out after leaving it for a second and coming back to it.
What it is that some slots have multiple images on them. For example the mouth slot has two images one for open and one for closed. So I have to get a list of the attachments.