using UnityEngine; using Zenject; namespace FlappyBird.Gameplay.Pipes { /// /// Thin MonoBehaviour that lives on the pipe-pair prefab. /// Responsibilities: /// - Expose top/bottom pipe transforms for positioning by the spawner /// - Scroll leftward every frame /// - Return itself to the pool when off-screen /// NO spawn logic lives here. /// public sealed class PipeView : MonoBehaviour, Core.IPoolable { [Tooltip("Transform of the top pipe (flipped, hanging from above).")] [SerializeField] private Transform topPipe; [Tooltip("Transform of the bottom pipe (standing upright).")] [SerializeField] private Transform bottomPipe; [Tooltip("Score trigger collider child sitting in the centre of the gap.")] [SerializeField] private ScoreTriggerView scoreTrigger; // ── Public accessors used by PipeSpawner ─────────────────────────── public Transform TopPipe => topPipe; public Transform BottomPipe => bottomPipe; public ScoreTriggerView ScoreTrigger => scoreTrigger; // ── Injected ─────────────────────────────────────────────────────── private IPipePool _pool; private PipeSettings _settings; [Inject] private void Construct(IPipePool pool, PipeSettings settings) { _pool = pool; _settings = settings; } // ── Unity lifecycle ──────────────────────────────────────────────── private void Update() { ScrollLeft(); } // ── IPoolable ────────────────────────────────────────────────────── /// Called by the pool just before this pair is handed to the spawner. public void OnSpawn() { gameObject.SetActive(true); } /// Called by the pool when this pair is returned. public void OnDespawn() { gameObject.SetActive(false); } // ── Private helpers ──────────────────────────────────────────────── /// Moves the pipe pair leftward and despawns when off-screen. private void ScrollLeft() { transform.position += Vector3.left * (_settings.ScrollSpeed * Time.deltaTime); if (transform.position.x <= _settings.DespawnX) _pool.Return(this); } // ── Zenject factory ──────────────────────────────────────────────── /// /// Zenject factory used by PipePool to instantiate pipe-pair prefabs /// with full dependency injection applied. /// public sealed class Factory : PlaceholderFactory { } } }