[csharp] Port of commit cb48737: Fixed constraint copy constructors references the wrong bones. Closes #2511.

This commit is contained in:
Harald Csaszar 2024-04-29 19:09:45 +02:00
parent cb4873702d
commit 6118a5f704
6 changed files with 33 additions and 39 deletions

View File

@ -52,26 +52,24 @@ namespace Spine {
public IkConstraint (IkConstraintData data, Skeleton skeleton) { public IkConstraint (IkConstraintData data, Skeleton skeleton) {
if (data == null) throw new ArgumentNullException("data", "data cannot be null."); if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
this.data = data; this.data = data;
mix = data.mix;
softness = data.softness;
bendDirection = data.bendDirection;
compress = data.compress;
stretch = data.stretch;
bones = new ExposedList<Bone>(data.bones.Count); bones = new ExposedList<Bone>(data.bones.Count);
foreach (BoneData boneData in data.bones) foreach (BoneData boneData in data.bones)
bones.Add(skeleton.bones.Items[boneData.index]); bones.Add(skeleton.bones.Items[boneData.index]);
target = skeleton.bones.Items[data.target.index]; target = skeleton.bones.Items[data.target.index];
mix = data.mix;
softness = data.softness;
bendDirection = data.bendDirection;
compress = data.compress;
stretch = data.stretch;
} }
/// <summary>Copy constructor.</summary> /// <summary>Copy constructor.</summary>
public IkConstraint (IkConstraint constraint) { public IkConstraint (IkConstraint constraint, Skeleton skeleton)
if (constraint == null) throw new ArgumentNullException("constraint", "constraint cannot be null."); : this(constraint.data, skeleton) {
data = constraint.data;
bones = new ExposedList<Bone>(constraint.Bones.Count);
bones.AddRange(constraint.Bones);
target = constraint.target;
mix = constraint.mix; mix = constraint.mix;
softness = constraint.softness; softness = constraint.softness;
bendDirection = constraint.bendDirection; bendDirection = constraint.bendDirection;

View File

@ -64,6 +64,7 @@ namespace Spine {
bones.Add(skeleton.bones.Items[boneData.index]); bones.Add(skeleton.bones.Items[boneData.index]);
target = skeleton.slots.Items[data.target.index]; target = skeleton.slots.Items[data.target.index];
position = data.position; position = data.position;
spacing = data.spacing; spacing = data.spacing;
mixRotate = data.mixRotate; mixRotate = data.mixRotate;
@ -72,12 +73,9 @@ namespace Spine {
} }
/// <summary>Copy constructor.</summary> /// <summary>Copy constructor.</summary>
public PathConstraint (PathConstraint constraint) { public PathConstraint (PathConstraint constraint, Skeleton skeleton)
if (constraint == null) throw new ArgumentNullException("constraint cannot be null."); : this(constraint.data, skeleton) {
data = constraint.data;
bones = new ExposedList<Bone>(constraint.Bones.Count);
bones.AddRange(constraint.Bones);
target = constraint.target;
position = constraint.position; position = constraint.position;
spacing = constraint.spacing; spacing = constraint.spacing;
mixRotate = constraint.mixRotate; mixRotate = constraint.mixRotate;

View File

@ -60,7 +60,9 @@ namespace Spine {
if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null."); if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
this.data = data; this.data = data;
this.skeleton = skeleton; this.skeleton = skeleton;
bone = skeleton.bones.Items[data.bone.index]; bone = skeleton.bones.Items[data.bone.index];
inertia = data.inertia; inertia = data.inertia;
strength = data.strength; strength = data.strength;
damping = data.damping; damping = data.damping;
@ -71,11 +73,9 @@ namespace Spine {
} }
/// <summary>Copy constructor.</summary> /// <summary>Copy constructor.</summary>
public PhysicsConstraint (PhysicsConstraint constraint) { public PhysicsConstraint (PhysicsConstraint constraint, Skeleton skeleton)
if (constraint == null) throw new ArgumentNullException("constraint", "constraint cannot be null."); : this(constraint.data, skeleton) {
data = constraint.data;
skeleton = constraint.skeleton;
bone = constraint.bone;
inertia = constraint.inertia; inertia = constraint.inertia;
strength = constraint.strength; strength = constraint.strength;
damping = constraint.damping; damping = constraint.damping;

View File

@ -187,19 +187,19 @@ namespace Spine {
ikConstraints = new ExposedList<IkConstraint>(skeleton.ikConstraints.Count); ikConstraints = new ExposedList<IkConstraint>(skeleton.ikConstraints.Count);
foreach (IkConstraint ikConstraint in skeleton.ikConstraints) foreach (IkConstraint ikConstraint in skeleton.ikConstraints)
ikConstraints.Add(new IkConstraint(ikConstraint)); ikConstraints.Add(new IkConstraint(ikConstraint, skeleton));
transformConstraints = new ExposedList<TransformConstraint>(skeleton.transformConstraints.Count); transformConstraints = new ExposedList<TransformConstraint>(skeleton.transformConstraints.Count);
foreach (TransformConstraint transformConstraint in skeleton.transformConstraints) foreach (TransformConstraint transformConstraint in skeleton.transformConstraints)
transformConstraints.Add(new TransformConstraint(transformConstraint)); transformConstraints.Add(new TransformConstraint(transformConstraint, skeleton));
pathConstraints = new ExposedList<PathConstraint>(skeleton.pathConstraints.Count); pathConstraints = new ExposedList<PathConstraint>(skeleton.pathConstraints.Count);
foreach (PathConstraint pathConstraint in skeleton.pathConstraints) foreach (PathConstraint pathConstraint in skeleton.pathConstraints)
pathConstraints.Add(new PathConstraint(pathConstraint)); pathConstraints.Add(new PathConstraint(pathConstraint, skeleton));
physicsConstraints = new ExposedList<PhysicsConstraint>(skeleton.physicsConstraints.Count); physicsConstraints = new ExposedList<PhysicsConstraint>(skeleton.physicsConstraints.Count);
foreach (PhysicsConstraint physicsConstraint in skeleton.physicsConstraints) foreach (PhysicsConstraint physicsConstraint in skeleton.physicsConstraints)
physicsConstraints.Add(new PhysicsConstraint(physicsConstraint)); physicsConstraints.Add(new PhysicsConstraint(physicsConstraint, skeleton));
skin = skeleton.skin; skin = skeleton.skin;
r = skeleton.r; r = skeleton.r;

View File

@ -51,27 +51,25 @@ namespace Spine {
if (data == null) throw new ArgumentNullException("data", "data cannot be null."); if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null."); if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
this.data = data; this.data = data;
mixRotate = data.mixRotate;
mixX = data.mixX;
mixY = data.mixY;
mixScaleX = data.mixScaleX;
mixScaleY = data.mixScaleY;
mixShearY = data.mixShearY;
bones = new ExposedList<Bone>(); bones = new ExposedList<Bone>();
foreach (BoneData boneData in data.bones) foreach (BoneData boneData in data.bones)
bones.Add(skeleton.bones.Items[boneData.index]); bones.Add(skeleton.bones.Items[boneData.index]);
target = skeleton.bones.Items[data.target.index]; target = skeleton.bones.Items[data.target.index];
mixRotate = data.mixRotate;
mixX = data.mixX;
mixY = data.mixY;
mixScaleX = data.mixScaleX;
mixScaleY = data.mixScaleY;
mixShearY = data.mixShearY;
} }
/// <summary>Copy constructor.</summary> /// <summary>Copy constructor.</summary>
public TransformConstraint (TransformConstraint constraint) { public TransformConstraint (TransformConstraint constraint, Skeleton skeleton)
if (constraint == null) throw new ArgumentNullException("constraint cannot be null."); : this(constraint.data, skeleton) {
data = constraint.data;
bones = new ExposedList<Bone>(constraint.Bones.Count);
bones.AddRange(constraint.Bones);
target = constraint.target;
mixRotate = constraint.mixRotate; mixRotate = constraint.mixRotate;
mixX = constraint.mixX; mixX = constraint.mixX;
mixY = constraint.mixY; mixY = constraint.mixY;

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-csharp", "name": "com.esotericsoftware.spine.spine-csharp",
"displayName": "spine-csharp Runtime", "displayName": "spine-csharp Runtime",
"description": "This plugin provides the spine-csharp core runtime.", "description": "This plugin provides the spine-csharp core runtime.",
"version": "4.2.20", "version": "4.2.21",
"unity": "2018.3", "unity": "2018.3",
"author": { "author": {
"name": "Esoteric Software", "name": "Esoteric Software",