mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] 2D Option for KinematicShadow.
This commit is contained in:
parent
e46a04a130
commit
17ce8d5bcf
@ -41,6 +41,7 @@ namespace Spine.Unity.Modules {
|
|||||||
public bool detachedShadow = false;
|
public bool detachedShadow = false;
|
||||||
public Transform parent;
|
public Transform parent;
|
||||||
public bool hideShadow = true;
|
public bool hideShadow = true;
|
||||||
|
public PhysicsSystem physicsSystem = PhysicsSystem.Physics3D;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
GameObject shadowRoot;
|
GameObject shadowRoot;
|
||||||
@ -49,6 +50,11 @@ namespace Spine.Unity.Modules {
|
|||||||
public Transform dest, src;
|
public Transform dest, src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum PhysicsSystem {
|
||||||
|
Physics2D,
|
||||||
|
Physics3D
|
||||||
|
};
|
||||||
|
|
||||||
void Start () {
|
void Start () {
|
||||||
// Duplicate this gameObject as the "shadow" with a different parent.
|
// Duplicate this gameObject as the "shadow" with a different parent.
|
||||||
shadowRoot = Instantiate<GameObject>(this.gameObject);
|
shadowRoot = Instantiate<GameObject>(this.gameObject);
|
||||||
@ -85,8 +91,9 @@ namespace Spine.Unity.Modules {
|
|||||||
if (b.gameObject == this.gameObject)
|
if (b.gameObject == this.gameObject)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
System.Type checkType = (physicsSystem == PhysicsSystem.Physics2D) ? typeof(Rigidbody2D) : typeof(Rigidbody);
|
||||||
foreach (var sb in shadowBones) {
|
foreach (var sb in shadowBones) {
|
||||||
if (sb.GetComponent<Rigidbody>() != null && sb.boneName == b.boneName) {
|
if (sb.GetComponent(checkType) != null && sb.boneName == b.boneName) {
|
||||||
shadowTable.Add(new TransformPair {
|
shadowTable.Add(new TransformPair {
|
||||||
dest = b.transform,
|
dest = b.transform,
|
||||||
src = sb.transform
|
src = sb.transform
|
||||||
@ -111,9 +118,15 @@ namespace Spine.Unity.Modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate () {
|
void FixedUpdate () {
|
||||||
var shadowRootRigidbody = shadowRoot.GetComponent<Rigidbody>();
|
if (physicsSystem == PhysicsSystem.Physics2D) {
|
||||||
shadowRootRigidbody.MovePosition(transform.position);
|
var shadowRootRigidbody = shadowRoot.GetComponent<Rigidbody2D>();
|
||||||
shadowRootRigidbody.MoveRotation(transform.rotation);
|
shadowRootRigidbody.MovePosition(transform.position);
|
||||||
|
shadowRootRigidbody.MoveRotation(transform.rotation.eulerAngles.z);
|
||||||
|
} else {
|
||||||
|
var shadowRootRigidbody = shadowRoot.GetComponent<Rigidbody>();
|
||||||
|
shadowRootRigidbody.MovePosition(transform.position);
|
||||||
|
shadowRootRigidbody.MoveRotation(transform.rotation);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0, n = shadowTable.Count; i < n; i++) {
|
for (int i = 0, n = shadowTable.Count; i < n; i++) {
|
||||||
var pair = shadowTable[i];
|
var pair = shadowTable[i];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user