Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public override void Evaluate(float elapsed, float duration,
: 1f - EaseInQuad(Mathf.Clamp01(alphaElapsed / fadeDuration));
}

// FloatingTextAnimator.ScheduleEvaluateBatch must be overridden with a Burst-compatible batch path.
public override JobHandle ScheduleEvaluateBatch(
NativeArray<FloatingTextEntryNative> entries,
NativeArray<AnimationResult> results)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;
#if UNITY_ASSERTIONS
using UnityEngine.Assertions;
#endif

namespace LD.FloatingTextRenderFeature
{
Expand All @@ -10,6 +13,10 @@ namespace LD.FloatingTextRenderFeature
/// </summary>
public abstract class FloatingTextAnimator : ScriptableObject
{
#if DEVELOPMENT_BUILD || UNITY_EDITOR
private static bool s_loggedManagedFallbackWarning;
#endif

/// <summary>
/// Evaluate animation values at the given time.
/// </summary>
Expand All @@ -29,6 +36,22 @@ public virtual JobHandle ScheduleEvaluateBatch(
NativeArray<FloatingTextEntryNative> entries,
NativeArray<AnimationResult> results)
{
#if UNITY_ASSERTIONS
Assert.IsTrue(false,
$"[{nameof(FloatingTextAnimator)}] {GetType().Name} is using managed fallback in {nameof(ScheduleEvaluateBatch)}(). " +
"Override ScheduleEvaluateBatch() and provide a Burst-compatible job for production use.");
Comment on lines +40 to +42

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate fallback assertion to avoid per-frame assertion storms

The new fallback path asserts unconditionally on every ScheduleEvaluateBatch call in UNITY_ASSERTIONS builds, so any custom animator that doesn’t override this method now triggers repeated assertion failures every frame; in Editor configurations where assertions raise exceptions this can also abort the fallback execution and prevent animation output for that frame. This contradicts the intended "warn once" behavior and makes development runs noisy/unusable until fixed, so the assert should be emitted once (or downgraded) instead of firing on every update.

Useful? React with 👍 / 👎.

#endif

#if DEVELOPMENT_BUILD || UNITY_EDITOR
if (!s_loggedManagedFallbackWarning)
{
s_loggedManagedFallbackWarning = true;
Debug.LogWarning(
$"[{nameof(FloatingTextAnimator)}] {GetType().Name} did not override {nameof(ScheduleEvaluateBatch)}(). " +
"Falling back to managed Evaluate() loop. Implement a Burst job to avoid per-frame main-thread cost.");
}
#endif

for (int i = 0; i < entries.Length; i++)
{
var e = entries[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.AddressableAssets;
#if UNITY_ASSERTIONS
using UnityEngine.Assertions;
#endif
#if UNITY_EDITOR
using UnityEditor;
#endif
Expand Down Expand Up @@ -255,7 +258,10 @@ private void LateUpdate()

EnsureDigitOutputCapacity(totalDigits);

// ── Phase 3: Evaluate animation (Burst job or managed fallback) ──
// ── Phase 3: Evaluate animation (custom animator must provide ScheduleEvaluateBatch Burst job) ──
#if UNITY_ASSERTIONS
Assert.IsNotNull(_animator, $"[{nameof(FloatingTextManager)}] Animator is null.");
#endif
JobHandle animHandle = _animator.ScheduleEvaluateBatch(
_nativeEntries.GetSubArray(0, count),
_animResults.GetSubArray(0, count));
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ FloatingTextManager.Instance.Show(worldPosition, damage);
FloatingTextManager.Instance.Show(worldPosition, damage, duration: 1.0f, scale: 1.5f);
```

## 커스텀 Animator 작성 규칙

`FloatingTextAnimator`를 상속해 커스텀 애니메이터를 만들 때는 아래 규칙을 지켜주세요.

- `Evaluate(...)`는 단일 엔트리 계산 로직(수학식) 정의용입니다.
- `ScheduleEvaluateBatch(...)`는 **반드시 override** 해서 `IJobFor`/`IJobParallelFor` 기반의 Burst job을 스케줄해야 합니다.
- `FloatingTextManager`는 매 프레임 `_animator.ScheduleEvaluateBatch(...)`를 호출합니다.
- 미구현 시 managed fallback(`Evaluate` 루프)으로 진입하며, 개발 빌드/에디터에서는 경고 로그가 1회 출력됩니다.
- `UNITY_ASSERTIONS` 환경에서는 런타임 assert로 구현 누락을 빠르게 감지합니다.

권장: 기본 구현은 `DefaultFloatingTextAnimator`의 `ScheduleEvaluateBatch` 예제를 참고하세요.

## Font Sprite Generator

`Window > Floating Text > Font Sprite Generator` 메뉴에서 접근할 수 있는 에디터 도구입니다.
Expand Down