You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
68 lines
1.8 KiB
using Spine;
|
|
using Spine.Unity;
|
|
using Spine.Unity.AttachmentTools;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class SpineSkinTest : MonoBehaviour
|
|
{
|
|
[SerializeField] Material charMat;
|
|
|
|
SkeletonAnimation skeletonAnimation;
|
|
Skeleton skeleton => skeletonAnimation.Skeleton;
|
|
|
|
int totalCostumeCount;
|
|
int totalWeaponCount;
|
|
|
|
int skinIndex = 1;
|
|
int weaponSkinIndex = 1;
|
|
|
|
private void Awake()
|
|
{
|
|
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
|
|
|
totalCostumeCount = skeleton.Data.Skins.Count((s) => s.Name.Contains("Costume/"));
|
|
totalWeaponCount = skeleton.Data.Skins.Count((s) => s.Name.Contains("Weapon/"));
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
SetCustomSkin();
|
|
}
|
|
|
|
[ContextMenu("Change Costume")]
|
|
private void ChangeCostume()
|
|
{
|
|
if(totalCostumeCount == 0) return;
|
|
skinIndex = (skinIndex + 1) % (totalCostumeCount + 1);
|
|
SetCustomSkin();
|
|
}
|
|
|
|
[ContextMenu("Change Weapon Skin")]
|
|
private void ChangeWeaponSkin()
|
|
{
|
|
if(totalWeaponCount == 0) return;
|
|
weaponSkinIndex = (weaponSkinIndex + 1) % (totalWeaponCount + 1);
|
|
SetCustomSkin();
|
|
}
|
|
|
|
private void SetCustomSkin()
|
|
{
|
|
var newSkin = new Skin("custom");
|
|
newSkin.AddSkin(skeleton.Data.DefaultSkin);
|
|
|
|
if(skeleton.Data.TryGetSkin($"Costume/{skinIndex}", out Skin costumeSkin))
|
|
newSkin.AddSkin(costumeSkin);
|
|
|
|
if(skeleton.Data.TryGetSkin($"Weapon/{weaponSkinIndex}", out Skin weaponSkin))
|
|
newSkin.AddSkin(weaponSkin);
|
|
|
|
var repackedSkin = newSkin.GetRepackedSkin("custom", charMat, out var newMat, out var newTex);
|
|
|
|
skeleton.SetSkin(repackedSkin);
|
|
skeleton.SetSlotsToSetupPose();
|
|
skeletonAnimation.Update(0);
|
|
|
|
AtlasUtilities.ClearCache();
|
|
}
|
|
}
|