Exemple #1
0
        public void Preview(string assetpath)
        {
            //UnityEditorInternal.AssetStoreToolUtils.PreviewAssetStoreAssetBundleInInspector
            //and
            //UnityEditorInternal.AssetStoreToolUtils.UpdatePreloadingInternal
            //is missing from Unity 2020.x+. It's available in 2019.4 or earlier.
            //So it's impossible for this method to work normally.
#if !UNITY_2020_1_OR_NEWER
            string          path            = MainAssetsUtil.CreateBundle(assetpath);
            AssetStoreAsset assetStoreAsset = new AssetStoreAsset();
            assetStoreAsset.name = "Preview";
            byte[] bytes = File.ReadAllBytes(path);
            AssetBundleCreateRequest assetBundleCreateRequest = this.LoadFromMemoryAsync(bytes);
            if (assetBundleCreateRequest == null)
            {
                DebugUtils.Log("Unable to generate preview");
                return;
            }
            while (!assetBundleCreateRequest.isDone)
            {
                AssetStoreToolUtils.UpdatePreloadingInternal();
            }
            AssetBundle assetBundle = assetBundleCreateRequest.assetBundle;
            if (assetBundle == null)
            {
                DebugUtils.Log("No bundle at path");
                return;
            }
            AssetStoreToolUtils.PreviewAssetStoreAssetBundleInInspector(assetBundle, assetStoreAsset);
            assetBundle.Unload(false);
            File.Delete(path);
#endif
        }
        public void Preview(string assetpath)
        {
#if UNITY_5_4_0 || UNITY_5_5_0
            string          path            = MainAssetsUtil.CreateBundle(assetpath);
            AssetStoreAsset assetStoreAsset = new AssetStoreAsset();
            assetStoreAsset.name = "Preview";
            byte[] binary = File.ReadAllBytes(path);
            AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync(binary);
            if (assetBundleCreateRequest == null)
            {
                DebugUtils.Log("Unable to generate preview");
            }
            while (!assetBundleCreateRequest.isDone)
            {
                AssetStoreToolUtils.UpdatePreloadingInternal();
            }
            AssetBundle assetBundle = assetBundleCreateRequest.assetBundle;
            if (assetBundle == null)
            {
                DebugUtils.Log("No bundle at path");
                return;
            }
            AssetStoreToolUtils.PreviewAssetStoreAssetBundleInInspector(assetBundle, assetStoreAsset);
            assetBundle.Unload(false);
            File.Delete(path);
#endif
        }
    public void Preview(string assetpath)
    {
        string          str             = MainAssetsUtil.CreateBundle(assetpath);
        AssetStoreAsset assetStoreAsset = new AssetStoreAsset()
        {
            name = "Preview"
        };
        AssetBundleCreateRequest assetBundleCreateRequest = this.LoadFromMemoryAsync(File.ReadAllBytes(str));

        if (assetBundleCreateRequest == null)
        {
            DebugUtils.Log("Unable to generate preview");
        }
        while (!assetBundleCreateRequest.isDone)
        {
            AssetStoreToolUtils.UpdatePreloadingInternal();
        }
        AssetBundle assetBundle = assetBundleCreateRequest.assetBundle;

        if (assetBundle == null)
        {
            DebugUtils.Log("No bundle at path");
            assetBundleCreateRequest = null;
            return;
        }
        AssetStoreToolUtils.PreviewAssetStoreAssetBundleInInspector(assetBundle, assetStoreAsset);
        assetBundle.Unload(false);
        assetBundleCreateRequest = null;
        File.Delete(str);
    }