using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class totalView : MonoBehaviour
{
    public float showAnimationTime = 0.25f;
    public float showTime = 3f;
    public float hideAnimationTIme = 0.25f;
    public string title = "test xcvc kmxcv";
    public GameObject titleObj = null;
    private float nowY = 0;
    private float speed = 0.0f;
    private bool isRun = false;
    private Vector3 vector3 = new Vector3();
    private Quaternion quaternion = new Quaternion();
    public float distanc1 = 50;
    public float distanc2 = 50;
    // Start is called before the first frame update
    void Start()
    {
        titleObj.GetComponent<TextMeshProUGUI>().text = title;
    }
    void startShowView()
    {
        nowY = 0 - distanc1;
        isRun = true;
        transform.GetLocalPositionAndRotation(out vector3, out quaternion);
        vector3.y = nowY;
        transform.SetLocalPositionAndRotation(vector3, quaternion);
        speed = distanc1 / showAnimationTime;
    }
    // Update is called once per frame
    void Update()
    {
        if(isRun == true)
        {
            var nowY1 = nowY + (Time.deltaTime * speed);
            vector3.y = nowY1;
            
            transform.SetLocalPositionAndRotation(vector3, quaternion);
            if (nowY1 > 0 && nowY < 0)
            {
                isRun = false;
                Debug.Log(DateTime.Now.ToString());
                utilsTools.addTimer_Sec(gameObject, "pause", (string name1) => { 
                    speed = distanc2 / hideAnimationTIme;
                    isRun = true;
                    Debug.Log(DateTime.Now.ToString());
                    return false;
                    
                }, showTime);
            }
            else if(nowY1 > distanc2)
            {
                isRun = false;
                transform.SetParent(null);
                GameObject.Destroy(gameObject);
                return;

            }
            nowY = nowY1;

        }
    }
    public void onTestClick()
    {
        this.startShowView();
    }
    public void show()
    {
        startShowView();
    }

}
