Skip to content

Commit

Permalink
[unity] Added updateSeparatorPartScale property to `SkeletonGraphic…
Browse files Browse the repository at this point in the history
…` to let render separator parts follow scale.
  • Loading branch information
HaraldCsaszar committed Jun 14, 2023
1 parent cbe0e54 commit ad614dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -103,6 +103,7 @@
* Timeline extension package: An additional Spine preferences parameter `Timeline` - `Default Mix Duration` has been added, setting newly added `SpineAnimationStateClip` clips accordingly, defaults to false. This Spine preferences parameter can be enabled to default to the previous behaviour before this update.
* Tint Black: Added support for [Tint Black](http://en.esotericsoftware.com/spine-slots#Tint-black) functionality at all Spine URP shaders (2D and 3D shaders) and at all standard pipeline `Spine/Sprite` shaders. This feature can be enabled via the `Tint Black` material parameter in the Inspector. Note: The URP Sprite shaders provided in the Spine URP Shaders extension UPM package require the latest version of the spine-unity runtime (package version 4.1.12, 2023-05-31 or newer) to display the added material parameters in the Inspector GUI.
* Added `SkeletonGraphic.MeshScale` property to allow access to calculated mesh scale. `MeshScale` is based on (1) Canvas pixels per unit, and (2) `RectTransform` bounds when using `Layout Scale Mode` other than `None` at `SkeletonGraphic` which scales the skeleton mesh to fit the parent `RectTransform` bounds accordingly.
* Added `updateSeparatorPartScale` property to `SkeletonGraphic` to let render separator parts follow the scale (lossy scale) of the `SkeletonGraphic` GameObject. Defaults to `false` to maintain existing behaviour.

* **Breaking changes**
* Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead.
Expand Down
Expand Up @@ -64,7 +64,8 @@ public class SkeletonGraphicInspector : UnityEditor.Editor {
updateTiming, updateWhenInvisible, unscaledTime, tintBlack, layoutScaleMode, editReferenceRect;
SerializedProperty initialFlipX, initialFlipY;
SerializedProperty meshGeneratorSettings;
SerializedProperty allowMultipleCanvasRenderers, separatorSlotNames, enableSeparatorSlots, updateSeparatorPartLocation;
SerializedProperty allowMultipleCanvasRenderers, separatorSlotNames, enableSeparatorSlots,
updateSeparatorPartLocation, updateSeparatorPartScale;
SerializedProperty raycastTarget, maskable;

readonly GUIContent UnscaledTimeLabel = new GUIContent("Unscaled Time",
Expand Down Expand Up @@ -141,6 +142,7 @@ public class SkeletonGraphicInspector : UnityEditor.Editor {

allowMultipleCanvasRenderers = so.FindProperty("allowMultipleCanvasRenderers");
updateSeparatorPartLocation = so.FindProperty("updateSeparatorPartLocation");
updateSeparatorPartScale = so.FindProperty("updateSeparatorPartScale");
enableSeparatorSlots = so.FindProperty("enableSeparatorSlots");

separatorSlotNames = so.FindProperty("separatorSlotNames");
Expand Down Expand Up @@ -304,7 +306,7 @@ public class SkeletonGraphicInspector : UnityEditor.Editor {
}

EditorGUILayout.Space();
SeparatorsField(separatorSlotNames, enableSeparatorSlots, updateSeparatorPartLocation);
SeparatorsField(separatorSlotNames, enableSeparatorSlots, updateSeparatorPartLocation, updateSeparatorPartScale);
}
}

Expand Down Expand Up @@ -428,7 +430,7 @@ public class SkeletonGraphicInspector : UnityEditor.Editor {
}

public static void SeparatorsField (SerializedProperty separatorSlotNames, SerializedProperty enableSeparatorSlots,
SerializedProperty updateSeparatorPartLocation) {
SerializedProperty updateSeparatorPartLocation, SerializedProperty updateSeparatorPartScale) {

bool multi = separatorSlotNames.serializedObject.isEditingMultipleObjects;
bool hasTerminalSlot = false;
Expand Down Expand Up @@ -466,6 +468,7 @@ public class SkeletonGraphicInspector : UnityEditor.Editor {

EditorGUILayout.PropertyField(enableSeparatorSlots, SpineInspectorUtility.TempContent("Enable Separation", tooltip: "Whether to enable separation at the above separator slots."));
EditorGUILayout.PropertyField(updateSeparatorPartLocation, SpineInspectorUtility.TempContent("Update Part Location", tooltip: "Update separator part GameObject location to match the position of the SkeletonGraphic. This can be helpful when re-parenting parts to a different GameObject."));
EditorGUILayout.PropertyField(updateSeparatorPartScale, SpineInspectorUtility.TempContent("Update Part Scale", tooltip: "Update separator part GameObject scale to match the scale (lossyScale) of the SkeletonGraphic. This can be helpful when re-parenting parts to a different GameObject."));
}
}

Expand Down
Expand Up @@ -116,6 +116,7 @@ public enum LayoutMode {
[SerializeField] protected List<Transform> separatorParts = new List<Transform>();
public List<Transform> SeparatorParts { get { return separatorParts; } }
public bool updateSeparatorPartLocation = true;
public bool updateSeparatorPartScale = false;

private bool wasUpdatedAfterInit = true;
private bool requiresInstructionUpate = true;
Expand Down Expand Up @@ -952,6 +953,17 @@ public enum LayoutMode {
separatorParts[p].rotation = this.transform.rotation;
}
}
if (updateSeparatorPartScale) {
Vector3 targetScale = this.transform.lossyScale;
for (int p = 0; p < this.separatorParts.Count; ++p) {
Transform partParent = separatorParts[p].transform.parent;
Vector3 parentScale = partParent == null ? Vector3.one : partParent.lossyScale;
separatorParts[p].localScale = new Vector3(
parentScale.x == 0f ? 1f : targetScale.x / parentScale.x,
parentScale.y == 0f ? 1f : targetScale.y / parentScale.y,
parentScale.z == 0f ? 1f : targetScale.z / parentScale.z);
}
}

for (int i = 0; i < submeshCount; i++) {
CanvasRenderer canvasRenderer = canvasRenderers[i];
Expand Down

0 comments on commit ad614dc

Please sign in to comment.