using UnityEngine;

namespace NBF.TEST
{
    public class FurGenerator : MonoBehaviour
    {
        [SerializeField] private Transform capsuleTransform;
        [SerializeField] private VerletRope furPrefab;
        [SerializeField] private float furLength = 0.5f;
        [SerializeField] private float radius = 0.5f;
        [SerializeField] private float height = 2f;
        [SerializeField] private int radialSegments = 8;
        [SerializeField] private int heightSegments = 8;

        private void Start()
        {
            for (var i = 0; i < radialSegments; i++)
            {
                for (var j = 0; j < heightSegments; j++)
                {
                    var angle = ((float)i / radialSegments) * Mathf.PI * 2;
                    var y = ((float)j / heightSegments) * height - 1f;
                    var x = Mathf.Cos(angle) * radius;
                    var z = Mathf.Sin(angle) * radius;
                    var localPos = new Vector3(x, y, z);
                    var worldPos = capsuleTransform.TransformPoint(localPos);
                    var outDir = new Vector3(x, 0, z).normalized;
                    var endWorldPos = worldPos + outDir * furLength;
                    var fur = Instantiate(furPrefab, worldPos, Quaternion.identity);
                    fur.ropeStartPoint = worldPos;
                    fur.ropeEndPoint = endWorldPos;
                    fur.Enable();
                    fur.PinNode(0, capsuleTransform, localPos);
                }
            }            
        }
        
        private void StartDelayed()
        {
            
        }
    }
}