From 22a0cdc3ac72b3939cc93aca95d81b35e5a53952 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 19 Mar 2019 16:53:06 +0100 Subject: [PATCH 1/3] [csharp] Fixed differences in Slot between csharp and ref-impl. Noticed before porting commit bd306d4 on 3.8-beta branch. See #1294 and #1303. --- spine-csharp/src/Slot.cs | 100 +++++++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 9 deletions(-) diff --git a/spine-csharp/src/Slot.cs b/spine-csharp/src/Slot.cs index 6151aa9a8..38113176e 100644 --- a/spine-csharp/src/Slot.cs +++ b/spine-csharp/src/Slot.cs @@ -31,6 +31,12 @@ using System; namespace Spine { + + /// + /// Stores a slot's current pose. Slots organize attachments for {@link Skeleton#drawOrder} purposes and provide a place to store + /// state for an attachment.State cannot be stored in an attachment itself because attachments are stateless and may be shared + /// across multiple skeletons. + /// public class Slot { internal SlotData data; internal Bone bone; @@ -41,22 +47,83 @@ namespace Spine { internal float attachmentTime; internal ExposedList attachmentVertices = new ExposedList(); + public Slot (SlotData data, Bone bone) { + if (data == null) throw new ArgumentNullException("data", "data cannot be null."); + if (bone == null) throw new ArgumentNullException("bone", "bone cannot be null."); + this.data = data; + this.bone = bone; + + // darkColor = data.darkColor == null ? null : new Color(); + if (data.hasSecondColor) { + r2 = g2 = b2 = 0; + } + + SetToSetupPose(); + } + + /// Copy constructor. + public Slot(Slot slot, Bone bone) { + if (slot == null) throw new ArgumentNullException("slot", "slot cannot be null."); + if (bone == null) throw new ArgumentNullException("bone", "bone cannot be null."); + data = slot.data; + this.bone = bone; + r = slot.r; + g = slot.g; + b = slot.b; + a = slot.a; + + // darkColor = slot.darkColor == null ? null : new Color(slot.darkColor); + if (slot.hasSecondColor) { + r2 = slot.r2; + g2 = slot.g2; + b2 = slot.b2; + } else { + r2 = g2 = b2 = 0; + } + hasSecondColor = slot.hasSecondColor; + + attachment = slot.attachment; + attachmentTime = slot.attachmentTime; + } + + /// The slot's setup pose data. public SlotData Data { get { return data; } } + /// The bone this slot belongs to. public Bone Bone { get { return bone; } } + /// The skeleton this slot belongs to. public Skeleton Skeleton { get { return bone.skeleton; } } + /// The color used to tint the slot's attachment. If is set, this is used as the light color for two + /// color tinting. public float R { get { return r; } set { r = value; } } + /// The color used to tint the slot's attachment. If is set, this is used as the light color for two + /// color tinting. public float G { get { return g; } set { g = value; } } + /// The color used to tint the slot's attachment. If is set, this is used as the light color for two + /// color tinting. public float B { get { return b; } set { b = value; } } + /// The color used to tint the slot's attachment. If is set, this is used as the light color for two + /// color tinting. public float A { get { return a; } set { a = value; } } + /// The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used. + /// public float R2 { get { return r2; } set { r2 = value; } } + /// The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used. + /// public float G2 { get { return g2; } set { g2 = value; } } + /// The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used. + /// public float B2 { get { return b2; } set { b2 = value; } } + /// Whether R2 G2 B2 are used to tint the slot's attachment for two color tinting. False if two color tinting is not used. public bool HasSecondColor { get { return data.hasSecondColor; } set { data.hasSecondColor = value; } } - /// May be null. public Attachment Attachment { + /// The current attachment for the slot, or null if the slot has no attachment. get { return attachment; } + /// + /// Sets the slot's attachment and, if the attachment changed, resets and clears + /// . + /// May be null. set { if (attachment == value) return; attachment = value; @@ -65,26 +132,41 @@ namespace Spine { } } + /// The time that has elapsed since the last time the attachment was set or cleared. Relies on Skeleton + /// public float AttachmentTime { get { return bone.skeleton.time - attachmentTime; } set { attachmentTime = bone.skeleton.time - value; } } - public ExposedList AttachmentVertices { get { return attachmentVertices; } set { attachmentVertices = value; } } - - public Slot (SlotData data, Bone bone) { - if (data == null) throw new ArgumentNullException("data", "data cannot be null."); - if (bone == null) throw new ArgumentNullException("bone", "bone cannot be null."); - this.data = data; - this.bone = bone; - SetToSetupPose(); + /// Vertices to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a + /// weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions. + /// + /// See and . + public ExposedList AttachmentVertices { + get { + return attachmentVertices; + } + set { + if (attachmentVertices == null) throw new ArgumentNullException("attachmentVertices", "attachmentVertices cannot be null."); + attachmentVertices = value; + } } + /// Sets this slot to the setup pose. public void SetToSetupPose () { r = data.r; g = data.g; b = data.b; a = data.a; + + // if (darkColor != null) darkColor.set(data.darkColor); + if (HasSecondColor) { + r2 = data.r2; + g2 = data.g2; + b2 = data.b2; + } + if (data.attachmentName == null) Attachment = null; else { From 0d44a041e971834aa8630f6a63b7cd6fb144ee70 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 20 Mar 2019 18:16:29 +0100 Subject: [PATCH 2/3] [unity] Added missing `Create 2D Hinge Chain` button at SkeletonUtilityBone inspector, only 3D version was available. Closes #1310. --- .../Editor/SkeletonUtilityBoneInspector.cs | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs index 4f339a7e2..58d21b995 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs @@ -28,10 +28,8 @@ * POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -//#define HINGECHAIN2D // Contributed by: Mitch Thompson - using UnityEngine; using UnityEditor; using System.Collections.Generic; @@ -177,8 +175,10 @@ namespace Spine.Unity.Editor { using (new GUILayout.HorizontalScope()) { EditorGUILayout.Space(); using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || !canCreateHingeChain)) { - if (GUILayout.Button(SpineInspectorUtility.TempContent("Create Hinge Chain", Icons.hingeChain), GUILayout.Width(150), GUILayout.Height(24))) + if (GUILayout.Button(SpineInspectorUtility.TempContent("Create 3D Hinge Chain", Icons.hingeChain), GUILayout.MinWidth(120), GUILayout.Height(24))) CreateHingeChain(); + if (GUILayout.Button(SpineInspectorUtility.TempContent("Create 2D Hinge Chain", Icons.hingeChain), GUILayout.MinWidth(120), GUILayout.Height(24))) + CreateHingeChain2D(); } EditorGUILayout.Space(); } @@ -277,17 +277,20 @@ namespace Spine.Unity.Editor { EditorGUIUtility.PingObject(go); } - -#if HINGECHAIN2D bool CanCreateHingeChain () { - if (utilityBone == null) return false; - if (utilityBone.GetComponent() != null) return false; - if (utilityBone.bone != null && utilityBone.bone.Children.Count == 0) return false; - var rigidbodies = utilityBone.GetComponentsInChildren(); - return rigidbodies.Length <= 0; + if (utilityBone == null) + return false; + if (utilityBone.GetComponent() != null || utilityBone.GetComponent() != null) + return false; + if (utilityBone.bone != null && utilityBone.bone.Children.Count == 0) + return false; + + var rigidbodies = utilityBone.GetComponentsInChildren(); + var rigidbodies2D = utilityBone.GetComponentsInChildren(); + return rigidbodies.Length <= 0 && rigidbodies2D.Length <= 0; } - void CreateHingeChain () { + void CreateHingeChain2D () { var utilBoneArr = utilityBone.GetComponentsInChildren(); foreach (var utilBone in utilBoneArr) { @@ -324,19 +327,6 @@ namespace Spine.Unity.Editor { utilBone.GetComponent().mass = utilBone.transform.parent.GetComponent().mass * 0.75f; } } -#else - bool CanCreateHingeChain () { - if (utilityBone == null) - return false; - if (utilityBone.GetComponent() != null) - return false; - if (utilityBone.bone != null && utilityBone.bone.Children.Count == 0) - return false; - - var rigidbodies = utilityBone.GetComponentsInChildren(); - - return rigidbodies.Length <= 0; - } void CreateHingeChain () { var utilBoneArr = utilityBone.GetComponentsInChildren(); @@ -380,7 +370,6 @@ namespace Spine.Unity.Editor { utilBone.gameObject.AddComponent(); } -#endif } } From 91532f19b10e5a6f1b8b84c4ada7094fd2d46fcc Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 26 Mar 2019 17:00:11 +0100 Subject: [PATCH 3/3] [unity] Fixed wrong atlas assets being assigned upon import when multiple skeletons are exported to the same directory. Closes #1312. --- .../Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs index eb2129b39..56c5faa24 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs @@ -638,8 +638,8 @@ namespace Spine.Unity.Editor { requiredPaths.Add((string)data["path"]); else if (data.ContainsKey("name")) requiredPaths.Add((string)data["name"]); - //else - // requiredPaths.Add(attachment.Key); + else + requiredPaths.Add(attachment.Key); } } }