CreateAssetWithImportPath() public static méthode

public static CreateAssetWithImportPath ( string importFrom ) : Asset
importFrom string
Résultat Asset
Exemple #1
0
        public void Setup(string nodeName, string nodeId, string unused_connectionIdToNextNode, Dictionary <string, List <Asset> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            try {
                ValidateBundleNameTemplate(
                    bundleNameTemplate,
                    () => {
                    throw new NodeException(nodeName + ":Bundle Name Template is empty.", nodeId);
                }
                    );

                foreach (var name in variants.Values)
                {
                    ValidateVariantName(name, variants.Values.ToList(),
                                        () => {
                        throw new NodeException(nodeName + ":Variant is empty.", nodeId);
                    },
                                        () => {
                        throw new NodeException(nodeName + ":Variant name cannot contain whitespace \"" + name + "\".", nodeId);
                    },
                                        () => {
                        throw new NodeException(nodeName + ":Variant name already exists \"" + name + "\".", nodeId);
                    });
                }
            } catch (NodeException e) {
                AssetBundleGraphEditorWindow.AddNodeException(e);
                return;
            }

            var recommendedBundleOutputDir = FileUtility.PathCombine(AssetBundleGraphSettings.BUNDLIZER_CACHE_PLACE, nodeId, SystemDataUtility.GetCurrentPlatformKey());

            var outputDict = new Dictionary <string, List <Asset> >();

            foreach (var groupKey in groupedSources.Keys)
            {
                var inputSources = groupedSources[groupKey];

                var reservedBundlePath = BundlizeAssets(nodeName, groupKey, inputSources, recommendedBundleOutputDir, false);
                if (string.IsNullOrEmpty(reservedBundlePath))
                {
                    continue;
                }

                var outputSources = new List <Asset>();

                var newAssetData = Asset.CreateAssetWithImportPath(reservedBundlePath);

                outputSources.Add(newAssetData);

                outputDict[groupKey] = outputSources;
            }

            if (assetsOutputConnectionId != AssetBundleGraphSettings.BUNDLIZER_FAKE_CONNECTION_ID)
            {
                Output(nodeId, assetsOutputConnectionId, outputDict, new List <string>());
            }
        }
        public void Setup(BuildTarget target,
                          NodeData node,
                          ConnectionPointData inputPoint,
                          ConnectionData connectionToOutput,
                          Dictionary <string, List <Asset> > inputGroupAssets,
                          List <string> alreadyCached,
                          Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            var outputDict = new Dictionary <string, List <Asset> >();

            outputDict[key] = new List <Asset>();

            var bundleNames = inputGroupAssets.Keys.ToList();

            var bundleVariants = new Dictionary <string, List <string> >();

            // get all variant name for bundles
            foreach (var name in bundleNames)
            {
                bundleVariants[name] = new List <string>();
                var assets = inputGroupAssets[name];
                foreach (var a in assets)
                {
                    var variantName = a.variantName;
                    if (!bundleVariants[name].Contains(variantName))
                    {
                        bundleVariants[name].Add(variantName);
                    }
                }
            }

            // add manifest file
            var manifestName = BuildTargetUtility.TargetToAssetBundlePlatformName(target);

            bundleNames.Add(manifestName);
            bundleVariants[manifestName] = new List <string>()
            {
                ""
            };

            var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node);

            foreach (var name in bundleNames)
            {
                foreach (var v in bundleVariants[name])
                {
                    string bundleName = (string.IsNullOrEmpty(v))? name : name + "." + v;
                    Asset  bundle     = Asset.CreateAssetWithImportPath(FileUtility.PathCombine(bundleOutputDir, bundleName));
                    Asset  manifest   = Asset.CreateAssetWithImportPath(FileUtility.PathCombine(bundleOutputDir, bundleName + AssetBundleGraphSettings.MANIFEST_FOOTER));
                    outputDict[key].Add(bundle);
                    outputDict[key].Add(manifest);
                }
            }

            Output(connectionToOutput, outputDict, new List <string>());
        }
Exemple #3
0
        public void Setup(BuildTarget target,
                          NodeData node,
                          ConnectionPointData inputPoint,
                          ConnectionData connectionToOutput,
                          Dictionary <string, List <Asset> > inputGroupAssets,
                          List <string> alreadyCached,
                          Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            ValidatePrefabBuilder(node, target, inputGroupAssets,
                                  () => {
                throw new NodeException(node.Name + " :PrefabBuilder is not configured. Please configure from Inspector.", node.Id);
            },
                                  () => {
                throw new NodeException(node.Name + " :Failed to create PrefabBuilder from settings. Please fix settings from Inspector.", node.Id);
            },
                                  (string groupKey) => {
                throw new NodeException(string.Format("{0} :Can not create prefab with incoming assets for group {1}.", node.Name, groupKey), node.Id);
            },
                                  (Asset badAsset) => {
                throw new NodeException(string.Format("{0} :Can not import incoming asset {1}.", node.Name, badAsset.fileNameAndExtension), node.Id);
            }
                                  );

            var builder = PrefabBuilderUtility.CreatePrefabBuilder(node, target);

            UnityEngine.Assertions.Assert.IsNotNull(builder);

            var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node);
            Dictionary <string, List <Asset> > output = new Dictionary <string, List <Asset> >();

            foreach (var key in inputGroupAssets.Keys)
            {
                var prefabFileName = builder.CanCreatePrefab(key, LoadAllAssets(inputGroupAssets[key]));
                output[key] = new List <Asset> ()
                {
                    Asset.CreateAssetWithImportPath(FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab"))
                };
            }

            Output(connectionToOutput, output, null);
        }
Exemple #4
0
        public void Run(BuildTarget target,
                        NodeData node,
                        ConnectionPointData inputPoint,
                        ConnectionData connectionToOutput,
                        Dictionary <string, List <Asset> > inputGroupAssets,
                        List <string> alreadyCached,
                        Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            var builder = PrefabBuilderUtility.CreatePrefabBuilder(node, target);

            UnityEngine.Assertions.Assert.IsNotNull(builder);

            var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node);
            Dictionary <string, List <Asset> > output = new Dictionary <string, List <Asset> >();

            foreach (var key in inputGroupAssets.Keys)
            {
                var allAssets              = LoadAllAssets(inputGroupAssets[key]);
                var prefabFileName         = builder.CanCreatePrefab(key, allAssets);
                UnityEngine.GameObject obj = builder.CreatePrefab(key, allAssets);
                if (obj == null)
                {
                    throw new AssetBundleGraphException(string.Format("{0} :PrefabBuilder {1} returned null in CreatePrefab() [groupKey:{2}]",
                                                                      node.Name, builder.GetType().FullName, key));
                }

                var prefabSavePath = FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab");
                PrefabUtility.CreatePrefab(prefabSavePath, obj, ReplacePrefabOptions.Default);

                output[key] = new List <Asset> ()
                {
                    Asset.CreateAssetWithImportPath(prefabSavePath)
                };
                GameObject.DestroyImmediate(obj);
            }

            Output(connectionToOutput, output, null);
        }
Exemple #5
0
        public void Run(string nodeName, string nodeId, string unused_connectionIdToNextNode, Dictionary <string, List <Asset> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            ValidateBundleNameTemplate(
                bundleNameTemplate,
                () => {
                throw new AssetBundleGraphBuildException(nodeName + ": Bundle Name Template is empty.");
            }
                );

            var recommendedBundleOutputDir = FileUtility.PathCombine(AssetBundleGraphSettings.BUNDLIZER_CACHE_PLACE, nodeId, SystemDataUtility.GetCurrentPlatformKey());

            var outputDict = new Dictionary <string, List <Asset> >();

            foreach (var groupKey in groupedSources.Keys)
            {
                var inputSources = groupedSources[groupKey];

                var reservedBundlePath = BundlizeAssets(nodeName, groupKey, inputSources, recommendedBundleOutputDir, true);
                if (string.IsNullOrEmpty(reservedBundlePath))
                {
                    continue;
                }

                var outputSources = new List <Asset>();

                var newAssetData = Asset.CreateAssetWithImportPath(reservedBundlePath);

                outputSources.Add(newAssetData);

                outputDict[groupKey] = outputSources;
            }

            if (assetsOutputConnectionId != AssetBundleGraphSettings.BUNDLIZER_FAKE_CONNECTION_ID)
            {
                Output(nodeId, assetsOutputConnectionId, outputDict, new List <string>());
            }
        }
Exemple #6
0
        public void Run(BuildTarget target,
                        NodeData node,
                        ConnectionPointData inputPoint,
                        ConnectionData connectionToOutput,
                        Dictionary <string, List <Asset> > inputGroupAssets,
                        List <string> alreadyCached,
                        Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node);

            var bundleNames    = inputGroupAssets.Keys.ToList();
            var bundleVariants = new Dictionary <string, List <string> >();

            // get all variant name for bundles
            foreach (var name in bundleNames)
            {
                bundleVariants[name] = new List <string>();
                var assets = inputGroupAssets[name];
                foreach (var a in assets)
                {
                    var variantName = a.variantName;
                    if (!bundleVariants[name].Contains(variantName))
                    {
                        bundleVariants[name].Add(variantName);
                    }
                }
            }

            int validNames = 0;

            foreach (var name in bundleNames)
            {
                var assets = inputGroupAssets[name];
                // we do not build bundle without any asset
                if (assets.Count > 0)
                {
                    validNames += bundleVariants[name].Count;
                }
            }

            AssetBundleBuild[] bundleBuild = new AssetBundleBuild[validNames];

            int bbIndex = 0;

            foreach (var name in bundleNames)
            {
                foreach (var v in bundleVariants[name])
                {
                    var bundleName = name;
                    var assets     = inputGroupAssets[name];

                    if (assets.Count <= 0)
                    {
                        continue;
                    }

                    bundleBuild[bbIndex].assetBundleName    = bundleName;
                    bundleBuild[bbIndex].assetBundleVariant = v;
                    bundleBuild[bbIndex].assetNames         = assets.Where(x => x.variantName == v).Select(x => x.importFrom).ToArray();
                    ++bbIndex;
                }
            }


            BuildPipeline.BuildAssetBundles(bundleOutputDir, bundleBuild, (BuildAssetBundleOptions)node.BundleBuilderBundleOptions[target], target);


            var output = new Dictionary <string, List <Asset> >();

            output[key] = new List <Asset>();

            var generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir);

            // add manifest file
            bundleNames.Add(BuildTargetUtility.TargetToAssetBundlePlatformName(target));
            foreach (var path in generatedFiles)
            {
                var fileName = Path.GetFileName(path);
                if (IsFileIntendedItem(fileName, bundleNames))
                {
                    output[key].Add(Asset.CreateAssetWithImportPath(path));
                }
                else
                {
                    Debug.LogWarning(node.Name + ":Irrelevant file found in assetbundle cache folder:" + fileName);
                }
            }

            Output(connectionToOutput, output, alreadyCached);
        }
        public void Run(string nodeName, string connectionIdToNextNode, string labelToNext, Dictionary <string, List <Asset> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            var recommendedBundleOutputDirSource = FileUtility.PathCombine(AssetBundleGraphSettings.BUNDLEBUILDER_CACHE_PLACE, connectionIdToNextNode);
            var recommendedBundleOutputDir       = FileUtility.PathCombine(recommendedBundleOutputDirSource, SystemDataUtility.GetCurrentPlatformKey());

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


            /*
             *      merge multi group into ["0"] group.
             */
            var intendedAssetNames = new List <string>();

            foreach (var groupKey in groupedSources.Keys)
            {
                var internalAssetsOfCurrentGroup = groupedSources[groupKey];
                foreach (var internalAsset in internalAssetsOfCurrentGroup)
                {
                    intendedAssetNames.Add(internalAsset.fileNameAndExtension);
                    intendedAssetNames.Add(internalAsset.fileNameAndExtension + AssetBundleGraphSettings.MANIFEST_FOOTER);
                }
            }



            /*
             *      platform's bundle & manifest.
             *      e.g. iOS & iOS.manifest.
             */
            var currentPlatform_Package_BundleFile         = SystemDataUtility.GetCurrentPlatformKey();
            var currentPlatform_Package_BundleFileManifest = currentPlatform_Package_BundleFile + AssetBundleGraphSettings.MANIFEST_FOOTER;

            intendedAssetNames.Add(currentPlatform_Package_BundleFile);
            intendedAssetNames.Add(currentPlatform_Package_BundleFileManifest);

            /*
             *      delete not intended assets.
             */
            foreach (var alreadyCachedPath in alreadyCached)
            {
                var cachedFileName = Path.GetFileName(alreadyCachedPath);
                if (intendedAssetNames.Contains(cachedFileName))
                {
                    continue;
                }
                File.Delete(alreadyCachedPath);
            }

            var assetBundleOptions = BuildAssetBundleOptions.None;

            foreach (var enabled in bundleOptions)
            {
                switch (enabled)
                {
                case "Uncompressed AssetBundle": {
                    assetBundleOptions = assetBundleOptions | BuildAssetBundleOptions.UncompressedAssetBundle;
                    break;
                }

                case "Disable Write TypeTree": {
                    assetBundleOptions = assetBundleOptions | BuildAssetBundleOptions.DisableWriteTypeTree;
                    break;
                }

                case "Deterministic AssetBundle": {
                    assetBundleOptions = assetBundleOptions | BuildAssetBundleOptions.DeterministicAssetBundle;
                    break;
                }

                case "Force Rebuild AssetBundle": {
                    assetBundleOptions = assetBundleOptions | BuildAssetBundleOptions.ForceRebuildAssetBundle;
                    break;
                }

                case "Ignore TypeTree Changes": {
                    assetBundleOptions = assetBundleOptions | BuildAssetBundleOptions.IgnoreTypeTreeChanges;
                    break;
                }

                case "Append Hash To AssetBundle Name": {
                    assetBundleOptions = assetBundleOptions | BuildAssetBundleOptions.AppendHashToAssetBundleName;
                    break;
                }

                                #if UNITY_5_3
                case "ChunkBased Compression": {
                    assetBundleOptions = assetBundleOptions | BuildAssetBundleOptions.ChunkBasedCompression;
                    break;
                }
                                #endif
                }
            }

            BuildPipeline.BuildAssetBundles(recommendedBundleOutputDir, assetBundleOptions, EditorUserBuildSettings.activeBuildTarget);


            /*
             *      check assumed bundlized resources and actual generated assetbundles.
             *
             *      "assuned bundlized resources info from bundlizer" are contained by "actual bundlized resources".
             */
            var outputDict    = new Dictionary <string, List <Asset> >();
            var outputSources = new List <Asset>();

            var newAssetPaths             = new List <string>();
            var generatedAssetBundlePaths = FileUtility.FilePathsInFolder(recommendedBundleOutputDir);
            foreach (var newAssetPath in generatedAssetBundlePaths)
            {
                newAssetPaths.Add(newAssetPath);
                var newAssetData = Asset.CreateAssetWithImportPath(newAssetPath);
                outputSources.Add(newAssetData);
            }

            // compare, erase & notice.
            var containedAssetBundles = new List <string>();

            // collect intended output.
            foreach (var generatedAssetPath in newAssetPaths)
            {
                var generatedAssetName = Path.GetFileName(generatedAssetPath);

                // collect intended assetBundle & assetBundleManifest file.
                foreach (var bundledName in intendedAssetNames)
                {
                    if (generatedAssetName == bundledName)
                    {
                        containedAssetBundles.Add(generatedAssetPath);
                        continue;
                    }

                    var bundleManifestName = bundledName + AssetBundleGraphSettings.MANIFEST_FOOTER;
                    if (generatedAssetName == bundleManifestName)
                    {
                        containedAssetBundles.Add(generatedAssetPath);
                        continue;
                    }
                }
            }

            var diffs = newAssetPaths.Except(containedAssetBundles);
            foreach (var diff in diffs)
            {
                Debug.LogWarning(nodeName + ": AssetBundle " + diff + " is not intended to build. Check if unnecessary importer or prefabricator exists in the graph.");
            }

            outputDict["0"] = outputSources;

            var usedCache = new List <string>(alreadyCached);
            Output(connectionIdToNextNode, labelToNext, outputDict, usedCache);
        }