using System;
using System.Collections;
using System.Collections.Generic;
using MPStudio;
using UnityEngine;
//Author: SkyAllen Email: 894982165@qq.com Website: www.ytn0.com
public class FoldImage : MonoBehaviour
{
    public bool isAutoAnimal = true;
    public float foldTime = 0.5f;
    RectTransform rt;

    private float initH;
    private void Awake()
    {
        rt = GetComponent<RectTransform>();
        initH = rt.sizeDelta.y;
        
        print(initH);
       // rt.sizeDelta = new Vector2(rt.sizeDelta.x, 200); // 保持宽度不变，高度设为200
    }

    private void OnEnable()
    {
        if (isAutoAnimal)
        {
            Show();
        }
    }

    public void Show()
    {
        StartCoroutine(
        TweenManager.Inst.ToFloat(0, initH, this.foldTime, (f) =>
        {
            rt.sizeDelta = new Vector2(rt.sizeDelta.x, f);
        }));
    }

    public void Hide()
    {
        print("hide");
        StartCoroutine(
            TweenManager.Inst.ToFloat(initH, 0, foldTime, (f) =>
            {
                
                rt.sizeDelta = new Vector2(rt.sizeDelta.x, f);
            }, () =>
            {
                gameObject.SetActive(false);
            }));
    }
}
