Beispiel #1
0
        private void LoadConfig()
        {
            m_settings = new BundleBuildSettings();

            string fullpath = "BundleBuildSettings.xml";

            if (File.Exists(fullpath))
            {
                string            content        = File.ReadAllText(fullpath);
                XmlReaderSettings readerSettings = new XmlReaderSettings();
                readerSettings.CheckCharacters = false;
                readerSettings.CloseInput      = true;

                using (var cr = XmlReader.Create(new StringReader(content), readerSettings))
                {
                    XmlSerializer serialize = new XmlSerializer(typeof(BundleBuildSettings));
                    m_settings = serialize.Deserialize(cr) as BundleBuildSettings;
                }
            }
        }
        private static void createAssetBundle(string buildPath, BuildTarget buildTarget, BundleBuildSettings settings)
        {
            Caching.ClearCache();
            ///默认的路径
            string Path = buildPath + "/AssetBundles";

            if (!Directory.Exists(Path))
            {
                Directory.CreateDirectory(Path);
            }

            ClearDirectory(Path);

            if (settings != null)
            {
                AssetBundleBuild[] builds = settings.GetAssetBundleBuilds();
                if (builds != null)
                {
                    BuildPipeline.BuildAssetBundles(Path, builds, BuildAssetBundleOptions.ChunkBasedCompression, buildTarget);
                }
            }
            else
            {
                BuildPipeline.BuildAssetBundles(Path, BuildAssetBundleOptions.ChunkBasedCompression, buildTarget);
            }
        }
        public static void BuildAssetBundles(string buildPath, BundleBuildTarget bundleBuildTarget, BundleBuildSettings settings = null)
        {
            BuildTarget buildTarget = BuildTarget.NoTarget;

            switch (bundleBuildTarget)
            {
            case BundleBuildTarget.Android:
                buildTarget = BuildTarget.Android;
                break;

            case BundleBuildTarget.iOS:
                buildTarget = BuildTarget.iOS;
                break;

            case BundleBuildTarget.Windows:
                buildTarget = BuildTarget.StandaloneWindows;
                break;
            }

            createAssetBundle(buildPath, buildTarget, settings);
            createAssetsInfo(buildPath);
        }