コード例 #1
0
        public string BundlizeAssets(string groupkey, List <InternalAssetData> sources, string recommendedBundleOutputDir, bool isRun)
        {
            var invalids = new List <string>();

            foreach (var source in sources)
            {
                if (string.IsNullOrEmpty(source.importedPath))
                {
                    invalids.Add(source.pathUnderSourceBase);
                }
            }
            if (invalids.Any())
            {
                throw new Exception("bundlizer:" + string.Join(", ", invalids.ToArray()) + " is not imported yet, should import before bundlize.");
            }

            var bundleName = bundleNameTemplate;

            /*
             *      if contains KEYWORD_WILDCARD, use group identifier to bundlize name.
             */
            if (bundleNameTemplate.Contains(AssetBundleGraphSettings.KEYWORD_WILDCARD))
            {
                var templateHead = bundleNameTemplate.Split(AssetBundleGraphSettings.KEYWORD_WILDCARD)[0];
                var templateTail = bundleNameTemplate.Split(AssetBundleGraphSettings.KEYWORD_WILDCARD)[1];

                bundleName = (templateHead + groupkey + templateTail + "." + GraphStackController.Platform_Dot_Package()).ToLower();
            }

            var bundlePath = FileController.PathCombine(recommendedBundleOutputDir, bundleName);

            foreach (var source in sources)
            {
                // if already bundled in this running, avoid changing that name.
                if (source.isBundled)
                {
                    continue;
                }

                if (isRun)
                {
                    if (GraphStackController.IsMetaFile(source.importedPath))
                    {
                        continue;
                    }
                    var assetImporter = AssetImporter.GetAtPath(source.importedPath);
                    if (assetImporter == null)
                    {
                        continue;
                    }
                    assetImporter.assetBundleName = bundleName;
                }

                // set as this resource is already bundled.
                source.isBundled = true;
            }

            return(bundlePath);
        }