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

namespace Toast.SmartDownloader.Example
{
    [ExecuteInEditMode]
    public class FileSizeText : MonoBehaviour
    {
        public ProgressBar ProgressBar;
        private Text Percentage;

        void Awake()
        {
            Percentage = GetComponent<Text>();
            if (Percentage == null)
            {
                Debug.LogError("Failed to get a UnityEngine.UI.Text component in this GameObjct");
                return;
            }

            if (ProgressBar == null)
            {
                Debug.LogError("Failed to load ProgressBar in this FileSizeText");
                return;
            }

            ProgressBar.OnPercentageChanged += (percentage, completeFileSize, totalFileSize) =>
            {
                Percentage.text = string.Format("{0:F2} KB / {1:F2} KB", completeFileSize, totalFileSize);
            };
        }
    }
}