Add focused word scale-down and smooth camera shake + unfocus words scribble

This commit is contained in:
2026-01-27 20:13:18 +01:00
parent d1b7104676
commit b64a57d810
16 changed files with 764 additions and 32 deletions
@@ -57,18 +57,23 @@ namespace Unheimlich.Interactions.FloatingWords
private int _originalSortingOrder;
private Vector3 _startLocalPos;
private float _originalScale;
private float _originalTextScale = 1f;
private int _textScaleTweenId = -1;
private bool _positionCaptured = false;
private Vector3 _shakeOffset = Vector3.zero;
private Vector3 _shakeTarget = Vector3.zero;
private float _shakeTimer = 0f;
private bool _isShaking = false;
private float _shakeSpeedMultiplier = 1f;
private bool _disableFloatingEffects = false;
private Queue<Vector3> _positionHistory = new Queue<Vector3>();
private float _historyTimer = 0f;
private const float HISTORY_SAMPLE_RATE = 0.016f;
private SketchFadeEffect _sketchFadeEffect;
void Awake()
{
@@ -169,7 +174,7 @@ namespace Unheimlich.Interactions.FloatingWords
if (!GetEnableOrganicShake())
return;
_shakeTimer += Time.deltaTime * GetShakeSpeed();
_shakeTimer += Time.deltaTime * GetShakeSpeed() * _shakeSpeedMultiplier;
if (_shakeTimer >= 1f)
{
@@ -204,6 +209,29 @@ namespace Unheimlich.Interactions.FloatingWords
_shakeOffset = Vector3.zero;
}
public void SetShakeSpeedMultiplier(float multiplier)
{
_shakeSpeedMultiplier = Mathf.Max(0f, multiplier);
}
public void SetTextScale(float targetScale, float duration = 0.3f)
{
if (_choiceTextComponent == null)
return;
if (_textScaleTweenId >= 0)
LeanTween.cancel(_textScaleTweenId);
_textScaleTweenId = LeanTween.scale(_choiceTextComponent.gameObject, Vector3.one * targetScale, duration)
.setEase(LeanTweenType.easeOutQuad)
.id;
}
public void ResetTextScale(float duration = 0.3f)
{
SetTextScale(_originalTextScale, duration);
}
public void HideGhostTrail()
{
if (_ghostTextComponent != null)
@@ -230,6 +258,11 @@ namespace Unheimlich.Interactions.FloatingWords
LeanTween.cancel(gameObject);
StopOrganicShake();
DialogueAnimationSettings settings = GetAnimationSettings();
float textScaleMultiplier = settings != null ? settings.FocusedTextScaleMultiplier : 0.9f;
float textScaleDuration = settings != null ? settings.FocusedTextScaleDuration : 0.3f;
SetTextScale(textScaleMultiplier, textScaleDuration);
}
transform.localScale = Vector3.one * Mathf.Lerp(_originalScale, MAX_FOCUS_SCALE, progress);
@@ -374,7 +407,10 @@ namespace Unheimlich.Interactions.FloatingWords
}
_startLocalPos = transform.localPosition;
_originalScale = transform.localScale.x;
_originalScale = transform.localScale.x;
if (_choiceTextComponent != null)
_originalTextScale = _choiceTextComponent.transform.localScale.x;
LeanTween.cancel(gameObject);
@@ -383,6 +419,13 @@ namespace Unheimlich.Interactions.FloatingWords
if (_ghostTextComponent != null)
_ghostTextComponent.text = GetChoiceText();
DialogueAnimationSettings settings = GetAnimationSettings();
if (settings != null && settings.EnableSketchFadeOnFocus && settings.SketchMaterial != null)
{
_sketchFadeEffect = gameObject.AddComponent<SketchFadeEffect>();
_sketchFadeEffect.Initialize(_choiceTextComponent, _ghostTextComponent, settings.SketchMaterial);
}
StartOrganicShake();
}
@@ -465,8 +508,14 @@ namespace Unheimlich.Interactions.FloatingWords
/// </summary>
public void ResetFeedback(float duration)
{
LeanTween.cancel(gameObject);
LeanTween.cancel(gameObject);
if (_textScaleTweenId >= 0)
LeanTween.cancel(_textScaleTweenId);
StopOrganicShake();
ResetSketchFade();
LeanTween.moveLocal(gameObject, _startLocalPos, duration)
.setEase(LeanTweenType.easeOutQuad)
@@ -479,10 +528,11 @@ namespace Unheimlich.Interactions.FloatingWords
StartOrganicShake();
});
transform.localScale = Vector3.one;
transform.localScale = Vector3.one * _originalScale;
if (_choiceTextComponent != null)
{
_choiceTextComponent.transform.localScale = Vector3.one * _originalTextScale;
_choiceTextComponent.color = Color.white;
if (_ghostTextComponent != null)
@@ -497,5 +547,24 @@ namespace Unheimlich.Interactions.FloatingWords
if (_canvas != null)
_canvas.sortingOrder = _originalSortingOrder;
}
public void ApplySketchFade()
{
DialogueAnimationSettings settings = GetAnimationSettings();
if (settings == null || !settings.EnableSketchFadeOnFocus || _sketchFadeEffect == null)
return;
_sketchFadeEffect.PlaySketchFadeEffect(
settings.SketchDuration,
settings.FadeOutDuration,
settings.FinalFadeAlpha
);
}
public void ResetSketchFade()
{
if (_sketchFadeEffect != null)
_sketchFadeEffect.ResetEffect();
}
}
}