using UnityEngine;
using UnityEditor;
using LitJson;
using System.IO;

public class VersionGUI
{
    private string mAppVersion;
    private string mResVersion;

    public void Awake()
    {
        VersionMgr.instance.Init();
        mAppVersion = VersionMgr.instance.appVersion;
        mResVersion = VersionMgr.instance.resVersion;
    }

    public void DrawVersion()
    {
        GUILayout.BeginHorizontal();
        mAppVersion = EditorGUILayout.TextField("app_version", mAppVersion);
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        mResVersion = EditorGUILayout.TextField("res_version", mResVersion);
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        JsonData jsonData = new JsonData();
        jsonData["app_version"] = mAppVersion;
        jsonData["res_version"] = mResVersion;
        if (GUILayout.Button("Save Version"))
        {
            using (StreamWriter sw = new StreamWriter(Application.dataPath + "/Resources/version.bytes"))
            {
                sw.Write(jsonData.ToJson());
            }
            AssetDatabase.Refresh();
            GameLogger.Log("Save version OK, app_version = " + mAppVersion + ", res_version = " + mResVersion);
            VersionMgr.instance.DeleteCacheResVersion();
            VersionMgr.instance.Init();
        }
        GUILayout.EndHorizontal();
    }
}