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) { //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 }
private void RenderSelectedFileList() { LinkedListNode <FileSelector.FileNode> linkedListNode = this.m_SelectedFiles.First; while (linkedListNode != null) { FileSelector.FileNode value = linkedListNode.Value; GUILayout.BeginHorizontal(new GUILayoutOption[0]); value.Selected = GUILayout.Toggle(value.Selected, GUIContent.none, new GUILayoutOption[0]); value.RenderIconText(); if (MainAssetsUtil.CanPreview && GUILayout.Button("Preview", new GUILayoutOption[0])) { MainAssetsUtil.Preview(value.Name); } if (!value.Selected) { LinkedListNode <FileSelector.FileNode> node = linkedListNode; linkedListNode = linkedListNode.Next; this.m_SelectedFiles.Remove(node); } else { linkedListNode = linkedListNode.Next; GUILayout.EndHorizontal(); } } }
private void RenderSettings() { EditorGUILayout.Space(); GUILayout.Label("2. Select assets folder", new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); bool enabled = GUI.enabled; if (this.m_Package == null || this.m_Package.Status != Package.PublishedStatus.Draft || this.m_AssetsState != AssetStorePackageController.AssetsState.None) { GUI.enabled = false; } if (GUILayout.Button("Select...", new GUILayoutOption[] { GUILayout.Width(90f) })) { this.ChangeRootPathDialog(); } GUI.enabled = enabled; this.RenderAssetsFolderStatus(); GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (MainAssetsUtil.CanGenerateBundles) { GUILayout.Label("3. Select main assets", new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); bool enabled2 = GUI.enabled; if (this.m_Package == null || this.m_Package.Status != Package.PublishedStatus.Draft || string.IsNullOrEmpty(this.m_LocalRootPath) || !this.IsValidRelativeProjectFolder(this.m_LocalRootPath) || this.m_AssetsState != AssetStorePackageController.AssetsState.None) { GUI.enabled = false; } if (GUILayout.Button("Select...", new GUILayoutOption[] { GUILayout.Width(90f) })) { MainAssetsUtil.ShowManager(this.m_LocalRootPath, this.m_MainAssets, delegate(List <string> updatedMainAssets) { this.m_Dirty = true; this.m_MainAssets = updatedMainAssets; this.m_UnsavedChanges = true; }); } GUI.enabled = enabled2; this.RenderMainAssetsStatus(); GUILayout.EndHorizontal(); } EditorGUILayout.Space(); }
public void GenerateAssetBundles() { this.m_AssetBundleFiles = new Dictionary <string, string>(); foreach (string text in this.m_MainAssets) { DebugUtils.Log("processing: " + text); string text2 = MainAssetsUtil.CreateBundle(text); if (text2 == null) { DebugUtils.LogWarning(string.Format("Unable to Create Preview for: {0}", text)); } else { this.m_AssetBundleFiles.Add(text, text2); } } }
public static List <string> GetMainAssetsByTag(string folder) { List <string> list = new List <string>(); string[] files = Directory.GetFiles(Application.dataPath + folder); foreach (string text in files) { bool flag = false; string text2 = text.Substring(Application.dataPath.Length + 1); text2 = text2.Replace("\\", "/"); text2 = "Assets/" + text2; Regex regex = new Regex(".*[/][.][^/]*"); if (!regex.Match(text2).Success) { Object @object = AssetDatabase.LoadMainAssetAtPath(text2); if (!(@object == null)) { string[] labels = AssetDatabase.GetLabels(@object); foreach (string a in labels) { if (a == "MainAsset") { flag = true; break; } } if (flag) { list.Add(text2); } } } } string[] directories = Directory.GetDirectories(Application.dataPath + folder); foreach (string text3 in directories) { string folder2 = text3.Substring(Application.dataPath.Length); List <string> mainAssetsByTag = MainAssetsUtil.GetMainAssetsByTag(folder2); list.AddRange(mainAssetsByTag); } return(list); }