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.
53 lines
1.6 KiB
53 lines
1.6 KiB
using Spine;
|
|
using Spine.Unity;
|
|
using Spine.Unity.AttachmentTools;
|
|
using UnityEngine;
|
|
|
|
// UI등에서 사용되는 간단한 캐릭터 애니메이션(전투 등 불가).
|
|
public class IVCharSimple : MonoBehaviour
|
|
{
|
|
[SerializeField] SkeletonAnimation skAnim;
|
|
|
|
Skeleton skeleton;
|
|
Material mainMaterial;
|
|
|
|
int currentCostumeID = -1;
|
|
int currentWeaponID = -1;
|
|
|
|
public void Init()
|
|
{
|
|
skeleton = skAnim.Skeleton;
|
|
|
|
var renderer = skAnim.GetComponent<MeshRenderer>();
|
|
mainMaterial = renderer.sharedMaterial;
|
|
}
|
|
|
|
#region Costume & Color
|
|
public void SetCostume(int costumeID) => SetSkin(costumeID, currentWeaponID);
|
|
public void SetWeapon(int weaponID) => SetSkin(currentCostumeID, weaponID);
|
|
public void SetSkin(int costumeID, int weaponID)
|
|
{
|
|
if (costumeID == currentCostumeID && weaponID == currentWeaponID) return;
|
|
|
|
currentCostumeID = costumeID;
|
|
currentWeaponID = weaponID;
|
|
|
|
var newSkin = new Skin("Custom");
|
|
newSkin.AddSkin(skeleton.Data.DefaultSkin);
|
|
|
|
if (skeleton.Data.TryGetSkin($"Costume/{currentCostumeID}", out Skin costumeSkin))
|
|
newSkin.AddSkin(costumeSkin);
|
|
|
|
if (skeleton.Data.TryGetSkin($"Weapon/{currentWeaponID}", out Skin weaponSkin))
|
|
newSkin.AddSkin(weaponSkin);
|
|
|
|
var repackedSkin = newSkin.GetRepackedSkin("custom", mainMaterial, out var newMat, out var newTex);
|
|
|
|
skeleton.SetSkin(repackedSkin);
|
|
skeleton.SetSlotsToSetupPose();
|
|
skAnim.Update(0);
|
|
|
|
AtlasUtilities.ClearCache();
|
|
}
|
|
#endregion Costume & color
|
|
}
|