예제 #1
0
        static void BuildAll(bool IscompressedAssetBundle = true)
        {
            if (Selection.objects.Length == 0)
            {
                return;
            }
            AssetBundleBuild assetBundleBuild = new AssetBundleBuild();

            assetBundleBuild.assetNames = new string[Selection.objects.Length];
            for (int i = 0; i < Selection.objects.Length; i++)
            {
                assetBundleBuild.assetNames[i] = AssetDatabase.GetAssetPath(Selection.objects[i]);
            }
            directoryName = Path.GetDirectoryName(assetBundleBuild.assetNames[0]);
            Debug.Log(assetBundleBuild.assetNames[0]);
            if (Selection.objects.Length == 1)
            {
                assetBundleBuild.assetBundleName = Path.GetFileNameWithoutExtension(assetBundleBuild.assetNames[0]) + ".unity3d";
            }
            else
            {
                assetBundleBuild.assetBundleName = Path.GetFileName(directoryName) + ".unity3d";
            }
#if UNITY_ANDROID
            directoryName += "/Android";
#endif
#if UNITY_IOS
            directoryName += "/IOS";
#endif
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

#if UNITY_ANDROID
            if (IscompressedAssetBundle)
            {
                BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.None, BuildTarget.Android);
            }
            else
            {
                BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.Android);
            }
#endif

#if UNITY_IOS
            if (IscompressedAssetBundle)
            {
                BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.None, BuildTarget.iOS);
            }
            else
            {
                BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.iOS);
            }
#endif
        }
예제 #2
0
        public static void BuildOne(Object obj, bool IscompressedAssetBundle = true, string d = "", string fileName = "")
        {
            AssetBundleBuild assetBundleBuild = new AssetBundleBuild();

            assetBundleBuild.assetNames    = new string[1];
            assetBundleBuild.assetNames[0] = AssetDatabase.GetAssetPath(obj);
            directoryName = Path.GetDirectoryName(assetBundleBuild.assetNames[0]);
            if (string.IsNullOrEmpty(directoryName))
            {
                directoryName = d;
            }
            assetBundleBuild.assetBundleName = Path.GetFileNameWithoutExtension(assetBundleBuild.assetNames[0]) + ".unity3d";
            if (string.IsNullOrEmpty(fileName) == false)
            {
                assetBundleBuild.assetBundleName = fileName + ".unity3d";
            }
#if UNITY_ANDROID
            directoryName += "/Android";
#endif
#if UNITY_IOS
            directoryName += "/IOS";
#endif
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
            Debug.Log(directoryName);
#if UNITY_ANDROID
            if (IscompressedAssetBundle)
            {
                BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.None, BuildTarget.Android);
            }
            else
            {
                BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.Android);
            }
#endif

#if UNITY_IOS
            if (IscompressedAssetBundle)
            {
                BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.None, BuildTarget.iOS);
            }
            else
            {
                BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.iOS);
            }
#endif
        }
        static void BuildAssetBundle()
        {
            Debug.LogError("打包成package需将后缀unity删除");
            if (Selection.objects.Length == 0)
            {
                return;
            }
            AssetBundleBuild assetBundleBuild = new AssetBundleBuild();

            assetBundleBuild            = new AssetBundleBuild();
            assetBundleBuild.assetNames = new string[Selection.objects.Length];
            for (int i = 0; i < Selection.objects.Length; i++)
            {
                assetBundleBuild.assetNames[i] = AssetDatabase.GetAssetPath(Selection.objects[i]);
            }

            string directoryName = Path.GetDirectoryName(assetBundleBuild.assetNames[0]);

            //Debug.Log(directoryName);
            directoryName = "Assets/AssetBundle";
            if (Selection.objects.Length == 1)
            {
                assetBundleBuild.assetBundleName = Path.GetFileName(assetBundleBuild.assetNames[0]) + ".unity3d";
            }
            else
            {
                assetBundleBuild.assetBundleName = Path.GetFileName(directoryName) + ".unity3d";
            }

#if UNITY_ANDROID
            directoryName += "/Android";
#endif
#if UNITY_IOS
            directoryName += "/iOS";
#endif
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

#if UNITY_ANDROID
            BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.None, BuildTarget.Android);
#endif

#if UNITY_IOS
            BuildPipelineHelper.BuildAssetBundles(directoryName, new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.None, BuildTarget.iOS);
#endif
        }