From 53693c3faff900864ec8a4c89c8ed1a2f1866723 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 24 Jan 2016 10:17:32 +0800 Subject: [PATCH] [Unity] Comments for CustomSkin.cs --- spine-unity/Assets/spine-unity/CustomSkin.cs | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/spine-unity/Assets/spine-unity/CustomSkin.cs b/spine-unity/Assets/spine-unity/CustomSkin.cs index ea74d572a..fab223b14 100644 --- a/spine-unity/Assets/spine-unity/CustomSkin.cs +++ b/spine-unity/Assets/spine-unity/CustomSkin.cs @@ -35,33 +35,47 @@ using Spine; public class CustomSkin : MonoBehaviour { - [System.Serializable] public class SkinPair { + /// SpineAttachment attachment path to help find the attachment. + /// This use of SpineAttachment generates an attachment path string that can only be used by SpineAttachment.GetAttachment. [SpineAttachment(currentSkinOnly: false, returnAttachmentPath: true, dataField: "skinSource")] - public string sourceAttachment; + [UnityEngine.Serialization.FormerlySerializedAs("sourceAttachment")] + public string sourceAttachmentPath; + [SpineSlot] public string targetSlot; + + /// The name of the skin placeholder/skin dictionary entry this attachment should be associated with. + /// This name is used by the skin dictionary, used in the method Skin.AddAttachment as well as setting a slot attachment [SpineAttachment(currentSkinOnly: true, placeholdersOnly: true)] public string targetAttachment; } + #region Inspector public SkeletonDataAsset skinSource; - public SkinPair[] skinning; + + [UnityEngine.Serialization.FormerlySerializedAs("skinning")] + public SkinPair[] skinItems; + public Skin customSkin; + #endregion SkeletonRenderer skeletonRenderer; + void Start () { skeletonRenderer = GetComponent(); Skeleton skeleton = skeletonRenderer.skeleton; customSkin = new Skin("CustomSkin"); - foreach (var pair in skinning) { - var attachment = SpineAttachment.GetAttachment(pair.sourceAttachment, skinSource); + foreach (var pair in skinItems) { + var attachment = SpineAttachment.GetAttachment(pair.sourceAttachmentPath, skinSource); customSkin.AddAttachment(skeleton.FindSlotIndex(pair.targetSlot), pair.targetAttachment, attachment); } + // The custom skin does not need to be added to the skeleton data for it to work. + // But it's useful for your script to keep a reference to it. skeleton.SetSkin(customSkin); } }