using Spine; using Spine.Unity; using Spine.Unity.AttachmentTools; using System.Collections; using UnityEngine; public class WpTest : MonoBehaviour { #region Universal [Header("Universal")] public bool rePack = false; public TextureFormat txFormat = TextureFormat.RGBA32; public string skinName = "base"; public string slotName = "gun"; public string attachmentName = "gun"; public Material matBase; public Sprite sprWeapon; private Skeleton skeleton; private Texture2D tx2dRunAtlas; private Material matRunAtlas; private Skin skinCustom; private Skin skinRepack; #endregion Universal #region Skeleton Animation [Header("Skeleton Animation")] public bool useSkeletonAnimation = false; public SkeletonAnimation skAnim; private MeshRenderer mrendAnim; #endregion Skeleton Animation #region Skeleton Graphic [Header("Skeleton Graphic")] public bool useSkeletonGraphic = false; public SkeletonGraphic skGraphic; #endregion Skeleton Graphic // Start is called before the first frame update private IEnumerator Start() { if (skAnim != null) { skeleton = skAnim.Skeleton; mrendAnim = skAnim.GetComponent(); } if (skGraphic != null) { skeleton = skGraphic.Skeleton; } yield return null; yield return new WaitForSeconds(3f); ChangeWeapon(); } private void ChangeWeapon() { // ½ºÄÌ·¹Åæ ¾Ö´Ï¸ÞÀÌ¼Ç ¹«±â º¯°æ. if (useSkeletonAnimation) { skinCustom = skinCustom ?? new Skin("customskin"); //if (skinCustom == null) // skinCustom = new Skin("customskin"); //else // skinCustom.Clear(); Skin skintemp = skeleton.Data.FindSkin(skinName); int islotindexwp = skeleton.Data.FindSlot(slotName).Index; Attachment atchtemp = skintemp.GetAttachment(islotindexwp, attachmentName); Attachment atchwp = atchtemp.GetRemappedClone(sprWeapon, matBase, pivotShiftsMeshUVCoords: false); if (atchwp != null) skinCustom.SetAttachment(islotindexwp, attachmentName, atchwp); if (rePack) { skinRepack = new Skin("repackskin"); skinRepack.AddSkin(skeleton.Data.DefaultSkin); skinRepack.AddSkin(skinCustom); if (matRunAtlas) Destroy(matRunAtlas); if (tx2dRunAtlas) Destroy(tx2dRunAtlas); skinRepack = skinRepack.GetRepackedSkin("repackskin", matBase, out matRunAtlas, out tx2dRunAtlas, textureFormat: txFormat); skeleton.SetSkin(skinRepack); } else { skeleton.SetSkin(skinCustom); } skeleton.SetSlotsToSetupPose(); skAnim.Update(0f); } // ½ºÄÌ·¹Åæ ±×·¡ÇÈ ¹«±â º¯°æ. if (useSkeletonGraphic) { skinCustom = skinCustom ?? new Skin("customskin"); Skin skintemp = skeleton.Data.FindSkin(skinName); int islotindexwp = skeleton.Data.FindSlot(slotName).Index; Attachment atchtemp = skintemp.GetAttachment(islotindexwp, attachmentName); Attachment atchwp = atchtemp.GetRemappedClone(sprWeapon, matBase); if (atchwp != null) skinCustom.SetAttachment(islotindexwp, attachmentName, atchwp); if (rePack) { skinRepack = new Skin("repackskin"); skinRepack.AddSkin(skeleton.Data.DefaultSkin); skinRepack.AddSkin(skinCustom); if (matRunAtlas) Destroy(matRunAtlas); if (tx2dRunAtlas) Destroy(tx2dRunAtlas); //skinRepack = skinRepack.GetRepackedSkin("repackskin", matBase, out matRunAtlas, out tx2dRunAtlas, maxAtlasSize: 2048, textureFormat: txFormat); skinRepack = skinRepack.GetRepackedSkin("repackskin", matBase, out matRunAtlas, out tx2dRunAtlas, textureFormat: txFormat); skeleton.SetSkin(skinRepack); } else { skeleton.SetSkin(skinCustom); } //skeleton.SetSlotsToSetupPose(); skeleton.SetToSetupPose(); skGraphic.Update(0f); skGraphic.OverrideTexture = tx2dRunAtlas; } } }