From 16a41a1531382aa08e2c7115cf1efc8e7272bd66 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Sat, 19 Aug 2017 04:21:52 -0500 Subject: [PATCH] Unity add-on improvements - Use current filename as default - Better title for save dialog - Don't generate files if the user cancels out of the save dialog - Only get loop invariants once --- Assets/Editor/ExportAssetBundle.cs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Assets/Editor/ExportAssetBundle.cs b/Assets/Editor/ExportAssetBundle.cs index b4ae7ae..5bd731f 100644 --- a/Assets/Editor/ExportAssetBundle.cs +++ b/Assets/Editor/ExportAssetBundle.cs @@ -6,22 +6,24 @@ public class CreateAssetBundles { - [MenuItem ("Assets/Build Shader Bundle")] + [MenuItem ("Assets/Build Shader Bundles")] static void BuildAllAssetBundles () { // Bring up save panel - string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d"); - - var opts = BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.CollectDependencies; - BuildTarget[] platforms = { BuildTarget.StandaloneWindows, BuildTarget.StandaloneOSXUniversal, BuildTarget.StandaloneLinux }; - string[] platformExts = { "-windows", "-macosx", "-linux" }; + string path = EditorUtility.SaveFilePanel("Save Shader to Asset Bundles", "", "kopernicusshaders", "unity3d"); - for (var i = 0; i < platforms.Length; ++i) - { - // Build the resource file from the active selection. - Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.Assets); - BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path.Replace(".unity3d", platformExts[i] + ".unity3d"), opts, platforms[i]); - Selection.objects = selection; + if (path != string.Empty) { + const BuildAssetBundleOptions opts = BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.CollectDependencies; + BuildTarget[] platforms = { BuildTarget.StandaloneWindows, BuildTarget.StandaloneOSXUniversal, BuildTarget.StandaloneLinux }; + string[] platformExts = { "-windows", "-macosx", "-linux" }; + + Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.Assets); + var activeObj = Selection.activeObject; + for (var i = 0; i < platforms.Length; ++i) + { + // Build the resource file from the active selection. + BuildPipeline.BuildAssetBundle(activeObj, selection, path.Replace(".unity3d", platformExts[i] + ".unity3d"), opts, platforms[i]); + } } } -} \ No newline at end of file +}