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.
122 lines
3.4 KiB
122 lines
3.4 KiB
using Spine;
|
|
using Spine.Unity;
|
|
using Spine.Unity.AttachmentTools;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class WpTest2 : 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 Texture2D tx2dRunAtlas;
|
|
private Material matRunAtlas;
|
|
private Skin skinCustom;
|
|
private Skin skinRepack;
|
|
#endregion Universal
|
|
|
|
|
|
#region Skeleton Animation
|
|
[Header("Skeleton Animation")]
|
|
public bool useSkeletonAnimation = true;
|
|
public SkeletonAnimation skAnim;
|
|
private Skeleton skeletonAnim;
|
|
private MeshRenderer mrendAnim;
|
|
#endregion Skeleton Animation
|
|
|
|
|
|
#region Skeleton Graphic
|
|
[Header("Skeleton Graphic")]
|
|
public bool useSkeletonGraphic = true;
|
|
public SkeletonGraphic skGraphic;
|
|
private Skeleton skeletonGraphic;
|
|
#endregion Skeleton Graphic
|
|
|
|
|
|
// Start is called before the first frame update
|
|
private IEnumerator Start()
|
|
{
|
|
skeletonAnim = skAnim.Skeleton;
|
|
mrendAnim = skAnim.GetComponent<MeshRenderer>();
|
|
skeletonGraphic = skGraphic.Skeleton;
|
|
yield return null;
|
|
AtlasUtilities.ClearCache();
|
|
Resources.UnloadUnusedAssets();
|
|
|
|
yield return new WaitForSeconds(3f);
|
|
StartCoroutine(ChangeWeapon());
|
|
}
|
|
|
|
private IEnumerator ChangeWeapon()
|
|
{
|
|
#region Universal
|
|
skinCustom = skinCustom ?? new Skin("customskin");
|
|
Skin skintemp = skeletonAnim.Data.FindSkin(skinName);
|
|
|
|
int islotindexwp = skeletonAnim.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(skeletonAnim.Data.DefaultSkin);
|
|
skinRepack.AddSkin(skinCustom);
|
|
|
|
if (matRunAtlas)
|
|
Destroy(matRunAtlas);
|
|
if (tx2dRunAtlas)
|
|
Destroy(tx2dRunAtlas);
|
|
skinRepack = skinRepack.GetRepackedSkin("repackskin", matBase, out matRunAtlas, out tx2dRunAtlas, textureFormat: txFormat);
|
|
}
|
|
yield return null;
|
|
#endregion Universal
|
|
|
|
|
|
#region Animation
|
|
if (useSkeletonAnimation)
|
|
{
|
|
if (rePack)
|
|
skeletonAnim.SetSkin(skinRepack);
|
|
else
|
|
skeletonAnim.SetSkin(skinCustom);
|
|
|
|
skeletonAnim.SetSlotsToSetupPose();
|
|
skAnim.Update(0f);
|
|
yield return null;
|
|
}
|
|
#endregion Animation
|
|
|
|
|
|
#region Graphic
|
|
if (useSkeletonGraphic)
|
|
{
|
|
if (rePack)
|
|
skeletonGraphic.SetSkin(skinRepack);
|
|
else
|
|
skeletonGraphic.SetSkin(skinCustom);
|
|
|
|
//skeletonGraphic.SetSlotsToSetupPose();
|
|
skeletonGraphic.SetToSetupPose();
|
|
skGraphic.Update(0f);
|
|
skGraphic.OverrideTexture = tx2dRunAtlas;
|
|
}
|
|
#endregion Graphic
|
|
|
|
|
|
yield return null;
|
|
AtlasUtilities.ClearCache();
|
|
Resources.UnloadUnusedAssets();
|
|
}
|
|
|
|
}
|