mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 02:06:03 +08:00
[csharp] Fixed differences in Slot between csharp and ref-impl. Noticed before porting commit bd306d4. See #1294 and #1303.
This commit is contained in:
parent
18acce0354
commit
37b759fc17
@ -31,6 +31,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Spine {
|
namespace Spine {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
public class Slot {
|
public class Slot {
|
||||||
internal SlotData data;
|
internal SlotData data;
|
||||||
internal Bone bone;
|
internal Bone bone;
|
||||||
@ -39,52 +45,128 @@ namespace Spine {
|
|||||||
internal bool hasSecondColor;
|
internal bool hasSecondColor;
|
||||||
internal Attachment attachment;
|
internal Attachment attachment;
|
||||||
internal float attachmentTime;
|
internal float attachmentTime;
|
||||||
internal ExposedList<float> attachmentVertices = new ExposedList<float>();
|
internal ExposedList<float> attachmentVertices = new ExposedList<float>();
|
||||||
|
|
||||||
public SlotData Data { get { return data; } }
|
|
||||||
public Bone Bone { get { return bone; } }
|
|
||||||
public Skeleton Skeleton { get { return bone.skeleton; } }
|
|
||||||
public float R { get { return r; } set { r = value; } }
|
|
||||||
public float G { get { return g; } set { g = value; } }
|
|
||||||
public float B { get { return b; } set { b = value; } }
|
|
||||||
public float A { get { return a; } set { a = value; } }
|
|
||||||
|
|
||||||
public float R2 { get { return r2; } set { r2 = value; } }
|
|
||||||
public float G2 { get { return g2; } set { g2 = value; } }
|
|
||||||
public float B2 { get { return b2; } set { b2 = value; } }
|
|
||||||
public bool HasSecondColor { get { return data.hasSecondColor; } set { data.hasSecondColor = value; } }
|
|
||||||
|
|
||||||
/// <summary>May be null.</summary>
|
|
||||||
public Attachment Attachment {
|
|
||||||
get { return attachment; }
|
|
||||||
set {
|
|
||||||
if (attachment == value) return;
|
|
||||||
attachment = value;
|
|
||||||
attachmentTime = bone.skeleton.time;
|
|
||||||
attachmentVertices.Clear(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float AttachmentTime {
|
|
||||||
get { return bone.skeleton.time - attachmentTime; }
|
|
||||||
set { attachmentTime = bone.skeleton.time - value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExposedList<float> AttachmentVertices { get { return attachmentVertices; } set { attachmentVertices = value; } }
|
|
||||||
|
|
||||||
public Slot (SlotData data, Bone bone) {
|
public Slot (SlotData data, Bone bone) {
|
||||||
if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
|
if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
|
||||||
if (bone == null) throw new ArgumentNullException("bone", "bone cannot be null.");
|
if (bone == null) throw new ArgumentNullException("bone", "bone cannot be null.");
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.bone = bone;
|
this.bone = bone;
|
||||||
|
|
||||||
|
// darkColor = data.darkColor == null ? null : new Color();
|
||||||
|
if (data.hasSecondColor) {
|
||||||
|
r2 = g2 = b2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
SetToSetupPose();
|
SetToSetupPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Copy constructor.</summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The slot's setup pose data.</summary>
|
||||||
|
public SlotData Data { get { return data; } }
|
||||||
|
/// <summary>The bone this slot belongs to.</summary>
|
||||||
|
public Bone Bone { get { return bone; } }
|
||||||
|
/// <summary>The skeleton this slot belongs to.</summary>
|
||||||
|
public Skeleton Skeleton { get { return bone.skeleton; } }
|
||||||
|
/// <summary>The color used to tint the slot's attachment. If <see cref="HasSecondColor"/> is set, this is used as the light color for two
|
||||||
|
/// color tinting.</summary>
|
||||||
|
public float R { get { return r; } set { r = value; } }
|
||||||
|
/// <summary>The color used to tint the slot's attachment. If <see cref="HasSecondColor"/> is set, this is used as the light color for two
|
||||||
|
/// color tinting.</summary>
|
||||||
|
public float G { get { return g; } set { g = value; } }
|
||||||
|
/// <summary>The color used to tint the slot's attachment. If <see cref="HasSecondColor"/> is set, this is used as the light color for two
|
||||||
|
/// color tinting.</summary>
|
||||||
|
public float B { get { return b; } set { b = value; } }
|
||||||
|
/// <summary>The color used to tint the slot's attachment. If <see cref="HasSecondColor"/> is set, this is used as the light color for two
|
||||||
|
/// color tinting.</summary>
|
||||||
|
public float A { get { return a; } set { a = value; } }
|
||||||
|
|
||||||
|
/// <summary>The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used.</summary>
|
||||||
|
/// <seealso cref="HasSecondColor"/>
|
||||||
|
public float R2 { get { return r2; } set { r2 = value; } }
|
||||||
|
/// <summary>The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used.</summary>
|
||||||
|
/// <seealso cref="HasSecondColor"/>
|
||||||
|
public float G2 { get { return g2; } set { g2 = value; } }
|
||||||
|
/// <summary>The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used.</summary>
|
||||||
|
/// <seealso cref="HasSecondColor"/>
|
||||||
|
public float B2 { get { return b2; } set { b2 = value; } }
|
||||||
|
/// <summary>Whether R2 G2 B2 are used to tint the slot's attachment for two color tinting. False if two color tinting is not used.</summary>
|
||||||
|
public bool HasSecondColor { get { return data.hasSecondColor; } set { data.hasSecondColor = value; } }
|
||||||
|
|
||||||
|
public Attachment Attachment {
|
||||||
|
/// <summary>The current attachment for the slot, or null if the slot has no attachment.</summary>
|
||||||
|
get { return attachment; }
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the slot's attachment and, if the attachment changed, resets <see cref="AttachmentTime"/> and clears
|
||||||
|
/// <see cref="AttachmentVertices">.</summary>
|
||||||
|
/// <param name="value">May be null.</param>
|
||||||
|
set {
|
||||||
|
if (attachment == value) return;
|
||||||
|
attachment = value;
|
||||||
|
attachmentTime = bone.skeleton.time;
|
||||||
|
attachmentVertices .Clear(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> The time that has elapsed since the last time the attachment was set or cleared. Relies on Skeleton
|
||||||
|
/// <see cref="Skeleton.Time"/></summary>
|
||||||
|
public float AttachmentTime {
|
||||||
|
get { return bone.skeleton.time - attachmentTime; }
|
||||||
|
set { attachmentTime = bone.skeleton.time - value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> 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.
|
||||||
|
/// <para />
|
||||||
|
/// See <see cref="VertexAttachment.ComputeWorldVertices(Slot, int, int, float[], int, int)"/> and <see cref="DeformTimeline"/>.</summary>
|
||||||
|
public ExposedList<float> AttachmentVertices {
|
||||||
|
get {
|
||||||
|
return attachmentVertices ;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (attachmentVertices == null) throw new ArgumentNullException("attachmentVertices", "attachmentVertices cannot be null.");
|
||||||
|
attachmentVertices = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Sets this slot to the setup pose.</summary>
|
||||||
public void SetToSetupPose () {
|
public void SetToSetupPose () {
|
||||||
r = data.r;
|
r = data.r;
|
||||||
g = data.g;
|
g = data.g;
|
||||||
b = data.b;
|
b = data.b;
|
||||||
a = data.a;
|
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)
|
if (data.attachmentName == null)
|
||||||
Attachment = null;
|
Attachment = null;
|
||||||
else {
|
else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user