using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class SizeStretch : MonoBehaviour
{

    [SerializeField]
    private GridLayoutGroup gridLayoutGroupTarget;

    public void OnRectTransformDimensionsChange()
    {
        float lastX = gridLayoutGroupTarget.cellSize.x;

        float newX = GetComponent<RectTransform>().rect.width / 3;
        float ratio = newX / lastX;

        //Debug.Log(ratio);

        Vector2 newSize = new Vector2(newX, (gridLayoutGroupTarget.cellSize.y>0) ? gridLayoutGroupTarget.cellSize.y * ratio : 100);

        gridLayoutGroupTarget.cellSize = newSize;

        //gridLayoutGroupTarget.spacing = new Vector2(gridLayoutGroupTarget.spacing.x*ratio, gridLayoutGroupTarget.spacing.y);



    }
}
