mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
[unity] PhysicsConstraints: Added Movement relative to Transform property for relative instead of world-space movement.
This commit is contained in:
parent
6812160239
commit
4266c727cb
@ -55,6 +55,7 @@
|
|||||||
* URP Shaders: Added support for [Tint Black](http://en.esotericsoftware.com/spine-slots#Tint-black) functionality at "Blend Modes" Spine URP shaders (2D and 3D shaders).
|
* URP Shaders: Added support for [Tint Black](http://en.esotericsoftware.com/spine-slots#Tint-black) functionality at "Blend Modes" Spine URP shaders (2D and 3D shaders).
|
||||||
* PhysicsConstraints: Skeleton GameObjects now automatically apply Transform translation and rotation to the skeleton's `PhysicsConstraints`. You can disable applying translation or rotation at the Skeleton component Inspector under `Advanced - Physics Constraints` `Transform Translation` and `Transform Rotation`, or by setting the properties `applyTranslationToPhysics` and `applyRotationToPhysics` at the skeleton component via code.
|
* PhysicsConstraints: Skeleton GameObjects now automatically apply Transform translation and rotation to the skeleton's `PhysicsConstraints`. You can disable applying translation or rotation at the Skeleton component Inspector under `Advanced - Physics Constraints` `Transform Translation` and `Transform Rotation`, or by setting the properties `applyTranslationToPhysics` and `applyRotationToPhysics` at the skeleton component via code.
|
||||||
* Added `Physics Constraints` example scene (located in `Spine Examples/Other Examples`) together with `celestial-circus` example skeleton assets. This scene demonstrates Transform movement automatically affecting physics constraints of a skeleton.
|
* Added `Physics Constraints` example scene (located in `Spine Examples/Other Examples`) together with `celestial-circus` example skeleton assets. This scene demonstrates Transform movement automatically affecting physics constraints of a skeleton.
|
||||||
|
* PhysicsConstraints: Skeleton components now allow you to use relative instead of world-space Transform movement (with `applyTranslationToPhysics` and `applyRotationToPhysics`) by assigning a Transform (typically the parent) to the new `Movement relative to` property. Leave this property at `null` (the default) to use world-space Transform movement for physics.
|
||||||
|
|
||||||
* **Breaking changes**
|
* **Breaking changes**
|
||||||
* Changed `SpineShaderWithOutlineGUI` outline related methods from `private` to `protected virtual` to allow for custom shader GUI subclasses to switch to different outline shaders.
|
* Changed `SpineShaderWithOutlineGUI` outline related methods from `private` to `protected virtual` to allow for custom shader GUI subclasses to switch to different outline shaders.
|
||||||
|
|||||||
@ -243,21 +243,7 @@ namespace Spine.Unity {
|
|||||||
state.Update(deltaTime);
|
state.Update(deltaTime);
|
||||||
skeleton.Update(deltaTime);
|
skeleton.Update(deltaTime);
|
||||||
|
|
||||||
if (Application.isPlaying) {
|
ApplyTransformMovementToPhysics();
|
||||||
if (applyTranslationToPhysics) {
|
|
||||||
Vector2 position = new Vector2(transform.position.x, transform.position.y);
|
|
||||||
Vector2 positionDelta = position - lastPosition;
|
|
||||||
positionDelta.x /= transform.lossyScale.x;
|
|
||||||
positionDelta.y /= transform.lossyScale.y;
|
|
||||||
skeleton.PhysicsTranslate(positionDelta.x, positionDelta.y);
|
|
||||||
lastPosition = position;
|
|
||||||
}
|
|
||||||
if (applyRotationToPhysics) {
|
|
||||||
float rotation = this.transform.rotation.eulerAngles.z;
|
|
||||||
skeleton.PhysicsRotate(0, 0, rotation - lastRotation);
|
|
||||||
lastRotation = rotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateMode == UpdateMode.OnlyAnimationStatus) {
|
if (updateMode == UpdateMode.OnlyAnimationStatus) {
|
||||||
state.ApplyEventTimelinesOnly(skeleton, issueEvents: false);
|
state.ApplyEventTimelinesOnly(skeleton, issueEvents: false);
|
||||||
|
|||||||
@ -381,21 +381,7 @@ namespace Spine.Unity {
|
|||||||
state.Update(deltaTime);
|
state.Update(deltaTime);
|
||||||
skeleton.Update(deltaTime);
|
skeleton.Update(deltaTime);
|
||||||
|
|
||||||
if (Application.isPlaying) {
|
ApplyTransformMovementToPhysics();
|
||||||
if (applyTranslationToPhysics) {
|
|
||||||
Vector2 position = new Vector2(transform.position.x, transform.position.y);
|
|
||||||
Vector2 positionDelta = (position - lastPosition) / meshScale;
|
|
||||||
positionDelta.x /= transform.lossyScale.x;
|
|
||||||
positionDelta.y /= transform.lossyScale.y;
|
|
||||||
skeleton.PhysicsTranslate(positionDelta.x, positionDelta.y);
|
|
||||||
lastPosition = position;
|
|
||||||
}
|
|
||||||
if (applyRotationToPhysics) {
|
|
||||||
float rotation = this.transform.rotation.eulerAngles.z;
|
|
||||||
skeleton.PhysicsRotate(0, 0, rotation - lastRotation);
|
|
||||||
lastRotation = rotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateMode == UpdateMode.OnlyAnimationStatus) {
|
if (updateMode == UpdateMode.OnlyAnimationStatus) {
|
||||||
state.ApplyEventTimelinesOnly(skeleton, issueEvents: false);
|
state.ApplyEventTimelinesOnly(skeleton, issueEvents: false);
|
||||||
@ -403,6 +389,50 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void ApplyTransformMovementToPhysics() {
|
||||||
|
if (Application.isPlaying) {
|
||||||
|
if (applyTranslationToPhysics) {
|
||||||
|
Vector2 position = GetPhysicsTransformPosition();
|
||||||
|
Vector2 positionDelta = (position - lastPosition) / meshScale;
|
||||||
|
if (physicsMovementRelativeTo != null) {
|
||||||
|
positionDelta *= physicsMovementRelativeTo.lossyScale;
|
||||||
|
}
|
||||||
|
positionDelta /= transform.lossyScale;
|
||||||
|
skeleton.PhysicsTranslate(positionDelta.x, positionDelta.y);
|
||||||
|
lastPosition = position;
|
||||||
|
}
|
||||||
|
if (applyRotationToPhysics) {
|
||||||
|
float rotation = GetPhysicsTransformRotation();
|
||||||
|
skeleton.PhysicsRotate(0, 0, rotation - lastRotation);
|
||||||
|
lastRotation = rotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Vector2 GetPhysicsTransformPosition () {
|
||||||
|
if (physicsMovementRelativeTo == null) {
|
||||||
|
return transform.position;
|
||||||
|
} else {
|
||||||
|
if (physicsMovementRelativeTo == transform.parent)
|
||||||
|
return transform.localPosition;
|
||||||
|
else
|
||||||
|
return physicsMovementRelativeTo.InverseTransformPoint(transform.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float GetPhysicsTransformRotation () {
|
||||||
|
if (physicsMovementRelativeTo == null) {
|
||||||
|
return this.transform.rotation.eulerAngles.z;
|
||||||
|
} else {
|
||||||
|
if (physicsMovementRelativeTo == this.transform.parent)
|
||||||
|
return this.transform.localRotation.eulerAngles.z;
|
||||||
|
else {
|
||||||
|
Quaternion relative = Quaternion.Inverse(physicsMovementRelativeTo.rotation) * this.transform.rotation;
|
||||||
|
return relative.eulerAngles.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void ApplyAnimation () {
|
public virtual void ApplyAnimation () {
|
||||||
if (BeforeApply != null)
|
if (BeforeApply != null)
|
||||||
BeforeApply(this);
|
BeforeApply(this);
|
||||||
@ -539,17 +569,25 @@ namespace Spine.Unity {
|
|||||||
public bool applyTranslationToPhysics = true;
|
public bool applyTranslationToPhysics = true;
|
||||||
/// <summary>When enabled, Transform rotation is applied to skeleton PhysicsConstraints.</summary>
|
/// <summary>When enabled, Transform rotation is applied to skeleton PhysicsConstraints.</summary>
|
||||||
public bool applyRotationToPhysics = true;
|
public bool applyRotationToPhysics = true;
|
||||||
|
/// <summary>Reference transform relative to which physics movement will be calculated, or null to use world location.</summary>
|
||||||
|
public Transform physicsMovementRelativeTo = null;
|
||||||
|
|
||||||
/// <summary>Used for applying Transform translation to skeleton PhysicsConstraints.</summary>
|
/// <summary>Used for applying Transform translation to skeleton PhysicsConstraints.</summary>
|
||||||
protected Vector2 lastPosition;
|
protected Vector2 lastPosition;
|
||||||
/// <summary>Used for applying Transform rotation to skeleton PhysicsConstraints.</summary>
|
/// <summary>Used for applying Transform rotation to skeleton PhysicsConstraints.</summary>
|
||||||
protected float lastRotation;
|
protected float lastRotation;
|
||||||
|
|
||||||
public void ResetLastPosition () { lastPosition = this.transform.position; }
|
public void ResetLastPosition () {
|
||||||
public void ResetLastRotation () { lastRotation = this.transform.rotation.eulerAngles.z; }
|
lastPosition = GetPhysicsTransformPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetLastRotation () {
|
||||||
|
lastRotation = GetPhysicsTransformRotation();
|
||||||
|
}
|
||||||
|
|
||||||
public void ResetLastPositionAndRotation () {
|
public void ResetLastPositionAndRotation () {
|
||||||
lastPosition = this.transform.position;
|
lastPosition = GetPhysicsTransformPosition();
|
||||||
lastRotation = this.transform.rotation.eulerAngles.z;
|
lastRotation = GetPhysicsTransformRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] protected Spine.Unity.MeshGenerator meshGenerator = new MeshGenerator();
|
[SerializeField] protected Spine.Unity.MeshGenerator meshGenerator = new MeshGenerator();
|
||||||
|
|||||||
@ -126,21 +126,7 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
skeleton.Update(deltaTime);
|
skeleton.Update(deltaTime);
|
||||||
|
|
||||||
if (Application.isPlaying) {
|
ApplyTransformMovementToPhysics();
|
||||||
if (applyTranslationToPhysics) {
|
|
||||||
Vector2 position = new Vector2(transform.position.x, transform.position.y);
|
|
||||||
Vector2 positionDelta = position - lastPosition;
|
|
||||||
positionDelta.x /= transform.lossyScale.x;
|
|
||||||
positionDelta.y /= transform.lossyScale.y;
|
|
||||||
skeleton.PhysicsTranslate(positionDelta.x, positionDelta.y);
|
|
||||||
lastPosition = position;
|
|
||||||
}
|
|
||||||
if (applyRotationToPhysics) {
|
|
||||||
float rotation = this.transform.rotation.eulerAngles.z;
|
|
||||||
skeleton.PhysicsRotate(0, 0, rotation - lastRotation);
|
|
||||||
lastRotation = rotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplyAnimation();
|
ApplyAnimation();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -293,17 +293,25 @@ namespace Spine.Unity {
|
|||||||
public bool applyTranslationToPhysics = true;
|
public bool applyTranslationToPhysics = true;
|
||||||
/// <summary>When enabled, Transform rotation is applied to skeleton PhysicsConstraints.</summary>
|
/// <summary>When enabled, Transform rotation is applied to skeleton PhysicsConstraints.</summary>
|
||||||
public bool applyRotationToPhysics = true;
|
public bool applyRotationToPhysics = true;
|
||||||
|
/// <summary>Reference transform relative to which physics movement will be calculated, or null to use world location.</summary>
|
||||||
|
public Transform physicsMovementRelativeTo = null;
|
||||||
|
|
||||||
/// <summary>Used for applying Transform translation to skeleton PhysicsConstraints.</summary>
|
/// <summary>Used for applying Transform translation to skeleton PhysicsConstraints.</summary>
|
||||||
protected Vector2 lastPosition;
|
protected Vector2 lastPosition;
|
||||||
/// <summary>Used for applying Transform rotation to skeleton PhysicsConstraints.</summary>
|
/// <summary>Used for applying Transform rotation to skeleton PhysicsConstraints.</summary>
|
||||||
protected float lastRotation;
|
protected float lastRotation;
|
||||||
|
|
||||||
public void ResetLastPosition () { lastPosition = this.transform.position; }
|
public void ResetLastPosition () {
|
||||||
public void ResetLastRotation () { lastRotation = this.transform.rotation.eulerAngles.z; }
|
lastPosition = GetPhysicsTransformPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetLastRotation () {
|
||||||
|
lastRotation = GetPhysicsTransformRotation();
|
||||||
|
}
|
||||||
|
|
||||||
public void ResetLastPositionAndRotation () {
|
public void ResetLastPositionAndRotation () {
|
||||||
lastPosition = this.transform.position;
|
lastPosition = GetPhysicsTransformPosition();
|
||||||
lastRotation = this.transform.rotation.eulerAngles.z;
|
lastRotation = GetPhysicsTransformRotation();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -460,6 +468,50 @@ namespace Spine.Unity {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void ApplyTransformMovementToPhysics () {
|
||||||
|
if (Application.isPlaying) {
|
||||||
|
if (applyTranslationToPhysics) {
|
||||||
|
Vector2 position = GetPhysicsTransformPosition();
|
||||||
|
Vector2 positionDelta = position - lastPosition;
|
||||||
|
if (physicsMovementRelativeTo != null) {
|
||||||
|
positionDelta *= physicsMovementRelativeTo.lossyScale;
|
||||||
|
}
|
||||||
|
positionDelta /= transform.lossyScale;
|
||||||
|
skeleton.PhysicsTranslate(positionDelta.x, positionDelta.y);
|
||||||
|
lastPosition = position;
|
||||||
|
}
|
||||||
|
if (applyRotationToPhysics) {
|
||||||
|
float rotation = GetPhysicsTransformRotation();
|
||||||
|
skeleton.PhysicsRotate(0, 0, rotation - lastRotation);
|
||||||
|
lastRotation = rotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Vector2 GetPhysicsTransformPosition () {
|
||||||
|
if (physicsMovementRelativeTo == null) {
|
||||||
|
return transform.position;
|
||||||
|
} else {
|
||||||
|
if (physicsMovementRelativeTo == transform.parent)
|
||||||
|
return transform.localPosition;
|
||||||
|
else
|
||||||
|
return physicsMovementRelativeTo.InverseTransformPoint(transform.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float GetPhysicsTransformRotation () {
|
||||||
|
if (physicsMovementRelativeTo == null) {
|
||||||
|
return this.transform.rotation.eulerAngles.z;
|
||||||
|
} else {
|
||||||
|
if (physicsMovementRelativeTo == this.transform.parent)
|
||||||
|
return this.transform.localRotation.eulerAngles.z;
|
||||||
|
else {
|
||||||
|
Quaternion relative = Quaternion.Inverse(physicsMovementRelativeTo.rotation) * this.transform.rotation;
|
||||||
|
return relative.eulerAngles.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void UpdateWorldTransform (Skeleton.Physics physics) {
|
protected virtual void UpdateWorldTransform (Skeleton.Physics physics) {
|
||||||
skeleton.UpdateWorldTransform(physics);
|
skeleton.UpdateWorldTransform(physics);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "com.esotericsoftware.spine.spine-unity",
|
"name": "com.esotericsoftware.spine.spine-unity",
|
||||||
"displayName": "spine-unity Runtime",
|
"displayName": "spine-unity Runtime",
|
||||||
"description": "This plugin provides the spine-unity runtime core.",
|
"description": "This plugin provides the spine-unity runtime core.",
|
||||||
"version": "4.2.48",
|
"version": "4.2.49",
|
||||||
"unity": "2018.3",
|
"unity": "2018.3",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Esoteric Software",
|
"name": "Esoteric Software",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user