Merge branch '3.7-beta' of https://github.com/esotericsoftware/spine-runtimes into 3.7-beta
@ -266,6 +266,11 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();
|
||||
bool isTwoColorTint = this->isTwoColorTint();
|
||||
|
||||
// Early exit if the skeleton is invisible
|
||||
if (getDisplayedOpacity() == 0 || _skeleton->color.a == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
if (_effect) _effect->begin(_effect, _skeleton);
|
||||
|
||||
Color4F nodeColor;
|
||||
@ -301,6 +306,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
continue;
|
||||
}
|
||||
|
||||
// Early exit if slot is invisible
|
||||
if (slot->color.a == 0) {
|
||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
cocos2d::TrianglesCommand::Triangles triangles;
|
||||
TwoColorTriangles trianglesTwoColor;
|
||||
|
||||
@ -309,6 +320,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
||||
attachmentVertices = getAttachmentVertices(attachment);
|
||||
|
||||
// Early exit if attachment is invisible
|
||||
if (attachment->color.a == 0) {
|
||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isTwoColorTint) {
|
||||
triangles.indices = attachmentVertices->_triangles->indices;
|
||||
triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
||||
@ -338,6 +355,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
|
||||
attachmentVertices = getAttachmentVertices(attachment);
|
||||
|
||||
// Early exit if attachment is invisible
|
||||
if (attachment->color.a == 0) {
|
||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isTwoColorTint) {
|
||||
triangles.indices = attachmentVertices->_triangles->indices;
|
||||
triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
||||
|
||||
@ -53,10 +53,6 @@ namespace Spine {
|
||||
internal float a, b, worldX;
|
||||
internal float c, d, worldY;
|
||||
|
||||
// internal float worldSignX, worldSignY;
|
||||
// public float WorldSignX { get { return worldSignX; } }
|
||||
// public float WorldSignY { get { return worldSignY; } }
|
||||
|
||||
internal bool sorted;
|
||||
|
||||
public BoneData Data { get { return data; } }
|
||||
@ -152,27 +148,13 @@ namespace Spine {
|
||||
|
||||
Bone parent = this.parent;
|
||||
if (parent == null) { // Root bone.
|
||||
float rotationY = rotation + 90 + shearY;
|
||||
float la = MathUtils.CosDeg(rotation + shearX) * scaleX;
|
||||
float lb = MathUtils.CosDeg(rotationY) * scaleY;
|
||||
float lc = MathUtils.SinDeg(rotation + shearX) * scaleX;
|
||||
float ld = MathUtils.SinDeg(rotationY) * scaleY;
|
||||
if (skeleton.flipX) {
|
||||
x = -x;
|
||||
la = -la;
|
||||
lb = -lb;
|
||||
}
|
||||
if (skeleton.flipY != yDown) {
|
||||
y = -y;
|
||||
lc = -lc;
|
||||
ld = -ld;
|
||||
}
|
||||
a = la;
|
||||
b = lb;
|
||||
c = lc;
|
||||
d = ld;
|
||||
worldX = x + skeleton.x;
|
||||
worldY = y + skeleton.y;
|
||||
float rotationY = rotation + 90 + shearY, sx = skeleton.scaleX, sy = skeleton.scaleY;
|
||||
a = MathUtils.CosDeg(rotation + shearX) * scaleX * sx;
|
||||
b = MathUtils.CosDeg(rotationY) * scaleY * sy;
|
||||
c = MathUtils.SinDeg(rotation + shearX) * scaleX * sx;
|
||||
d = MathUtils.SinDeg(rotationY) * scaleY * sy;
|
||||
worldX = x * sx + skeleton.x;
|
||||
worldY = y * sy + skeleton.y;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -228,8 +210,8 @@ namespace Spine {
|
||||
case TransformMode.NoScale:
|
||||
case TransformMode.NoScaleOrReflection: {
|
||||
float cos = MathUtils.CosDeg(rotation), sin = MathUtils.SinDeg(rotation);
|
||||
float za = pa * cos + pb * sin;
|
||||
float zc = pc * cos + pd * sin;
|
||||
float za = (pa * cos + pb * sin) / skeleton.scaleX;
|
||||
float zc = (pc * cos + pd * sin) / skeleton.scaleY;
|
||||
float s = (float)Math.Sqrt(za * za + zc * zc);
|
||||
if (s > 0.00001f) s = 1 / s;
|
||||
za *= s;
|
||||
@ -242,26 +224,18 @@ namespace Spine {
|
||||
float lb = MathUtils.CosDeg(90 + shearY) * scaleY;
|
||||
float lc = MathUtils.SinDeg(shearX) * scaleX;
|
||||
float ld = MathUtils.SinDeg(90 + shearY) * scaleY;
|
||||
if (data.transformMode != TransformMode.NoScaleOrReflection? pa * pd - pb* pc< 0 : skeleton.flipX != skeleton.flipY) {
|
||||
zb = -zb;
|
||||
zd = -zd;
|
||||
}
|
||||
a = za * la + zb * lc;
|
||||
b = za * lb + zb * ld;
|
||||
c = zc * la + zd * lc;
|
||||
d = zc * lb + zd * ld;
|
||||
return;
|
||||
d = zc * lb + zd * ld;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (skeleton.flipX) {
|
||||
a = -a;
|
||||
b = -b;
|
||||
}
|
||||
if (skeleton.flipY != Bone.yDown) {
|
||||
c = -c;
|
||||
d = -d;
|
||||
}
|
||||
a *= skeleton.scaleX;
|
||||
b *= skeleton.scaleX;
|
||||
c *= skeleton.scaleY;
|
||||
d *= skeleton.scaleY;
|
||||
}
|
||||
|
||||
public void SetToSetupPose () {
|
||||
|
||||
@ -45,7 +45,7 @@ namespace Spine {
|
||||
internal Skin skin;
|
||||
internal float r = 1, g = 1, b = 1, a = 1;
|
||||
internal float time;
|
||||
internal bool flipX, flipY;
|
||||
internal float scaleX, scaleY;
|
||||
internal float x, y;
|
||||
|
||||
public SkeletonData Data { get { return data; } }
|
||||
@ -64,8 +64,14 @@ namespace Spine {
|
||||
public float Time { get { return time; } set { time = value; } }
|
||||
public float X { get { return x; } set { x = value; } }
|
||||
public float Y { get { return y; } set { y = value; } }
|
||||
public bool FlipX { get { return flipX; } set { flipX = value; } }
|
||||
public bool FlipY { get { return flipY; } set { flipY = value; } }
|
||||
public float ScaleX { get { return scaleX; } set { scaleX = value; } }
|
||||
public float ScaleY { get { return scaleY; } set { scaleY = value; } }
|
||||
|
||||
[Obsolete("Use ScaleX instead. FlipX is when ScaleX is negative.")]
|
||||
public bool FlipX { get { return scaleX < 0; } set { scaleX = value ? -1f : 1f; } }
|
||||
|
||||
[Obsolete("Use ScaleY instead. FlipY is when ScaleY is negative.")]
|
||||
public bool FlipY { get { return scaleY < 0; } set { scaleY = value ? -1f : 1f; } }
|
||||
|
||||
public Bone RootBone {
|
||||
get { return bones.Count == 0 ? null : bones.Items[0]; }
|
||||
|
||||
@ -37,6 +37,7 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import com.esotericsoftware.spine.attachments.Attachment;
|
||||
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
||||
|
||||
@ -1294,11 +1295,12 @@ public class Animation {
|
||||
}
|
||||
}
|
||||
|
||||
/** Changes an IK constraint's {@link IkConstraint#getMix()} and {@link IkConstraint#getBendDirection()}. */
|
||||
/** Changes an IK constraint's {@link IkConstraint#getMix()}, {@link IkConstraint#getBendDirection()}, and
|
||||
* {@link IkConstraint#getStretch()}. */
|
||||
static public class IkConstraintTimeline extends CurveTimeline {
|
||||
static public final int ENTRIES = 3;
|
||||
static private final int PREV_TIME = -3, PREV_MIX = -2, PREV_BEND_DIRECTION = -1;
|
||||
static private final int MIX = 1, BEND_DIRECTION = 2;
|
||||
static public final int ENTRIES = 4;
|
||||
static private final int PREV_TIME = -4, PREV_MIX = -3, PREV_BEND_DIRECTION = -2, PREV_STRETCH = -1;
|
||||
static private final int MIX = 1, BEND_DIRECTION = 2, STRETCH = 3;
|
||||
|
||||
int ikConstraintIndex;
|
||||
private final float[] frames; // time, mix, bendDirection, ...
|
||||
@ -1328,11 +1330,12 @@ public class Animation {
|
||||
}
|
||||
|
||||
/** Sets the time in seconds, mix, and bend direction for the specified key frame. */
|
||||
public void setFrame (int frameIndex, float time, float mix, int bendDirection) {
|
||||
public void setFrame (int frameIndex, float time, float mix, int bendDirection, boolean stretch) {
|
||||
frameIndex *= ENTRIES;
|
||||
frames[frameIndex] = time;
|
||||
frames[frameIndex + MIX] = mix;
|
||||
frames[frameIndex + BEND_DIRECTION] = bendDirection;
|
||||
frames[frameIndex + STRETCH] = stretch ? 1 : 0;
|
||||
}
|
||||
|
||||
public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> events, float alpha, MixBlend blend,
|
||||
@ -1345,10 +1348,12 @@ public class Animation {
|
||||
case setup:
|
||||
constraint.mix = constraint.data.mix;
|
||||
constraint.bendDirection = constraint.data.bendDirection;
|
||||
constraint.stretch = constraint.data.stretch;
|
||||
return;
|
||||
case first:
|
||||
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
|
||||
constraint.bendDirection = constraint.data.bendDirection;
|
||||
constraint.stretch = constraint.data.stretch;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1356,11 +1361,19 @@ public class Animation {
|
||||
if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame.
|
||||
if (blend == setup) {
|
||||
constraint.mix = constraint.data.mix + (frames[frames.length + PREV_MIX] - constraint.data.mix) * alpha;
|
||||
constraint.bendDirection = direction == out ? constraint.data.bendDirection
|
||||
: (int)frames[frames.length + PREV_BEND_DIRECTION];
|
||||
if (direction == out) {
|
||||
constraint.bendDirection = constraint.data.bendDirection;
|
||||
constraint.stretch = constraint.data.stretch;
|
||||
} else {
|
||||
constraint.bendDirection = (int)frames[frames.length + PREV_BEND_DIRECTION];
|
||||
constraint.stretch = frames[frames.length + PREV_STRETCH] != 0;
|
||||
}
|
||||
} else {
|
||||
constraint.mix += (frames[frames.length + PREV_MIX] - constraint.mix) * alpha;
|
||||
if (direction == in) constraint.bendDirection = (int)frames[frames.length + PREV_BEND_DIRECTION];
|
||||
if (direction == in) {
|
||||
constraint.bendDirection = (int)frames[frames.length + PREV_BEND_DIRECTION];
|
||||
constraint.stretch = frames[frames.length + PREV_STRETCH] != 0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1373,11 +1386,19 @@ public class Animation {
|
||||
|
||||
if (blend == setup) {
|
||||
constraint.mix = constraint.data.mix + (mix + (frames[frame + MIX] - mix) * percent - constraint.data.mix) * alpha;
|
||||
constraint.bendDirection = direction == out ? constraint.data.bendDirection
|
||||
: (int)frames[frame + PREV_BEND_DIRECTION];
|
||||
if (direction == out) {
|
||||
constraint.bendDirection = constraint.data.bendDirection;
|
||||
constraint.stretch = constraint.data.stretch;
|
||||
} else {
|
||||
constraint.bendDirection = (int)frames[frame + PREV_BEND_DIRECTION];
|
||||
constraint.stretch = frames[frame + PREV_STRETCH] != 0;
|
||||
}
|
||||
} else {
|
||||
constraint.mix += (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha;
|
||||
if (direction == in) constraint.bendDirection = (int)frames[frame + PREV_BEND_DIRECTION];
|
||||
if (direction == in) {
|
||||
constraint.bendDirection = (int)frames[frame + PREV_BEND_DIRECTION];
|
||||
constraint.stretch = frames[frame + PREV_STRETCH] != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,8 +42,9 @@ public class IkConstraint implements Constraint {
|
||||
final IkConstraintData data;
|
||||
final Array<Bone> bones;
|
||||
Bone target;
|
||||
float mix = 1;
|
||||
int bendDirection;
|
||||
boolean stretch;
|
||||
float mix = 1;
|
||||
|
||||
public IkConstraint (IkConstraintData data, Skeleton skeleton) {
|
||||
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
||||
@ -51,6 +52,7 @@ public class IkConstraint implements Constraint {
|
||||
this.data = data;
|
||||
mix = data.mix;
|
||||
bendDirection = data.bendDirection;
|
||||
stretch = data.stretch;
|
||||
|
||||
bones = new Array(data.bones.size);
|
||||
for (BoneData boneData : data.bones)
|
||||
@ -69,6 +71,7 @@ public class IkConstraint implements Constraint {
|
||||
target = skeleton.bones.get(constraint.target.data.index);
|
||||
mix = constraint.mix;
|
||||
bendDirection = constraint.bendDirection;
|
||||
stretch = constraint.stretch;
|
||||
}
|
||||
|
||||
/** Applies the constraint to the constrained bones. */
|
||||
@ -81,10 +84,10 @@ public class IkConstraint implements Constraint {
|
||||
Array<Bone> bones = this.bones;
|
||||
switch (bones.size) {
|
||||
case 1:
|
||||
apply(bones.first(), target.worldX, target.worldY, mix);
|
||||
apply(bones.first(), target.worldX, target.worldY, stretch, mix);
|
||||
break;
|
||||
case 2:
|
||||
apply(bones.first(), bones.get(1), target.worldX, target.worldY, bendDirection, mix);
|
||||
apply(bones.first(), bones.get(1), target.worldX, target.worldY, bendDirection, stretch, mix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -125,6 +128,16 @@ public class IkConstraint implements Constraint {
|
||||
this.bendDirection = bendDirection;
|
||||
}
|
||||
|
||||
/** When true, if the target is out of range, the parent bone is scaled on the X axis to reach it. If the parent bone has local
|
||||
* nonuniform scale, stretching is not applied. */
|
||||
public boolean getStretch () {
|
||||
return stretch;
|
||||
}
|
||||
|
||||
public void setStretch (boolean stretch) {
|
||||
this.stretch = stretch;
|
||||
}
|
||||
|
||||
/** The IK constraint's setup pose data. */
|
||||
public IkConstraintData getData () {
|
||||
return data;
|
||||
@ -135,7 +148,7 @@ public class IkConstraint implements Constraint {
|
||||
}
|
||||
|
||||
/** Applies 1 bone IK. The target is specified in the world coordinate system. */
|
||||
static public void apply (Bone bone, float targetX, float targetY, float alpha) {
|
||||
static public void apply (Bone bone, float targetX, float targetY, boolean stretch, float alpha) {
|
||||
if (!bone.appliedValid) bone.updateAppliedTransform();
|
||||
Bone p = bone.parent;
|
||||
float id = 1 / (p.a * p.d - p.b * p.c);
|
||||
@ -146,20 +159,25 @@ public class IkConstraint implements Constraint {
|
||||
if (rotationIK > 180)
|
||||
rotationIK -= 360;
|
||||
else if (rotationIK < -180) rotationIK += 360;
|
||||
bone.updateWorldTransform(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, bone.ascaleX, bone.ascaleY, bone.ashearX,
|
||||
float sx = bone.ascaleX;
|
||||
if (stretch) {
|
||||
float b = bone.data.length * sx, dd = (float)Math.sqrt(tx * tx + ty * ty);
|
||||
if (dd > b && b > 0.0001f) sx *= (dd / b - 1) * alpha + 1;
|
||||
}
|
||||
bone.updateWorldTransform(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, bone.ascaleY, bone.ashearX,
|
||||
bone.ashearY);
|
||||
}
|
||||
|
||||
/** Applies 2 bone IK. The target is specified in the world coordinate system.
|
||||
* @param child A direct descendant of the parent bone. */
|
||||
static public void apply (Bone parent, Bone child, float targetX, float targetY, int bendDir, float alpha) {
|
||||
static public void apply (Bone parent, Bone child, float targetX, float targetY, int bendDir, boolean stretch, float alpha) {
|
||||
if (alpha == 0) {
|
||||
child.updateWorldTransform();
|
||||
return;
|
||||
}
|
||||
if (!parent.appliedValid) parent.updateAppliedTransform();
|
||||
if (!child.appliedValid) child.updateAppliedTransform();
|
||||
float px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, csx = child.ascaleX;
|
||||
float px = parent.ax, py = parent.ay, psx = parent.ascaleX, sx = psx, psy = parent.ascaleY, csx = child.ascaleX;
|
||||
int os1, os2, s2;
|
||||
if (psx < 0) {
|
||||
psx = -psx;
|
||||
@ -195,7 +213,7 @@ public class IkConstraint implements Constraint {
|
||||
c = pp.c;
|
||||
d = pp.d;
|
||||
float id = 1 / (a * d - b * c), x = targetX - pp.worldX, y = targetY - pp.worldY;
|
||||
float tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
|
||||
float tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py, dd = tx * tx + ty * ty;
|
||||
x = cwx - pp.worldX;
|
||||
y = cwy - pp.worldY;
|
||||
float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
|
||||
@ -203,10 +221,13 @@ public class IkConstraint implements Constraint {
|
||||
outer:
|
||||
if (u) {
|
||||
l2 *= psx;
|
||||
float cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
||||
float cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
||||
if (cos < -1)
|
||||
cos = -1;
|
||||
else if (cos > 1) cos = 1;
|
||||
else if (cos > 1) {
|
||||
cos = 1;
|
||||
if (stretch && l1 + l2 > 0.0001f) sx *= ((float)Math.sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
|
||||
}
|
||||
a2 = (float)Math.acos(cos) * bendDir;
|
||||
a = l1 + l2 * cos;
|
||||
b = l2 * sin(a2);
|
||||
@ -214,7 +235,7 @@ public class IkConstraint implements Constraint {
|
||||
} else {
|
||||
a = psx * l2;
|
||||
b = psy * l2;
|
||||
float aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = atan2(ty, tx);
|
||||
float aa = a * a, bb = b * b, ta = atan2(ty, tx);
|
||||
c = bb * l1 * l1 + aa * dd - aa * bb;
|
||||
float c1 = -2 * bb * l1, c2 = bb - aa;
|
||||
d = c1 * c1 - 4 * c2 * c;
|
||||
@ -266,7 +287,7 @@ public class IkConstraint implements Constraint {
|
||||
if (a1 > 180)
|
||||
a1 -= 360;
|
||||
else if (a1 < -180) a1 += 360;
|
||||
parent.updateWorldTransform(px, py, rotation + a1 * alpha, parent.ascaleX, parent.ascaleY, 0, 0);
|
||||
parent.updateWorldTransform(px, py, rotation + a1 * alpha, sx, parent.ascaleY, 0, 0);
|
||||
rotation = child.arotation;
|
||||
a2 = ((a2 + os) * radDeg - child.ashearX) * s2 + os2 - rotation;
|
||||
if (a2 > 180)
|
||||
|
||||
@ -41,6 +41,7 @@ public class IkConstraintData {
|
||||
final Array<BoneData> bones = new Array();
|
||||
BoneData target;
|
||||
int bendDirection = 1;
|
||||
boolean stretch;
|
||||
float mix = 1;
|
||||
|
||||
public IkConstraintData (String name) {
|
||||
@ -86,6 +87,16 @@ public class IkConstraintData {
|
||||
this.bendDirection = bendDirection;
|
||||
}
|
||||
|
||||
/** When true, if the target is out of range, the parent bone is scaled on the X axis to reach it. If the parent bone has local
|
||||
* nonuniform scale, stretching is not applied. */
|
||||
public boolean getStretch () {
|
||||
return stretch;
|
||||
}
|
||||
|
||||
public void setStretch (boolean stretch) {
|
||||
this.stretch = stretch;
|
||||
}
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
|
||||
public float getMix () {
|
||||
return mix;
|
||||
|
||||
@ -395,6 +395,7 @@ public class Skeleton {
|
||||
for (int i = 0, n = ikConstraints.size; i < n; i++) {
|
||||
IkConstraint constraint = ikConstraints.get(i);
|
||||
constraint.bendDirection = constraint.data.bendDirection;
|
||||
constraint.stretch = constraint.data.stretch;
|
||||
constraint.mix = constraint.data.mix;
|
||||
}
|
||||
|
||||
|
||||
@ -232,6 +232,7 @@ public class SkeletonBinary {
|
||||
data.target = skeletonData.bones.get(input.readInt(true));
|
||||
data.mix = input.readFloat();
|
||||
data.bendDirection = input.readByte();
|
||||
data.stretch = input.readBoolean();
|
||||
skeletonData.ikConstraints.add(data);
|
||||
}
|
||||
|
||||
@ -660,7 +661,7 @@ public class SkeletonBinary {
|
||||
IkConstraintTimeline timeline = new IkConstraintTimeline(frameCount);
|
||||
timeline.ikConstraintIndex = index;
|
||||
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
|
||||
timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readByte());
|
||||
timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readByte(), input.readBoolean());
|
||||
if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
|
||||
}
|
||||
timelines.add(timeline);
|
||||
|
||||
@ -186,6 +186,7 @@ public class SkeletonJson {
|
||||
if (data.target == null) throw new SerializationException("IK target bone not found: " + targetName);
|
||||
|
||||
data.bendDirection = constraintMap.getBoolean("bendPositive", true) ? 1 : -1;
|
||||
data.stretch = constraintMap.getBoolean("stretch", false);
|
||||
data.mix = constraintMap.getFloat("mix", 1);
|
||||
|
||||
skeletonData.ikConstraints.add(data);
|
||||
@ -568,7 +569,7 @@ public class SkeletonJson {
|
||||
int frameIndex = 0;
|
||||
for (JsonValue valueMap = constraintMap.child; valueMap != null; valueMap = valueMap.next) {
|
||||
timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getFloat("mix", 1),
|
||||
valueMap.getBoolean("bendPositive", true) ? 1 : -1);
|
||||
valueMap.getBoolean("bendPositive", true) ? 1 : -1, valueMap.getBoolean("stretch", false));
|
||||
readCurve(valueMap, timeline, frameIndex);
|
||||
frameIndex++;
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class SkeletonRenderer {
|
||||
* skeleton is rendered without two color tinting and any mesh attachments will throw an exception.
|
||||
* <p>
|
||||
* This method may change the batch's {@link Batch#setBlendFunctionSeparate(int, int, int, int) blending function}. The
|
||||
* previous blend function is not restore, since that could result in unnecessary flushes, depending on what is rendered
|
||||
* previous blend function is not restored, since that could result in unnecessary flushes, depending on what is rendered
|
||||
* next. */
|
||||
public void draw (Batch batch, Skeleton skeleton) {
|
||||
if (batch instanceof PolygonSpriteBatch) {
|
||||
@ -144,7 +144,7 @@ public class SkeletonRenderer {
|
||||
/** Renders the specified skeleton, including meshes, but without two color tinting.
|
||||
* <p>
|
||||
* This method may change the batch's {@link Batch#setBlendFunctionSeparate(int, int, int, int) blending function}. The
|
||||
* previous blend function is not restore, since that could result in unnecessary flushes, depending on what is rendered
|
||||
* previous blend function is not restored, since that could result in unnecessary flushes, depending on what is rendered
|
||||
* next. */
|
||||
@SuppressWarnings("null")
|
||||
public void draw (PolygonSpriteBatch batch, Skeleton skeleton) {
|
||||
@ -266,7 +266,7 @@ public class SkeletonRenderer {
|
||||
/** Renders the specified skeleton, including meshes and two color tinting.
|
||||
* <p>
|
||||
* This method may change the batch's {@link Batch#setBlendFunctionSeparate(int, int, int, int) blending function}. The
|
||||
* previous blend function is not restore, since that could result in unnecessary flushes, depending on what is rendered
|
||||
* previous blend function is not restored, since that could result in unnecessary flushes, depending on what is rendered
|
||||
* next. */
|
||||
@SuppressWarnings("null")
|
||||
public void draw (TwoColorPolygonBatch batch, Skeleton skeleton) {
|
||||
|
||||
@ -116,6 +116,9 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
||||
states.texture = 0;
|
||||
unsigned short quadIndices[6] = { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
// Early out if skeleton is invisible
|
||||
if (skeleton->color.a == 0) return;
|
||||
|
||||
if (vertexEffect != 0) vertexEffect->begin(vertexEffect, skeleton);
|
||||
|
||||
sf::Vertex vertex;
|
||||
@ -125,6 +128,12 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
||||
Attachment* attachment = slot->attachment;
|
||||
if (!attachment) continue;
|
||||
|
||||
// Early out if slot is invisible
|
||||
if (slot->color.a == 0) {
|
||||
spSkeletonClipping_clipEnd(clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
float* vertices = worldVertices;
|
||||
int verticesCount = 0;
|
||||
float* uvs = 0;
|
||||
@ -134,16 +143,31 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
||||
|
||||
if (attachment->type == ATTACHMENT_REGION) {
|
||||
RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
|
||||
attachmentColor = ®ionAttachment->color;
|
||||
|
||||
// Early out if slot is invisible
|
||||
if (attachmentColor->a == 0) {
|
||||
spSkeletonClipping_clipEnd(clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, vertices, 0, 2);
|
||||
verticesCount = 4;
|
||||
uvs = regionAttachment->uvs;
|
||||
indices = quadIndices;
|
||||
indicesCount = 6;
|
||||
texture = (Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;
|
||||
attachmentColor = ®ionAttachment->color;
|
||||
|
||||
} else if (attachment->type == ATTACHMENT_MESH) {
|
||||
MeshAttachment* mesh = (MeshAttachment*)attachment;
|
||||
attachmentColor = &mesh->color;
|
||||
|
||||
// Early out if slot is invisible
|
||||
if (attachmentColor->a == 0) {
|
||||
spSkeletonClipping_clipEnd(clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mesh->super.worldVerticesLength > SPINE_MESH_VERTEX_COUNT_MAX) continue;
|
||||
texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
|
||||
spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2);
|
||||
@ -151,7 +175,7 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
||||
uvs = mesh->uvs;
|
||||
indices = mesh->triangles;
|
||||
indicesCount = mesh->trianglesCount;
|
||||
attachmentColor = &mesh->color;
|
||||
|
||||
} else if (attachment->type == SP_ATTACHMENT_CLIPPING) {
|
||||
spClippingAttachment* clip = (spClippingAttachment*)slot->attachment;
|
||||
spSkeletonClipping_clipStart(clipper, slot, clip);
|
||||
|
||||
@ -91,6 +91,9 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
|
||||
vertexArray->clear();
|
||||
states.texture = NULL;
|
||||
|
||||
// Early out if the skeleton alpha is 0
|
||||
if (skeleton->getColor().a == 0) return;
|
||||
|
||||
if (vertexEffect != NULL) vertexEffect->begin(*skeleton);
|
||||
|
||||
sf::Vertex vertex;
|
||||
@ -100,6 +103,12 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
|
||||
Attachment *attachment = slot.getAttachment();
|
||||
if (!attachment) continue;
|
||||
|
||||
// Early out if the slot color is 0
|
||||
if (slot.getColor().a == 0) {
|
||||
clipper.clipEnd(slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector<float> *vertices = &worldVertices;
|
||||
int verticesCount = 0;
|
||||
Vector<float> *uvs = NULL;
|
||||
@ -109,6 +118,14 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
|
||||
|
||||
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
||||
RegionAttachment *regionAttachment = (RegionAttachment *) attachment;
|
||||
attachmentColor = ®ionAttachment->getColor();
|
||||
|
||||
// Early out if the attachment color is 0
|
||||
if (attachmentColor->a == 0) {
|
||||
clipper.clipEnd(slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
worldVertices.setSize(8, 0);
|
||||
regionAttachment->computeWorldVertices(slot.getBone(), worldVertices, 0, 2);
|
||||
verticesCount = 4;
|
||||
@ -116,10 +133,17 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
|
||||
indices = &quadIndices;
|
||||
indicesCount = 6;
|
||||
texture = (Texture *) ((AtlasRegion *) regionAttachment->getRendererObject())->page->rendererObject;
|
||||
attachmentColor = ®ionAttachment->getColor();
|
||||
|
||||
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
||||
MeshAttachment *mesh = (MeshAttachment *) attachment;
|
||||
attachmentColor = &mesh->getColor();
|
||||
|
||||
// Early out if the attachment color is 0
|
||||
if (attachmentColor->a == 0) {
|
||||
clipper.clipEnd(slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
worldVertices.setSize(mesh->getWorldVerticesLength(), 0);
|
||||
texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->rendererObject;
|
||||
mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices, 0, 2);
|
||||
@ -127,7 +151,6 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
|
||||
uvs = &mesh->getUVs();
|
||||
indices = &mesh->getTriangles();
|
||||
indicesCount = mesh->getTriangles().size();
|
||||
attachmentColor = &mesh->getColor();
|
||||
} else if (attachment->getRTTI().isExactly(ClippingAttachment::rtti)) {
|
||||
ClippingAttachment *clip = (ClippingAttachment *) slot.getAttachment();
|
||||
clipper.clipStart(slot, clip);
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 173cd2c662ebd674f994bff2385cfbf6
|
||||
folderAsset: yes
|
||||
timeCreated: 1529972040
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b804088948820194cbda76af39c08174
|
||||
timeCreated: 1529972058
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,117 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class SpineAnimationTesterTool : MonoBehaviour, IHasSkeletonDataAsset, IHasSkeletonComponent {
|
||||
|
||||
public SkeletonAnimation skeletonAnimation;
|
||||
public SkeletonDataAsset SkeletonDataAsset { get { return skeletonAnimation.SkeletonDataAsset; } }
|
||||
public ISkeletonComponent SkeletonComponent { get { return skeletonAnimation; } }
|
||||
|
||||
public bool useOverrideMixDuration;
|
||||
public float overrideMixDuration = 0.2f;
|
||||
|
||||
[System.Serializable]
|
||||
public struct AnimationControl {
|
||||
[SpineAnimation]
|
||||
public string animationName;
|
||||
public bool loop;
|
||||
public KeyCode key;
|
||||
|
||||
[Space]
|
||||
public bool useCustomMixDuration;
|
||||
public float mixDuration;
|
||||
//public bool useChainToControl;
|
||||
//public int chainToControl;
|
||||
}
|
||||
[System.Serializable]
|
||||
public class ControlledTrack {
|
||||
public List<AnimationControl> controls = new List<AnimationControl>();
|
||||
}
|
||||
|
||||
[Space]
|
||||
public List<ControlledTrack> trackControls = new List<ControlledTrack>();
|
||||
|
||||
[Header("UI")]
|
||||
public UnityEngine.UI.Text boundAnimationsText;
|
||||
public UnityEngine.UI.Text skeletonNameText;
|
||||
|
||||
void OnValidate () {
|
||||
// Fill in the SkeletonData asset name
|
||||
if (skeletonNameText != null) {
|
||||
if (skeletonAnimation != null && skeletonAnimation.skeletonDataAsset != null) {
|
||||
skeletonNameText.text = SkeletonDataAsset.name.Replace("_SkeletonData", "");
|
||||
}
|
||||
}
|
||||
|
||||
// Fill in the control list.
|
||||
if (boundAnimationsText != null) {
|
||||
var boundAnimationsStringBuilder = new StringBuilder();
|
||||
boundAnimationsStringBuilder.AppendLine("Animation Controls:");
|
||||
|
||||
for (int trackIndex = 0; trackIndex < trackControls.Count; trackIndex++) {
|
||||
|
||||
if (trackIndex > 0)
|
||||
boundAnimationsStringBuilder.AppendLine();
|
||||
|
||||
boundAnimationsStringBuilder.AppendFormat("---- Track {0} ---- \n", trackIndex);
|
||||
foreach (var ba in trackControls[trackIndex].controls) {
|
||||
string animationName = ba.animationName;
|
||||
if (string.IsNullOrEmpty(animationName))
|
||||
animationName = "SetEmptyAnimation";
|
||||
|
||||
boundAnimationsStringBuilder.AppendFormat("[{0}] {1}\n", ba.key.ToString(), animationName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boundAnimationsText.text = boundAnimationsStringBuilder.ToString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Start () {
|
||||
if (useOverrideMixDuration) {
|
||||
skeletonAnimation.AnimationState.Data.DefaultMix = overrideMixDuration;
|
||||
}
|
||||
}
|
||||
|
||||
void Update () {
|
||||
var animationState = skeletonAnimation.AnimationState;
|
||||
|
||||
// For each track
|
||||
for (int trackIndex = 0; trackIndex < trackControls.Count; trackIndex++) {
|
||||
|
||||
// For each control in the track
|
||||
foreach (var control in trackControls[trackIndex].controls) {
|
||||
|
||||
// Check each control, and play the appropriate animation.
|
||||
if (Input.GetKeyDown(control.key)) {
|
||||
if (!string.IsNullOrEmpty(control.animationName)) {
|
||||
var trackEntry = animationState.SetAnimation(trackIndex, control.animationName, control.loop);
|
||||
if (control.useCustomMixDuration)
|
||||
trackEntry.MixDuration = control.mixDuration;
|
||||
|
||||
} else {
|
||||
float mix = control.useCustomMixDuration ? control.mixDuration : animationState.Data.DefaultMix;
|
||||
animationState.SetEmptyAnimation(trackIndex, mix);
|
||||
}
|
||||
|
||||
// Don't parse more than one animation per track.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b99b2d8e59226fa4db070f241259fd98
|
||||
timeCreated: 1529972356
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4766fcfd6167d2e46aad772ce3bc898c
|
||||
folderAsset: yes
|
||||
timeCreated: 1531292725
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afd3c9ec31200bc49b169c22f00b010b
|
||||
timeCreated: 1531300871
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cec34498f2eb26b488452ec274c54439
|
||||
timeCreated: 1531292741
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 9100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
public class AnimationStateMecanimState : StateMachineBehaviour {
|
||||
|
||||
#region Inspector
|
||||
public AnimationReferenceAsset animation;
|
||||
|
||||
[System.Serializable]
|
||||
public struct AnimationTransition {
|
||||
public AnimationReferenceAsset from;
|
||||
public AnimationReferenceAsset transition;
|
||||
}
|
||||
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("transitions")]
|
||||
public List<AnimationTransition> fromTransitions = new List<AnimationTransition>();
|
||||
#endregion
|
||||
|
||||
Spine.AnimationState state;
|
||||
|
||||
public void Initialize (Animator animator) {
|
||||
if (state == null) {
|
||||
var animationStateComponent = (animator.GetComponent(typeof(IAnimationStateComponent))) as IAnimationStateComponent;
|
||||
state = animationStateComponent.AnimationState;
|
||||
}
|
||||
}
|
||||
|
||||
override public void OnStateEnter (Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
|
||||
if (state == null) {
|
||||
Initialize(animator);
|
||||
}
|
||||
|
||||
float timeScale = stateInfo.speed;
|
||||
var current = state.GetCurrent(layerIndex);
|
||||
|
||||
bool transitionPlayed = false;
|
||||
if (current != null && fromTransitions.Count > 0) {
|
||||
foreach (var t in fromTransitions) {
|
||||
if (t.from.Animation == current.Animation) {
|
||||
var transitionEntry = state.SetAnimation(layerIndex, t.transition.Animation, false);
|
||||
transitionEntry.TimeScale = timeScale;
|
||||
transitionPlayed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TrackEntry trackEntry;
|
||||
if (transitionPlayed) {
|
||||
trackEntry = state.AddAnimation(layerIndex, animation.Animation, stateInfo.loop, 0);
|
||||
} else {
|
||||
trackEntry = state.SetAnimation(layerIndex, animation.Animation, stateInfo.loop);
|
||||
}
|
||||
trackEntry.TimeScale = timeScale;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 536bdde8dc7bbb641b17da9221d6562f
|
||||
timeCreated: 1531293563
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class AnimationStateWithMecanimExample : MonoBehaviour {
|
||||
|
||||
SkeletonAnimation skeletonAnimation;
|
||||
Animator logicAnimator;
|
||||
|
||||
[Header("Controls")]
|
||||
public KeyCode walkButton = KeyCode.LeftShift;
|
||||
public KeyCode jumpButton = KeyCode.Space;
|
||||
|
||||
[Header("Animator Properties")]
|
||||
public string horizontalSpeedProperty = "Speed";
|
||||
public string verticalSpeedProperty = "VerticalSpeed";
|
||||
public string groundedProperty = "Grounded";
|
||||
|
||||
[Header("Fake Physics")]
|
||||
public float jumpDuration = 1.5f;
|
||||
public Vector2 speed;
|
||||
public bool isGrounded;
|
||||
|
||||
void Awake () {
|
||||
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
||||
logicAnimator = GetComponent<Animator>();
|
||||
|
||||
isGrounded = true;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
float x = Input.GetAxisRaw("Horizontal");
|
||||
if (Input.GetKey(walkButton)) {
|
||||
x *= 0.4f;
|
||||
}
|
||||
|
||||
speed.x = x;
|
||||
|
||||
// Flip skeleton.
|
||||
if (x != 0) {
|
||||
skeletonAnimation.Skeleton.ScaleX = x > 0 ? 1f : -1f;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(jumpButton)) {
|
||||
if (isGrounded)
|
||||
StartCoroutine(FakeJump());
|
||||
}
|
||||
|
||||
logicAnimator.SetFloat(horizontalSpeedProperty, Mathf.Abs(speed.x));
|
||||
logicAnimator.SetFloat(verticalSpeedProperty, speed.y);
|
||||
logicAnimator.SetBool(groundedProperty, isGrounded);
|
||||
|
||||
}
|
||||
|
||||
IEnumerator FakeJump () {
|
||||
// Rise
|
||||
isGrounded = false;
|
||||
speed.y = 10f;
|
||||
float durationLeft = jumpDuration * 0.5f;
|
||||
while (durationLeft > 0) {
|
||||
durationLeft -= Time.deltaTime;
|
||||
if (!Input.GetKey(jumpButton)) break;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Fall
|
||||
speed.y = -10f;
|
||||
float fallDuration = (jumpDuration * 0.5f) - durationLeft;
|
||||
yield return new WaitForSeconds(fallDuration);
|
||||
|
||||
// Land
|
||||
speed.y = 0f;
|
||||
isGrounded = true;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 782062825deffd64ba7e7e9f978788e5
|
||||
timeCreated: 1531300740
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -80,11 +80,11 @@ namespace Spine.Unity.Examples {
|
||||
} else {
|
||||
if (Input.GetKey(rightKey)) {
|
||||
skeletonAnimation.AnimationName = moveAnimation;
|
||||
skeletonAnimation.Skeleton.FlipX = false;
|
||||
skeletonAnimation.Skeleton.ScaleX = 1;
|
||||
transform.Translate(moveSpeed * Time.deltaTime, 0, 0);
|
||||
} else if(Input.GetKey(leftKey)) {
|
||||
skeletonAnimation.AnimationName = moveAnimation;
|
||||
skeletonAnimation.Skeleton.FlipX = true;
|
||||
skeletonAnimation.Skeleton.ScaleX = -1;
|
||||
transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
|
||||
} else {
|
||||
skeletonAnimation.AnimationName = idleAnimation;
|
||||
|
||||
@ -183,7 +183,7 @@ namespace Spine.Unity.Examples {
|
||||
|
||||
// Face intended direction.
|
||||
if (input.x != 0)
|
||||
skeletonAnimation.Skeleton.FlipX = input.x < 0;
|
||||
skeletonAnimation.Skeleton.ScaleX = Mathf.Sign(input.x);
|
||||
|
||||
|
||||
// Effects
|
||||
|
||||
@ -93,11 +93,11 @@ namespace Spine.Unity.Examples {
|
||||
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
skeleton.FlipX = true; // skeleton allows you to flip the skeleton.
|
||||
skeleton.ScaleX = -1; // skeleton allows you to flip the skeleton.
|
||||
spineAnimationState.SetAnimation(0, idleTurnAnimationName, false);
|
||||
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
skeleton.FlipX = false;
|
||||
skeleton.ScaleX = 1;
|
||||
spineAnimationState.SetAnimation(0, idleTurnAnimationName, false);
|
||||
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
@ -69,7 +69,7 @@ namespace Spine.Unity.Examples {
|
||||
if (skeletonAnimation == null) return;
|
||||
if (model == null) return;
|
||||
|
||||
if (skeletonAnimation.skeleton.FlipX != model.facingLeft) { // Detect changes in model.facingLeft
|
||||
if ((skeletonAnimation.skeleton.ScaleX < 0) != model.facingLeft) { // Detect changes in model.facingLeft
|
||||
Turn(model.facingLeft);
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ namespace Spine.Unity.Examples {
|
||||
}
|
||||
|
||||
public void Turn (bool facingLeft) {
|
||||
skeletonAnimation.Skeleton.FlipX = facingLeft;
|
||||
skeletonAnimation.Skeleton.ScaleX = facingLeft ? -1f : 1f;
|
||||
// Maybe play a transient turning animation too, then call ChangeStableAnimation.
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -23,7 +23,7 @@ namespace Spine.Unity.Examples {
|
||||
var mousePosition = Input.mousePosition;
|
||||
var worldMousePosition = camera.ScreenToWorldPoint(mousePosition);
|
||||
var skeletonSpacePoint = skeletonAnimation.transform.InverseTransformPoint(worldMousePosition);
|
||||
if (skeletonAnimation.Skeleton.FlipX) skeletonSpacePoint.x *= -1;
|
||||
//if (skeletonAnimation.Skeleton.FlipX) skeletonSpacePoint.x *= -1;
|
||||
bone.SetPosition(skeletonSpacePoint);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,8 +69,8 @@ namespace Spine.Unity {
|
||||
sa.initialFlipX = this.initialFlipX;
|
||||
sa.initialFlipY = this.initialFlipY;
|
||||
var skeleton = sa.skeleton;
|
||||
skeleton.FlipX = this.initialFlipX;
|
||||
skeleton.FlipY = this.initialFlipY;
|
||||
skeleton.ScaleX = this.initialFlipX ? 1 : -1;
|
||||
skeleton.ScaleY = this.initialFlipY ? 1 : -1;
|
||||
|
||||
sa.Initialize(false);
|
||||
skeletonAnimations.Add(sa);
|
||||
|
||||
|
Before Width: | Height: | Size: 593 KiB After Width: | Height: | Size: 593 KiB |
|
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |