Esempio n. 1
0
    private void OnGUI()
    {
        if (GUI.Button(new Rect(0, 0, 100, 100), "同步加载(随机)"))
        {
            LoadAsset(GetRandomPrefabPath());
        }
        if (GUI.Button(new Rect(0, 100, 100, 100), "同步加载(全部)"))
        {
            foreach (string prefabPath in GetAllPrefabPath())
            {
                LoadAsset(prefabPath);
            }
        }
        if (GUI.Button(new Rect(0, 200, 100, 100), "异步加载(随机)"))
        {
            LoadAssetAsync(GetRandomPrefabPath(), null);
        }
        if (GUI.Button(new Rect(0, 300, 100, 100), "异步加载(全部)"))
        {
            foreach (string prefabPath in GetAllPrefabPath())
            {
                LoadAssetAsync(prefabPath, null);
            }
        }
        GUI.TextArea(new Rect(120, 400, 150, 20), "Loading: " + loadingCount.ToString());
        GUI.TextArea(new Rect(120, 420, 150, 20), "Loaded: " + loadedAsset.Count);
        int totalRefCount = 0;

        foreach (KeyValuePair <UnityEngine.Object, int> entry in refCount)
        {
            totalRefCount += entry.Value;
        }
        GUI.TextArea(new Rect(120, 440, 150, 20), "TotRef: " + totalRefCount);
        GUI.TextArea(new Rect(120, 460, 150, 20), "BundleRef: " + abLoader.GetTotalRef());
        if (GUI.Button(new Rect(270, 400, 150, 100), "卸载全部"))
        {
            UnloadAll();
        }
        if (GUI.Button(new Rect(0, 400, 100, 100), "随机混合加载"))
        {
            foreach (string prefabPath in GetAllPrefabPath())
            {
                if (UnityEngine.Random.Range(0, 1) == 0)
                {
                    LoadAssetAsync(prefabPath, null);
                }
                else
                {
                    LoadAsset(prefabPath);
                }
            }
        }

        if (GUI.Button(new Rect(0, 500, 100, 100), "随机操作"))
        {
            if (randomTestCo != null)
            {
                StopCoroutine(randomTestCo);
            }
            randomTestCo = StartCoroutine(RandomTest());
        }

        if (GUI.Button(new Rect(0, 700, 100, 100), "停止随机操作"))
        {
            if (randomTestCo != null)
            {
                StopCoroutine(randomTestCo);
            }
        }

        //if (GUI.Button(new Rect(0, 600, 100, 100), "一个资源连续加载N次"))
        //{
        //    string _p = GetRandomPrefabPath();
        //    for (int i = 0; i < 200; ++ i)
        //    {
        //        LoadAssetAsync(_p, null);
        //    }
        //}
        if (GUI.Button(new Rect(0, 600, 100, 100), "随机卸载"))
        {
            UnityEngine.Object[] assets = new UnityEngine.Object[loadedAsset.Count];
            if (assets.Length > 0)
            {
                loadedAsset.Keys.CopyTo(assets, 0);
                int idx = UnityEngine.Random.Range(0, assets.Length);
                Debug.LogWarningFormat("trying to Unload {0}", loadedAsset[assets[idx]]);
                UnloadAsset(assets[idx]);
            }
        }
    }