Skip to content

Extend presentation

Derive from PresentationBehaviour when a custom visual component should follow a presentation group's context authority and rebinding lifecycle. Derive from PhaseController only when your behavior genuinely requires the owning Day Phase source and its phase-presentation contract.

Binding hooks

Hook/property Responsibility
Context Protected resolved simulation authority; do not replace it with a separate scene-global lookup
BindDependencies() Resolve needed systems and subscribe to their events
UnbindDependencies() Remove exactly those subscriptions
RefreshPresentation() Apply current state safely; account for missing/unready optional dependencies
ReleasePresentation() Release/restore only the scene state your adapter owns
SetContext(context) Sets an ungrouped controller override; an enclosing enabled group remains authoritative
ReconnectContext() / RefreshBindings() Re-resolve authority / force dependency rebinding

The base handles OnEnable/OnDisable, context-ready/refresh notifications, parent changes, and context precedence. Preserve that behavior if overriding Unity callbacks. Do not initialize a simulation from an edit-mode presentation Inspector or assume an optional system must exist.

Example adapter

Create SunHeightIndicator.cs, assign a separate target transform, and place the component under a bound group. Its vertical scale represents solar elevation between −6° and 20°; this is an illustrative display, not a solar model:

SunHeightIndicator.cs
using Sital.Tunal.Presentation;
using Sital.Tunal.Systems;
using UnityEngine;

namespace TunalExamples
{
    public sealed class SunHeightIndicator : PresentationBehaviour
    {
        [SerializeField] private Transform target;
        private AstronomicalSystem astronomy;
        private Vector3 originalScale;
        private bool captured;

        protected override void BindDependencies()
        {
            if (target != null && !captured)
            {
                originalScale = target.localScale;
                captured = true;
            }
            astronomy = Context != null ? Context.Astronomy : null;
            if (astronomy != null)
                astronomy.onAstronomicalStateUpdated.AddListener(RefreshPresentation);
        }

        protected override void UnbindDependencies()
        {
            if (astronomy != null)
                astronomy.onAstronomicalStateUpdated.RemoveListener(RefreshPresentation);
            astronomy = null;
        }

        protected override void RefreshPresentation()
        {
            if (target == null || !captured || astronomy == null ||
                !astronomy.isActiveAndEnabled || !astronomy.IsInitialized) return;
            Vector3 scale = originalScale;
            scale.y *= Mathf.InverseLerp(-6f, 20f, astronomy.SolarElevation);
            target.localScale = scale;
        }

        protected override void ReleasePresentation()
        {
            if (target != null && captured) target.localScale = originalScale;
            captured = false;
        }
    }
}

The adapter captures its owned scale, subscribes to Astronomy, and restores that scale on release. Avoid another animation/response writing the same transform scale. Changing the referenced target at runtime would need an explicit release/rebind policy; this small example assumes its target is configured before activation.

Custom lighting/environment adapters need the same ownership discipline for global settings. Presentation groups separate binding scopes, not private copies of RenderSettings. Use the one-visible-presentation pattern for independent contexts sharing a scene.

Related: reactive response extension, presentation setup, events.