using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Giant.Res;
using System;
using System.Reflection;

public class AssetsMgrTool : EditorWindow
{
    // Start is called before the first frame update

    [MenuItem("Giant Tools/AssetBundles/ShowAssetMgr")]
    static void OpenWind() {
        var window = EditorWindow.CreateWindow<AssetsMgrTool>();
    }

    Vector2 scrollpos;
    private void OnGUI()
    {
        if (!Application.isPlaying) {
            return;
        }


        scrollpos = EditorGUILayout.BeginScrollView(scrollpos);
        {
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Assets Refrence");
            Type type = typeof(AssetsMgr);
            FieldInfo fieldInfo = type.GetField("_assets", BindingFlags.Static | BindingFlags.NonPublic);
            var value = fieldInfo.GetValue(null) as Dictionary<string, AssetRequest>;
            foreach (var item in value)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(item.Key, GUILayout.Width(500));
                EditorGUILayout.IntField(item.Value.refCount);
                EditorGUILayout.LabelField("loaded ", item.Value.isDone.ToString());
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.LabelField("Bundle Refrence");
            fieldInfo = type.GetField("_bundles", BindingFlags.Static | BindingFlags.NonPublic);
            var value1 = fieldInfo.GetValue(null) as Dictionary<string, BundleRequest>;
            foreach (var item in value1)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(item.Key, GUILayout.Width(500));
                EditorGUILayout.IntField(item.Value.refCount);
                EditorGUILayout.LabelField("loaded ", item.Value.isDone.ToString());
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.LabelField("LoadingAssets");
            fieldInfo = type.GetField("_loadingAssetsRequest", BindingFlags.Static | BindingFlags.NonPublic);
            var loadings = fieldInfo.GetValue(null) as List<AssetRequest>;
            foreach (var item in loadings)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(item.path, GUILayout.Width(500));
                EditorGUILayout.LabelField("loaded ", item.isDone.ToString());
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndScrollView();
       
        Repaint();
    }
}
