AssetBundleGraph.Asset.DuplicateAssetWithNewStatus C# (CSharp) Method

DuplicateAssetWithNewStatus() public static method

public static DuplicateAssetWithNewStatus ( Asset asset, bool isNew, bool isBundled ) : Asset
asset Asset
isNew bool
isBundled bool
return Asset
        public static Asset DuplicateAssetWithNewStatus(Asset asset, bool isNew, bool isBundled)
        {
            return new Asset(
                guid:asset.guid,
                assetDatabaseId:asset.assetDatabaseId,
                absoluteAssetPath:asset.absoluteAssetPath,
                importFrom:asset.importFrom,
                exportTo:asset.exportTo,
                assetType:asset.assetType,
                isNew:isNew,
                isBundled:isBundled,
                variantName:asset.variantName
            );
        }

Usage Example

Example #1
0
        public string BundlizeAssets(string nodeName, string groupkey, List <Asset> sources, string recommendedBundleOutputDir, bool isRun)
        {
            var invalids = new List <string>();

            foreach (var source in sources)
            {
                if (string.IsNullOrEmpty(source.importFrom))
                {
                    invalids.Add(source.absoluteAssetPath);
                }
            }
            if (invalids.Any())
            {
                throw new AssetBundleGraphBuildException(nodeName + ": Invalid files to bundle. Following files need to be imported before bundlize: " + string.Join(", ", invalids.ToArray()));
            }

            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 + "." + SystemDataUtility.GetCurrentPlatformShortName()).ToLower();
            }

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

            for (var i = 0; i < sources.Count; i++)
            {
                var source = sources[i];

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

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

                // set as this resource is already bundled.
                sources[i] = Asset.DuplicateAssetWithNewStatus(sources[i], sources[i].isNew, true);
            }

            return(bundlePath);
        }