using System.Collections.Generic;
using UnityEngine;

namespace KitsuneCafe.Rendering
{
    public class BillboardManager : MonoBehaviour
    {
        [SerializeField]
        private new Transform camera;

        [SerializeField]
        private bool registerChildren = false;

        private readonly List<Transform> transforms = new();

        private void Reset()
        {
            camera = Camera.main.transform;
        }

        private void Awake()
        {
            if (camera == null)
            {
                camera = Camera.main.transform;
            }
        }

        private void Start()
        {
            var count = transform.childCount;
            for (int i = 0; i < count; i++)
            {
                Register(transform.GetChild(i));
            }
        }

        private void Register(Transform transform)
        {
            transforms.Add(transform);
        }

        private void LateUpdate()
        {
            var count = transforms.Count;
            for (int i = 0; i < count; i++)
            {
                transforms[i].forward = camera.forward;
            }
        }
    }
}
