mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
Merge pull request #227 from pharan/bonecomponent
Fixed BoneComponent Z-positioning.
This commit is contained in:
commit
147c9bd763
@ -44,12 +44,29 @@ public class BoneComponent : MonoBehaviour {
|
||||
public SkeletonRenderer skeletonRenderer;
|
||||
public Bone bone;
|
||||
|
||||
public bool followZPosition = true;
|
||||
public bool followBoneRotation = true;
|
||||
|
||||
public SkeletonRenderer SkeletonRenderer {
|
||||
get { return skeletonRenderer; }
|
||||
set {
|
||||
skeletonRenderer = value;
|
||||
Reset ();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make the rotation behavior more customizable
|
||||
// public bool followTransformRotation = false;
|
||||
|
||||
// TODO: Make transform follow bone scale? too specific? This is really useful for shared shadow assets.
|
||||
//public bool followBoneScale = false;
|
||||
|
||||
/// <summary>If a bone isn't set, boneName is used to find the bone.</summary>
|
||||
public String boneName;
|
||||
|
||||
protected Transform cachedTransform;
|
||||
protected Transform skeletonTransform;
|
||||
|
||||
|
||||
public void Reset () {
|
||||
bone = null;
|
||||
cachedTransform = transform;
|
||||
@ -77,15 +94,28 @@ public class BoneComponent : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
Spine.Skeleton skeleton = skeletonRenderer.skeleton;
|
||||
float flipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f;
|
||||
|
||||
if (cachedTransform.parent == skeletonTransform) {
|
||||
cachedTransform.localPosition = new Vector3(bone.worldX, bone.worldY, cachedTransform.localPosition.z);
|
||||
Vector3 rotation = cachedTransform.localRotation.eulerAngles;
|
||||
cachedTransform.localRotation = Quaternion.Euler(rotation.x, rotation.y, bone.worldRotation);
|
||||
cachedTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : cachedTransform.localPosition.z);
|
||||
|
||||
if(followBoneRotation) {
|
||||
Vector3 rotation = cachedTransform.localRotation.eulerAngles;
|
||||
cachedTransform.localRotation = Quaternion.Euler(rotation.x, rotation.y, bone.worldRotation * flipRotation);
|
||||
}
|
||||
|
||||
} else {
|
||||
cachedTransform.position = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, cachedTransform.position.z));
|
||||
Vector3 rotation = skeletonTransform.rotation.eulerAngles;
|
||||
cachedTransform.rotation = Quaternion.Euler(rotation.x, rotation.y,
|
||||
skeletonTransform.rotation.eulerAngles.z + bone.worldRotation);
|
||||
Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, 0f));
|
||||
if(!followZPosition) targetWorldPosition.z = cachedTransform.position.z;
|
||||
|
||||
cachedTransform.position = targetWorldPosition;
|
||||
|
||||
if(followBoneRotation) {
|
||||
Vector3 rotation = skeletonTransform.rotation.eulerAngles;
|
||||
cachedTransform.rotation = Quaternion.Euler(rotation.x, rotation.y,
|
||||
skeletonTransform.rotation.eulerAngles.z + (bone.worldRotation * flipRotation) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -34,11 +34,14 @@ using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(BoneComponent))]
|
||||
public class BoneComponentInspector : Editor {
|
||||
private SerializedProperty boneName, skeletonRenderer;
|
||||
private SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation;
|
||||
|
||||
void OnEnable () {
|
||||
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
|
||||
boneName = serializedObject.FindProperty("boneName");
|
||||
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
||||
followZPosition = serializedObject.FindProperty("followZPosition");
|
||||
|
||||
}
|
||||
|
||||
override public void OnInspectorGUI () {
|
||||
@ -62,6 +65,9 @@ public class BoneComponentInspector : Editor {
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
boneName.stringValue = boneIndex == 0 ? null : bones[boneIndex];
|
||||
|
||||
EditorGUILayout.PropertyField(followBoneRotation);
|
||||
EditorGUILayout.PropertyField(followZPosition);
|
||||
}
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties() ||
|
||||
|
||||
@ -44,12 +44,29 @@ public class BoneComponent : MonoBehaviour {
|
||||
public SkeletonRenderer skeletonRenderer;
|
||||
public Bone bone;
|
||||
|
||||
public bool followZPosition = true;
|
||||
public bool followBoneRotation = true;
|
||||
|
||||
public SkeletonRenderer SkeletonRenderer {
|
||||
get { return skeletonRenderer; }
|
||||
set {
|
||||
skeletonRenderer = value;
|
||||
Reset ();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make the rotation behavior more customizable
|
||||
// public bool followTransformRotation = false;
|
||||
|
||||
// TODO: Make transform follow bone scale? too specific? This is really useful for shared shadow assets.
|
||||
//public bool followBoneScale = false;
|
||||
|
||||
/// <summary>If a bone isn't set, boneName is used to find the bone.</summary>
|
||||
public String boneName;
|
||||
|
||||
protected Transform cachedTransform;
|
||||
protected Transform skeletonTransform;
|
||||
|
||||
|
||||
public void Reset () {
|
||||
bone = null;
|
||||
cachedTransform = transform;
|
||||
@ -77,15 +94,28 @@ public class BoneComponent : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
Spine.Skeleton skeleton = skeletonRenderer.skeleton;
|
||||
float flipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f;
|
||||
|
||||
if (cachedTransform.parent == skeletonTransform) {
|
||||
cachedTransform.localPosition = new Vector3(bone.worldX, bone.worldY, cachedTransform.localPosition.z);
|
||||
Vector3 rotation = cachedTransform.localRotation.eulerAngles;
|
||||
cachedTransform.localRotation = Quaternion.Euler(rotation.x, rotation.y, bone.worldRotation);
|
||||
cachedTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : cachedTransform.localPosition.z);
|
||||
|
||||
if(followBoneRotation) {
|
||||
Vector3 rotation = cachedTransform.localRotation.eulerAngles;
|
||||
cachedTransform.localRotation = Quaternion.Euler(rotation.x, rotation.y, bone.worldRotation * flipRotation);
|
||||
}
|
||||
|
||||
} else {
|
||||
cachedTransform.position = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, cachedTransform.position.z));
|
||||
Vector3 rotation = skeletonTransform.rotation.eulerAngles;
|
||||
cachedTransform.rotation = Quaternion.Euler(rotation.x, rotation.y,
|
||||
skeletonTransform.rotation.eulerAngles.z + bone.worldRotation);
|
||||
Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, 0f));
|
||||
if(!followZPosition) targetWorldPosition.z = cachedTransform.position.z;
|
||||
|
||||
cachedTransform.position = targetWorldPosition;
|
||||
|
||||
if(followBoneRotation) {
|
||||
Vector3 rotation = skeletonTransform.rotation.eulerAngles;
|
||||
cachedTransform.rotation = Quaternion.Euler(rotation.x, rotation.y,
|
||||
skeletonTransform.rotation.eulerAngles.z + (bone.worldRotation * flipRotation) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -34,11 +34,14 @@ using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(BoneComponent))]
|
||||
public class BoneComponentInspector : Editor {
|
||||
private SerializedProperty boneName, skeletonRenderer;
|
||||
private SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation;
|
||||
|
||||
void OnEnable () {
|
||||
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
|
||||
boneName = serializedObject.FindProperty("boneName");
|
||||
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
||||
followZPosition = serializedObject.FindProperty("followZPosition");
|
||||
|
||||
}
|
||||
|
||||
override public void OnInspectorGUI () {
|
||||
@ -62,6 +65,9 @@ public class BoneComponentInspector : Editor {
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
boneName.stringValue = boneIndex == 0 ? null : bones[boneIndex];
|
||||
|
||||
EditorGUILayout.PropertyField(followBoneRotation);
|
||||
EditorGUILayout.PropertyField(followZPosition);
|
||||
}
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties() ||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user