From 1a4607ff89d8b6ce21cbd835bdfcb7c0484b75e6 Mon Sep 17 00:00:00 2001 From: papacoder Date: Thu, 20 Nov 2025 23:07:17 +0900 Subject: [PATCH] fix: stabilize speech bubble orientation --- Runtime/View/ActorView.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Runtime/View/ActorView.cs b/Runtime/View/ActorView.cs index c3198b6..1bd805e 100644 --- a/Runtime/View/ActorView.cs +++ b/Runtime/View/ActorView.cs @@ -764,6 +764,7 @@ public void ShowSpeech(string message, bool isThought) m_SpeechBubble.style.borderBottomColor = borderColor; m_SpeechBubble.style.borderLeftColor = borderColor; + ApplySpeechBubbleTransformCompensation(); m_SpeechBubble.style.display = DisplayStyle.Flex; } @@ -789,6 +790,36 @@ private void ResetSpeechStyle() } } + /// + /// #root に適用した拡縮・左右反転を打ち消し、吹き出しを常に読みやすい向きと等倍サイズへ補正する。 + /// 俳優の向き変更や拡大率更新後にも安定した見た目を維持するために呼び出す。 + /// + private void ApplySpeechBubbleTransformCompensation() + { + if (m_SpeechBubble == null) + { + return; + } + + var root = GetRootElement(); + if (root == null) + { + return; + } + +#if UNITY_2022_3_OR_NEWER + var rootScale = ResolveScaleXY(root, 1f); + var safeScaleX = Mathf.Approximately(rootScale.x, 0f) ? 1f : rootScale.x; + var safeScaleY = Mathf.Approximately(rootScale.y, 0f) ? 1f : rootScale.y; + var compensatedX = 1f / safeScaleX; + var compensatedY = 1f / safeScaleY; + ApplyScaleXY(m_SpeechBubble, compensatedX, compensatedY); +#endif + + ApplyCenterPivot(m_SpeechBubble); + m_SpeechBubble.style.rotate = new Rotate(Angle.Degrees(0f)); + } + /// /// 表示中の吹き出しを非表示にし、本文をリセットする。 /// @@ -1424,6 +1455,7 @@ private void ApplyAllTransforms() /// /// 現在のスケール値を #root 要素へ適用し、中心を基点に拡縮できるようにする。 + /// 同時に吹き出し側の反転補正も行い、向き変更時の可読性を保つ。 /// private void ApplyScaleToRoot() { @@ -1438,6 +1470,7 @@ private void ApplyScaleToRoot() var scaleX = m_CurrentScale * m_FlipSignX; ApplyScaleXY(root, scaleX, m_CurrentScale); #endif + ApplySpeechBubbleTransformCompensation(); } ///