mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +08:00
[unity] Added option to BoneFollower components to follow attachment Z spacing offset. Defaults to false to maintain existing behaviour.
This commit is contained in:
parent
e103d4494f
commit
57844ebe15
@ -176,6 +176,7 @@
|
|||||||
3. In the `RenderExistingMeshGraphic` component Inspector at `Reference Skeleton Graphic` assign the original `SkeletonGraphic` object.
|
3. In the `RenderExistingMeshGraphic` component Inspector at `Reference Skeleton Graphic` assign the original `SkeletonGraphic` object.
|
||||||
4. At `Replacement Material` assign e.g. the included _SkeletonGraphicDefaultOutline_ material to replace all materials with this material. Alternatively, if `Multiple CanvasRenderers` is enabled at the reference SkeletonGraphic, you can add entries to the `Replacement Materials` list and at each entry assign the original SkeletonGraphic material (e.g. _SkeletonGraphicDefault_) to be replaced and the respective `Replacement Material` (e.g. _SkeletonGraphicDefaultOutline_).
|
4. At `Replacement Material` assign e.g. the included _SkeletonGraphicDefaultOutline_ material to replace all materials with this material. Alternatively, if `Multiple CanvasRenderers` is enabled at the reference SkeletonGraphic, you can add entries to the `Replacement Materials` list and at each entry assign the original SkeletonGraphic material (e.g. _SkeletonGraphicDefault_) to be replaced and the respective `Replacement Material` (e.g. _SkeletonGraphicDefaultOutline_).
|
||||||
- Added option for unsafe direct data loading when loading skeleton binary data to avoid some allocations, enabled via build define `SPINE_ALLOW_UNSAFE`. This define can be set via Spine Preferences, setting `Unsafe Build Defines - Direct data access`. The define is disabled by default to maintain existing behaviour. Changed asmdef setting for spine-unity assembly to allow unsafe code, has no effect other than allowing setting the `SPINE_ALLOW_UNSAFE` define.
|
- Added option for unsafe direct data loading when loading skeleton binary data to avoid some allocations, enabled via build define `SPINE_ALLOW_UNSAFE`. This define can be set via Spine Preferences, setting `Unsafe Build Defines - Direct data access`. The define is disabled by default to maintain existing behaviour. Changed asmdef setting for spine-unity assembly to allow unsafe code, has no effect other than allowing setting the `SPINE_ALLOW_UNSAFE` define.
|
||||||
|
- Added option to `BoneFollower` components to follow attachment Z spacing offset. The Inspector component property can be found under `Follow Z Position` - `Attachment Z Spacing`. Defaults to `false` to maintain existing behaviour.
|
||||||
|
|
||||||
- **Breaking changes**
|
- **Breaking changes**
|
||||||
|
|
||||||
|
|||||||
@ -38,8 +38,8 @@ namespace Spine.Unity.Editor {
|
|||||||
[CustomEditor(typeof(BoneFollowerGraphic)), CanEditMultipleObjects]
|
[CustomEditor(typeof(BoneFollowerGraphic)), CanEditMultipleObjects]
|
||||||
public class BoneFollowerGraphicInspector : Editor {
|
public class BoneFollowerGraphicInspector : Editor {
|
||||||
|
|
||||||
SerializedProperty boneName, skeletonGraphic, followXYPosition, followZPosition, followBoneRotation,
|
SerializedProperty boneName, skeletonGraphic, followXYPosition, followZPosition, followAttachmentZSpacing,
|
||||||
followLocalScale, followParentWorldScale, followSkeletonFlip, maintainedAxisOrientation;
|
followBoneRotation, followLocalScale, followParentWorldScale, followSkeletonFlip, maintainedAxisOrientation;
|
||||||
BoneFollowerGraphic targetBoneFollower;
|
BoneFollowerGraphic targetBoneFollower;
|
||||||
bool needsReset;
|
bool needsReset;
|
||||||
|
|
||||||
@ -75,6 +75,7 @@ namespace Spine.Unity.Editor {
|
|||||||
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
||||||
followXYPosition = serializedObject.FindProperty("followXYPosition");
|
followXYPosition = serializedObject.FindProperty("followXYPosition");
|
||||||
followZPosition = serializedObject.FindProperty("followZPosition");
|
followZPosition = serializedObject.FindProperty("followZPosition");
|
||||||
|
followAttachmentZSpacing = serializedObject.FindProperty("followAttachmentZSpacing");
|
||||||
followLocalScale = serializedObject.FindProperty("followLocalScale");
|
followLocalScale = serializedObject.FindProperty("followLocalScale");
|
||||||
followParentWorldScale = serializedObject.FindProperty("followParentWorldScale");
|
followParentWorldScale = serializedObject.FindProperty("followParentWorldScale");
|
||||||
followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip");
|
followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip");
|
||||||
@ -172,6 +173,10 @@ namespace Spine.Unity.Editor {
|
|||||||
EditorGUILayout.PropertyField(followBoneRotation);
|
EditorGUILayout.PropertyField(followBoneRotation);
|
||||||
EditorGUILayout.PropertyField(followXYPosition);
|
EditorGUILayout.PropertyField(followXYPosition);
|
||||||
EditorGUILayout.PropertyField(followZPosition);
|
EditorGUILayout.PropertyField(followZPosition);
|
||||||
|
if (followZPosition.boolValue == true) {
|
||||||
|
using (new SpineInspectorUtility.IndentScope())
|
||||||
|
EditorGUILayout.PropertyField(followAttachmentZSpacing, new GUIContent("Attachment Z Spacing"));
|
||||||
|
}
|
||||||
EditorGUILayout.PropertyField(followLocalScale);
|
EditorGUILayout.PropertyField(followLocalScale);
|
||||||
EditorGUILayout.PropertyField(followParentWorldScale);
|
EditorGUILayout.PropertyField(followParentWorldScale);
|
||||||
EditorGUILayout.PropertyField(followSkeletonFlip);
|
EditorGUILayout.PropertyField(followSkeletonFlip);
|
||||||
|
|||||||
@ -37,8 +37,8 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
[CustomEditor(typeof(BoneFollower)), CanEditMultipleObjects]
|
[CustomEditor(typeof(BoneFollower)), CanEditMultipleObjects]
|
||||||
public class BoneFollowerInspector : Editor {
|
public class BoneFollowerInspector : Editor {
|
||||||
SerializedProperty boneName, skeletonRenderer, followXYPosition, followZPosition, followBoneRotation,
|
SerializedProperty boneName, skeletonRenderer, followXYPosition, followZPosition, followAttachmentZSpacing,
|
||||||
followLocalScale, followParentWorldScale, followSkeletonFlip, maintainedAxisOrientation;
|
followBoneRotation, followLocalScale, followParentWorldScale, followSkeletonFlip, maintainedAxisOrientation;
|
||||||
BoneFollower targetBoneFollower;
|
BoneFollower targetBoneFollower;
|
||||||
bool needsReset;
|
bool needsReset;
|
||||||
|
|
||||||
@ -85,6 +85,7 @@ namespace Spine.Unity.Editor {
|
|||||||
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
||||||
followXYPosition = serializedObject.FindProperty("followXYPosition");
|
followXYPosition = serializedObject.FindProperty("followXYPosition");
|
||||||
followZPosition = serializedObject.FindProperty("followZPosition");
|
followZPosition = serializedObject.FindProperty("followZPosition");
|
||||||
|
followAttachmentZSpacing = serializedObject.FindProperty("followAttachmentZSpacing");
|
||||||
followLocalScale = serializedObject.FindProperty("followLocalScale");
|
followLocalScale = serializedObject.FindProperty("followLocalScale");
|
||||||
followParentWorldScale = serializedObject.FindProperty("followParentWorldScale");
|
followParentWorldScale = serializedObject.FindProperty("followParentWorldScale");
|
||||||
followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip");
|
followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip");
|
||||||
@ -178,6 +179,10 @@ namespace Spine.Unity.Editor {
|
|||||||
EditorGUILayout.PropertyField(followBoneRotation);
|
EditorGUILayout.PropertyField(followBoneRotation);
|
||||||
EditorGUILayout.PropertyField(followXYPosition);
|
EditorGUILayout.PropertyField(followXYPosition);
|
||||||
EditorGUILayout.PropertyField(followZPosition);
|
EditorGUILayout.PropertyField(followZPosition);
|
||||||
|
if (followZPosition.boolValue == true) {
|
||||||
|
using (new SpineInspectorUtility.IndentScope())
|
||||||
|
EditorGUILayout.PropertyField(followAttachmentZSpacing, new GUIContent("Attachment Z Spacing"));
|
||||||
|
}
|
||||||
EditorGUILayout.PropertyField(followLocalScale);
|
EditorGUILayout.PropertyField(followLocalScale);
|
||||||
EditorGUILayout.PropertyField(followParentWorldScale);
|
EditorGUILayout.PropertyField(followParentWorldScale);
|
||||||
EditorGUILayout.PropertyField(followSkeletonFlip);
|
EditorGUILayout.PropertyField(followSkeletonFlip);
|
||||||
|
|||||||
@ -62,6 +62,7 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
public bool followXYPosition = true;
|
public bool followXYPosition = true;
|
||||||
public bool followZPosition = true;
|
public bool followZPosition = true;
|
||||||
|
public bool followAttachmentZSpacing = false;
|
||||||
public bool followBoneRotation = true;
|
public bool followBoneRotation = true;
|
||||||
|
|
||||||
[Tooltip("Follows the skeleton's flip state by controlling this Transform's local scale.")]
|
[Tooltip("Follows the skeleton's flip state by controlling this Transform's local scale.")]
|
||||||
@ -158,9 +159,10 @@ namespace Spine.Unity {
|
|||||||
float additionalFlipScale = 1;
|
float additionalFlipScale = 1;
|
||||||
if (skeletonTransformIsParent) {
|
if (skeletonTransformIsParent) {
|
||||||
// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
|
// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
|
||||||
thisTransform.localPosition = new Vector3(followXYPosition ? bone.WorldX : thisTransform.localPosition.x,
|
thisTransform.localPosition = new Vector3(
|
||||||
followXYPosition ? bone.WorldY : thisTransform.localPosition.y,
|
followXYPosition ? bone.WorldX : thisTransform.localPosition.x,
|
||||||
followZPosition ? 0f : thisTransform.localPosition.z);
|
followXYPosition ? bone.WorldY : thisTransform.localPosition.y,
|
||||||
|
followZPosition ? (followAttachmentZSpacing ? GetAttachmentZPosition() : 0f) : thisTransform.localPosition.z);
|
||||||
if (followBoneRotation) {
|
if (followBoneRotation) {
|
||||||
float halfRotation = Mathf.Atan2(bone.C, bone.A) * 0.5f;
|
float halfRotation = Mathf.Atan2(bone.C, bone.A) * 0.5f;
|
||||||
if (followLocalScale && bone.ScaleX < 0) // Negate rotation from negative scaleX. Don't use negative determinant. local scaleY doesn't factor into used rotation.
|
if (followLocalScale && bone.ScaleX < 0) // Negate rotation from negative scaleX. Don't use negative determinant. local scaleY doesn't factor into used rotation.
|
||||||
@ -174,7 +176,8 @@ namespace Spine.Unity {
|
|||||||
} else { // For special cases: Use transform world properties if transform relationship is complicated
|
} else { // For special cases: Use transform world properties if transform relationship is complicated
|
||||||
if (!skeletonTransform) return;
|
if (!skeletonTransform) return;
|
||||||
|
|
||||||
Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.WorldX, bone.WorldY, 0f));
|
float z0Position = (followZPosition && followAttachmentZSpacing) ? GetAttachmentZPosition() : 0f;
|
||||||
|
Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.WorldX, bone.WorldY, z0Position));
|
||||||
if (!followZPosition) targetWorldPosition.z = thisTransform.position.z;
|
if (!followZPosition) targetWorldPosition.z = thisTransform.position.z;
|
||||||
if (!followXYPosition) {
|
if (!followXYPosition) {
|
||||||
targetWorldPosition.x = thisTransform.position.x;
|
targetWorldPosition.x = thisTransform.position.x;
|
||||||
@ -221,5 +224,11 @@ namespace Spine.Unity {
|
|||||||
thisTransform.localScale = localScale;
|
thisTransform.localScale = localScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GetAttachmentZPosition () {
|
||||||
|
int boneIndex = skeletonRenderer.Skeleton.DrawOrder.FindIndex(slot => slot.Bone == bone);
|
||||||
|
if (boneIndex < 0) return 0f;
|
||||||
|
return skeletonRenderer.zSpacing * boneIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,6 +70,7 @@ namespace Spine.Unity {
|
|||||||
public bool followParentWorldScale = false;
|
public bool followParentWorldScale = false;
|
||||||
public bool followXYPosition = true;
|
public bool followXYPosition = true;
|
||||||
public bool followZPosition = true;
|
public bool followZPosition = true;
|
||||||
|
public bool followAttachmentZSpacing = false;
|
||||||
[Tooltip("Applies when 'Follow Skeleton Flip' is disabled but 'Follow Bone Rotation' is enabled."
|
[Tooltip("Applies when 'Follow Skeleton Flip' is disabled but 'Follow Bone Rotation' is enabled."
|
||||||
+ " When flipping the skeleton by scaling its Transform, this follower's rotation is adjusted"
|
+ " When flipping the skeleton by scaling its Transform, this follower's rotation is adjusted"
|
||||||
+ " instead of its scale to follow the bone orientation. When one of the axes is flipped, "
|
+ " instead of its scale to follow the bone orientation. When one of the axes is flipped, "
|
||||||
@ -145,15 +146,17 @@ namespace Spine.Unity {
|
|||||||
float additionalFlipScale = 1;
|
float additionalFlipScale = 1;
|
||||||
if (skeletonTransformIsParent) {
|
if (skeletonTransformIsParent) {
|
||||||
// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
|
// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
|
||||||
thisTransform.localPosition = new Vector3(followXYPosition ? bone.WorldX * scale + offset.x : thisTransform.localPosition.x,
|
thisTransform.localPosition = new Vector3(
|
||||||
followXYPosition ? bone.WorldY * scale + offset.y : thisTransform.localPosition.y,
|
followXYPosition ? bone.WorldX * scale + offset.x : thisTransform.localPosition.x,
|
||||||
followZPosition ? 0f : thisTransform.localPosition.z);
|
followXYPosition ? bone.WorldY * scale + offset.y : thisTransform.localPosition.y,
|
||||||
|
followZPosition ? (followAttachmentZSpacing ? GetAttachmentZPosition() : 0f) : thisTransform.localPosition.z);
|
||||||
if (followBoneRotation) thisTransform.localRotation = bone.GetQuaternion();
|
if (followBoneRotation) thisTransform.localRotation = bone.GetQuaternion();
|
||||||
} else { // For special cases: Use transform world properties if transform relationship is complicated
|
} else { // For special cases: Use transform world properties if transform relationship is complicated
|
||||||
if (!skeletonTransform) return;
|
if (!skeletonTransform) return;
|
||||||
|
|
||||||
|
float z0Position = (followZPosition && followAttachmentZSpacing) ? GetAttachmentZPosition() : 0f;
|
||||||
Vector3 targetWorldPosition = skeletonTransform.TransformPoint(
|
Vector3 targetWorldPosition = skeletonTransform.TransformPoint(
|
||||||
new Vector3(bone.WorldX * scale + offset.x, bone.WorldY * scale + offset.y, 0f));
|
new Vector3(bone.WorldX * scale + offset.x, bone.WorldY * scale + offset.y, z0Position));
|
||||||
if (!followZPosition) targetWorldPosition.z = thisTransform.position.z;
|
if (!followZPosition) targetWorldPosition.z = thisTransform.position.z;
|
||||||
if (!followXYPosition) {
|
if (!followXYPosition) {
|
||||||
targetWorldPosition.x = thisTransform.position.x;
|
targetWorldPosition.x = thisTransform.position.x;
|
||||||
@ -200,5 +203,11 @@ namespace Spine.Unity {
|
|||||||
thisTransform.localScale = localScale;
|
thisTransform.localScale = localScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GetAttachmentZPosition () {
|
||||||
|
int boneIndex = skeletonGraphic.Skeleton.DrawOrder.FindIndex(slot => slot.Bone == bone);
|
||||||
|
if (boneIndex < 0) return 0f;
|
||||||
|
return skeletonGraphic.MeshGenerator.settings.zSpacing * skeletonGraphic.MeshScale * boneIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user