using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.MeshOperations;

public class PlatformGenerator : MonoBehaviour{
    public Vector2 sizeRange = new Vector2(5f, 20f);

    public float snappingInterval = 2.5f;
    
    void Start(){
        
    }

    [Button]
    void GenerateNewPlatform(int corners){
        ProBuilderMesh newShape = new GameObject().AddComponent<ProBuilderMesh>();

        int originX = Mathf.RoundToInt(Random.Range(sizeRange.x, sizeRange.y));
        int originY = Mathf.RoundToInt(Random.Range(sizeRange.x, sizeRange.y));

        originX = -Mathf.Abs(originX);
        originY = -Mathf.Abs(originY);
        
        Vector3 origin = new Vector3(Snap(originX), 0f, Snap(originY));

        Vector3[] points = new Vector3[corners];
        
        for (int i = 0; i < corners; i++) {
            if (i == 0) {
                points[0] = origin;
            } else {
                points[i] = GetNewPoint(points[i - 1]);
            }
        }

        Vector3 GetNewPoint(Vector3 previous){
            return Vector3.zero;
            
        }

        float Snap(float input){
            return ((input = snappingInterval / 2) / snappingInterval) * snappingInterval;
        }
        
        newShape.CreateShapeFromPolygon(points, 5f, false);

    }
}
