Harald escreveuYou should be able to assign a repacked skin to multiple skeletons, just call skeleton.SetSkin(mySharedSkin)
on multiple skeletons instead of once.
I called skeleton.SetSkin(mySharedSkin) and then second character is missing material, So I did the following processing,still not working:
//save the first character skin and texture
repackedSkin=repackedSkin.GetRepackedSkin(templateSkinName, sourceMaterial, out runtimeMaterial, out runtimeAtlas);
skeleton.SetSkin(repackedSkin);
//get the clone of the first character texture not reference
Texture2D copyTexture = new Texture2D(runtimeAtlas.width, runtimeAtlas.height);
copyTexture.SetPixels(runtimeAtlas.GetPixels());
copyTexture.Apply();
//put first character skin and texture in an object with id "1"
DuckSkinPool.AddSkin("1",new DuckSkin(repackedSkin,copyTexture));
//////////////////////////////////////////////////////////////////
//set second character skin
DuckSkin duckSkin = DuckSkinPool.GetSkin("1");
skeleton.SetSkin(duckSkin.Skin);
//not working
//GetComponent<MeshRenderer>().material = duckSkin.Material;
GetComponent<SkeletonMecanim>().CustomMaterialOverride.Add(runtimeMaterial, duckSkin.Material);
GetComponent<SkeletonMecanim>().CustomMaterialOverride.Remove(runtimeMaterial);
//////////////////////////////////////////////////////////////////
public class DuckSkin
{
public Skin Skin;
public Texture2D Texture;
public DuckSkin(Skin skin,Texture2D texture)
{
Skin = skin;
Texture = texture;
}
public Material Material
{
get
{
var m = new Material(Shader.Find("Spine/Skeleton"));
m.mainTexture = Texture;
return m;
}
}
}