Skip to content

Commit

Permalink
[csharp] Port of commit cb48737: Fixed constraint copy constructors r…
Browse files Browse the repository at this point in the history
…eferences the wrong bones. Closes #2511.
  • Loading branch information
HaraldCsaszar committed Apr 29, 2024
1 parent cb48737 commit 6118a5f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 39 deletions.
20 changes: 9 additions & 11 deletions spine-csharp/src/IkConstraint.cs
Expand Up @@ -52,26 +52,24 @@ public class IkConstraint : IUpdatable {
public IkConstraint (IkConstraintData data, Skeleton skeleton) {
if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
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);
foreach (BoneData boneData in data.bones)
bones.Add(skeleton.bones.Items[boneData.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>
public IkConstraint (IkConstraint constraint) {
if (constraint == null) throw new ArgumentNullException("constraint", "constraint cannot be null.");
data = constraint.data;
bones = new ExposedList<Bone>(constraint.Bones.Count);
bones.AddRange(constraint.Bones);
target = constraint.target;
public IkConstraint (IkConstraint constraint, Skeleton skeleton)
: this(constraint.data, skeleton) {

mix = constraint.mix;
softness = constraint.softness;
bendDirection = constraint.bendDirection;
Expand Down
10 changes: 4 additions & 6 deletions spine-csharp/src/PathConstraint.cs
Expand Up @@ -64,6 +64,7 @@ public class PathConstraint : IUpdatable {
bones.Add(skeleton.bones.Items[boneData.index]);

target = skeleton.slots.Items[data.target.index];

position = data.position;
spacing = data.spacing;
mixRotate = data.mixRotate;
Expand All @@ -72,12 +73,9 @@ public class PathConstraint : IUpdatable {
}

/// <summary>Copy constructor.</summary>
public PathConstraint (PathConstraint constraint) {
if (constraint == null) throw new ArgumentNullException("constraint cannot be null.");
data = constraint.data;
bones = new ExposedList<Bone>(constraint.Bones.Count);
bones.AddRange(constraint.Bones);
target = constraint.target;
public PathConstraint (PathConstraint constraint, Skeleton skeleton)
: this(constraint.data, skeleton) {

position = constraint.position;
spacing = constraint.spacing;
mixRotate = constraint.mixRotate;
Expand Down
10 changes: 5 additions & 5 deletions spine-csharp/src/PhysicsConstraint.cs
Expand Up @@ -60,7 +60,9 @@ public class PhysicsConstraint : IUpdatable {
if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
this.data = data;
this.skeleton = skeleton;

bone = skeleton.bones.Items[data.bone.index];

inertia = data.inertia;
strength = data.strength;
damping = data.damping;
Expand All @@ -71,11 +73,9 @@ public class PhysicsConstraint : IUpdatable {
}

/// <summary>Copy constructor.</summary>
public PhysicsConstraint (PhysicsConstraint constraint) {
if (constraint == null) throw new ArgumentNullException("constraint", "constraint cannot be null.");
data = constraint.data;
skeleton = constraint.skeleton;
bone = constraint.bone;
public PhysicsConstraint (PhysicsConstraint constraint, Skeleton skeleton)
: this(constraint.data, skeleton) {

inertia = constraint.inertia;
strength = constraint.strength;
damping = constraint.damping;
Expand Down
8 changes: 4 additions & 4 deletions spine-csharp/src/Skeleton.cs
Expand Up @@ -187,19 +187,19 @@ public class Skeleton {

ikConstraints = new ExposedList<IkConstraint>(skeleton.ikConstraints.Count);
foreach (IkConstraint ikConstraint in skeleton.ikConstraints)
ikConstraints.Add(new IkConstraint(ikConstraint));
ikConstraints.Add(new IkConstraint(ikConstraint, skeleton));

transformConstraints = new ExposedList<TransformConstraint>(skeleton.transformConstraints.Count);
foreach (TransformConstraint transformConstraint in skeleton.transformConstraints)
transformConstraints.Add(new TransformConstraint(transformConstraint));
transformConstraints.Add(new TransformConstraint(transformConstraint, skeleton));

pathConstraints = new ExposedList<PathConstraint>(skeleton.pathConstraints.Count);
foreach (PathConstraint pathConstraint in skeleton.pathConstraints)
pathConstraints.Add(new PathConstraint(pathConstraint));
pathConstraints.Add(new PathConstraint(pathConstraint, skeleton));

physicsConstraints = new ExposedList<PhysicsConstraint>(skeleton.physicsConstraints.Count);
foreach (PhysicsConstraint physicsConstraint in skeleton.physicsConstraints)
physicsConstraints.Add(new PhysicsConstraint(physicsConstraint));
physicsConstraints.Add(new PhysicsConstraint(physicsConstraint, skeleton));

skin = skeleton.skin;
r = skeleton.r;
Expand Down
22 changes: 10 additions & 12 deletions spine-csharp/src/TransformConstraint.cs
Expand Up @@ -51,27 +51,25 @@ public class TransformConstraint : IUpdatable {
if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
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>();
foreach (BoneData boneData in data.bones)
bones.Add(skeleton.bones.Items[boneData.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>
public TransformConstraint (TransformConstraint constraint) {
if (constraint == null) throw new ArgumentNullException("constraint cannot be null.");
data = constraint.data;
bones = new ExposedList<Bone>(constraint.Bones.Count);
bones.AddRange(constraint.Bones);
target = constraint.target;
public TransformConstraint (TransformConstraint constraint, Skeleton skeleton)
: this(constraint.data, skeleton) {

mixRotate = constraint.mixRotate;
mixX = constraint.mixX;
mixY = constraint.mixY;
Expand Down
2 changes: 1 addition & 1 deletion spine-csharp/src/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-csharp",
"displayName": "spine-csharp Runtime",
"description": "This plugin provides the spine-csharp core runtime.",
"version": "4.2.20",
"version": "4.2.21",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",
Expand Down

0 comments on commit 6118a5f

Please sign in to comment.