Skip to main content

Custom Animations

HookUI comes with simple built-in animations (Fade, Scale, Move, Rotate) via HookAnimatorComponent. However, for professional games, you usually want to use DOTween or standard Unity Animations instead.

extending HookView​

You can simply override the ShowRoutine and HideRoutine methods.

public class MyTweenView : HookView
{
public override IEnumerator ShowRoutine()
{
canvasGroup.alpha = 0;
// Example with DOTween (pseudo-code)
// yield return transform.DOScale(1, 0.5f).WaitForCompletion();

// Manual way:
float t = 0;
while(t < 0.5f) {
t += Time.deltaTime;
canvasGroup.alpha = t / 0.5f;
yield return null;
}

canvasGroup.alpha = 1;
}
}

Built-in animations: HookAnimatorComponent​

If a HookView (or HookUIComponent) has a HookAnimatorComponent attached, its ShowAnimation/HideAnimation fields drive the transition instead of a plain fade. Each is a HookAnimation — a plain [Serializable] class, not a ScriptableObject — with independently toggled parts:

public class HookAnimation
{
public float StartDelay = 0f;
public float Duration = 0.5f;
public EaseType Ease = EaseType.OutQuad;

public bool EnableFade; public float FadeFrom = 0f; public float FadeTo = 1f;
public bool EnableScale; public Vector3 ScaleFrom = Vector3.zero; public Vector3 ScaleTo = Vector3.one;
public bool EnableMove; public MoveDirection MoveFromDirection = MoveDirection.Bottom;
public float MoveDistance = 500f; public Vector2 MoveCustomFrom;
public bool EnableRotate; public Vector3 RotateFrom = new Vector3(0, 0, -90); public Vector3 RotateTo = Vector3.zero;
}

Turn on only the pieces you need (e.g. EnableFade + EnableMove for a fade-and-slide). MoveFromDirection can be Left/Right/Top/Bottom — computed from MoveDistance — or Custom, which uses MoveCustomFrom directly.

Presets vs. inline animations​

By default a HookAnimatorComponent's ShowAnimation/HideAnimation are inline — editing them only affects that one component. If you want a look you can reuse across many components, save it as a HookAnimationPreset asset instead (Create > HookUI > Animation Preset), a ScriptableObject that just wraps a single HookAnimation Data field.

Assigning a preset to a component is not a live link:

  1. Drag the preset asset onto the component's Target Preset field.
  2. Use the component's context menu — Load Preset into SHOW or Load Preset into HIDE — to copy preset.Data into ShowAnimation/HideAnimation. This is a one-time value copy (via a JsonUtility round-trip), not a reference: editing the preset afterward does not retroactively update anything you already loaded.
  3. To go the other direction, Export SHOW to New Asset / Export HIDE to New Asset saves whatever is currently inline out to a brand-new preset asset.

If you change a preset and want a component to pick up the new values, re-run Load Preset into SHOW/HIDE on it — nothing does that automatically.

Reacting to view events without inheriting​

If you want reusable behavior without inheriting HookView or touching HookAnimatorComponent at all, subscribe to the view's events from a separate component:

[RequireComponent(typeof(HookView))]
public class ViewSoundEffect : MonoBehaviour
{
void Awake()
{
var view = GetComponent<HookView>();
view.OnShowStarted.AddListener(PlaySound);
}

void PlaySound() { ... }
}