Exemplo n.º 1
0
        static ScrutinizeAssetBundle()
        {
            if (GameObject.Find("[scrutinizer]") == null)
            {
                return;
            }
            Scrutinizer scrutinizer = GameObject.Find("[scrutinizer]").GetComponent <Scrutinizer>();

            Debug.Log(scrutinizer.assetBundlePath);

            string url = "file://" + scrutinizer.assetBundlePath;

            Swing.Editor.EditorCoroutine.start(Download(scrutinizer, url));
        }
Exemplo n.º 2
0
        static IEnumerator Download(Scrutinizer _scrutinizer, string _url)
        {
            var www = UnityWebRequestAssetBundle.GetAssetBundle(_url);

            yield return(www.SendWebRequest());

            DownloadHandlerAssetBundle tempAsset = (DownloadHandlerAssetBundle)www.downloadHandler;
            AssetBundle bundle = tempAsset.assetBundle;

            int   count         = 0;
            int   total         = bundle.GetAllAssetNames().Length;
            float standardToken = 0;

            EditorUtility.DisplayProgressBar("檢測中...0% (同物件權重誤差約為30)", "檢測物件 : " + "開始掃描Prefab", (float)count / (float)total);



            System.Diagnostics.Stopwatch swRoot = new System.Diagnostics.Stopwatch();
            swRoot.Start();
            for (int i = 0; i < 100; ++i)
            {
                var        loadedAssetRoot = bundle.LoadAsset <GameObject>(_scrutinizer.targetPrefabRootAssetName);
                GameObject goRoot          = GameObject.Instantiate(loadedAssetRoot as GameObject);
                GameObject.DestroyImmediate(goRoot);
            }
            swRoot.Stop();
            standardToken = swRoot.Elapsed.Ticks / 100f;
            var tokenRoot = standardToken;

            tokenRoot = tokenRoot * (1000f / standardToken);
            yield return(null);

            ++count;
            EditorUtility.DisplayProgressBar(string.Format("檢測中...{0}% (同物件權重誤差約為30)", (((float)count * 100) / (float)total).ToString("f1")), "檢測物件 : " + _scrutinizer.targetPrefabRootAssetName, (float)count / (float)total);
            CustomHierarchyView.performances.Put(_scrutinizer.prefabPathMap[_scrutinizer.prefabPaths.IndexOf(_scrutinizer.targetPrefabRootAssetName)], (int)tokenRoot);



            foreach (string assetName in bundle.GetAllAssetNames())
            {
                if (assetName.Equals(_scrutinizer.targetPrefabRootAssetName))
                {
                    continue;
                }
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();

                for (int i = 0; i < 100; ++i)
                {
                    var        loadedAsset = bundle.LoadAsset <GameObject>(assetName);
                    GameObject go          = GameObject.Instantiate(loadedAsset as GameObject);
                    GameObject.DestroyImmediate(go);
                }
                sw.Stop();
                float token = sw.Elapsed.Ticks / 100f;

                if (_scrutinizer.targetPrefabRoot == _scrutinizer.prefabPathMap[_scrutinizer.prefabPaths.IndexOf(assetName)])
                {
                    standardToken = token;
                }
                token = token * (1000f / standardToken);
                yield return(null);

                ++count;
                EditorUtility.DisplayProgressBar(string.Format("檢測中...{0}% (同物件權重誤差約為30)", (((float)count * 100) / (float)total).ToString("f1")), "檢測物件 : " + assetName, (float)count / (float)total);

                try
                {
                    CustomHierarchyView.performances.Put(_scrutinizer.prefabPathMap[_scrutinizer.prefabPaths.IndexOf(assetName)], (int)token);
                }
                catch
                {
                    bundle.Unload(false);
                    EditorUtility.ClearProgressBar();
                    Resources.UnloadUnusedAssets();
                }
            }
            bundle.Unload(false);
            EditorUtility.ClearProgressBar();
            Resources.UnloadUnusedAssets();
            DestroyImmediate(_scrutinizer.gameObject);
            System.IO.File.Delete("Assets/Prefab_Temporary_Detector");
        }