private void RemoveBundleSettings(string nodePath)
        {
            EditorUtility.DisplayProgressBar("AssetGraph BundleBuilder unbundlize resources...", nodePath, 0);
            var filePathsInFolder = FileController.FilePathsInFolder(nodePath);

            foreach (var filePath in filePathsInFolder)
            {
                if (GraphStackController.IsMetaFile(filePath))
                {
                    continue;
                }
                var assetImporter = AssetImporter.GetAtPath(filePath);
                assetImporter.assetBundleName = string.Empty;
            }
            EditorUtility.ClearProgressBar();
        }
Beispiel #2
0
        public string BundlizeAssets(string package, 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(AssetGraphSettings.KEYWORD_WILDCARD))
            {
                var templateHead = bundleNameTemplate.Split(AssetGraphSettings.KEYWORD_WILDCARD)[0];
                var templateTail = bundleNameTemplate.Split(AssetGraphSettings.KEYWORD_WILDCARD)[1];

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

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

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

            return(bundlePath);
        }
        private void RemoveOtherPlatformAndPackageBundleSettings(List <string> nodeIds, string package)
        {
            if (!Directory.Exists(AssetGraphSettings.APPLICATIONDATAPATH_CACHE_PATH))
            {
                return;
            }

            /*
             *      get all cache folder of node from cache path.
             */
            var cachedNodeKindFolderPaths = FileController.FolderPathsInFolder(AssetGraphSettings.APPLICATIONDATAPATH_CACHE_PATH);

            foreach (var cachedNodeKindFolderPath in cachedNodeKindFolderPaths)
            {
                var nodeIdFolderPaths = FileController.FolderPathsInFolder(cachedNodeKindFolderPath);
                foreach (var nodeIdFolderPath in nodeIdFolderPaths)
                {
                    var nodeIdFromFolder = nodeIdFolderPath.Split(AssetGraphSettings.UNITY_FOLDER_SEPARATOR).Last();

                    // remove all bundle settings from unrelated nodes.
                    if (!nodeIds.Contains(nodeIdFromFolder))
                    {
                        RemoveBundleSettings(nodeIdFolderPath);
                        continue;
                    }

                    // related nodes, contains platform_package folder.

                    // remove all bundle settings from unrelated platforms + packages.
                    var platformFolderPaths = FileController.FolderPathsInFolder(nodeIdFolderPath);
                    foreach (var platformFolderPath in platformFolderPaths)
                    {
                        var platformNameFromFolder = platformFolderPath.Split(AssetGraphSettings.UNITY_FOLDER_SEPARATOR).Last();

                        if (platformNameFromFolder == GraphStackController.Current_Platform_Package_Folder(package))
                        {
                            continue;
                        }

                        RemoveBundleSettings(platformFolderPath);
                    }
                }
            }
        }
Beispiel #4
0
        public void Run(string nodeId, string labelToNext, string package, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            ValidateBundleNameTemplate(
                bundleNameTemplate,
                () => {
                throw new Exception("no Bundle Name Template set.");
            }
                );

            var recommendedBundleOutputDir = FileController.PathCombine(AssetGraphSettings.BUNDLIZER_CACHE_PLACE, nodeId, GraphStackController.Current_Platform_Package_Folder(package));

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

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

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

                var outputSources = new List <InternalAssetData>();

                var newAssetData = InternalAssetData.InternalAssetDataGeneratedByBundlizer(reservedBundlePath);

                outputSources.Add(newAssetData);

                outputDict[groupKey] = outputSources;
            }

            Output(nodeId, labelToNext, outputDict, new List <string>());

            /*
             *      generate additional output:
             *      output bundle resources for next node, for generate another AssetBundles with dependency.
             */
            if (outputResource)
            {
                Output(nodeId, AssetGraphSettings.BUNDLIZER_RESOURCES_OUTPUTPOINT_LABEL, groupedSources, new List <string>());
            }
        }
Beispiel #5
0
        public void Run(string nodeId, string labelToNext, string package, Dictionary <string, List <InternalAssetData> > unused, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            ValidateLoadPath(
                loadFilePath,
                loadFilePath,
                () => {
                throw new Exception("load path is empty.");
            },
                () => {
                throw new Exception("directory not found:" + loadFilePath);
            }
                );

            var outputSource = new List <InternalAssetData>();

            try {
                var targetFilePaths = FileController.FilePathsInFolder(loadFilePath);

                foreach (var targetFilePath in targetFilePaths)
                {
                    outputSource.Add(
                        InternalAssetData.InternalAssetDataByLoader(
                            targetFilePath,
                            loadFilePath
                            )
                        );
                }

                var outputDir = new Dictionary <string, List <InternalAssetData> > {
                    { "0", outputSource }
                };

                Output(nodeId, labelToNext, outputDir, new List <string>());
            } catch (Exception e) {
                Debug.LogError("Loader error:" + e);
            }
        }
Beispiel #6
0
        public void Setup(string nodeId, string labelToNext, string package, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            var outputDict = new Dictionary <string, List <InternalAssetData> >();


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

                var assumedImportedAssetDatas = new List <InternalAssetData>();

                foreach (var inputData in inputSources)
                {
                    var assumedImportedBasePath = inputData.absoluteSourcePath.Replace(inputData.sourceBasePath, AssetGraphSettings.IMPORTER_CACHE_PLACE);
                    var assumedImportedPath     = FileController.PathCombine(assumedImportedBasePath, nodeId);

                    var assumedType = AssumeTypeFromExtension();

                    var newData = InternalAssetData.InternalAssetDataByImporter(
                        inputData.traceId,
                        inputData.absoluteSourcePath,
                        inputData.sourceBasePath,
                        inputData.fileNameAndExtension,
                        inputData.pathUnderSourceBase,
                        assumedImportedPath,
                        null,
                        assumedType
                        );
                    assumedImportedAssetDatas.Add(newData);
                }

                outputDict[groupKey] = assumedImportedAssetDatas;
            }

            Output(nodeId, labelToNext, outputDict, new List <string>());
        }
        public void Run(string nodeId, string labelToNext, string package, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            RemoveOtherPlatformAndPackageBundleSettings(relatedNodeIds, package);

            var recommendedBundleOutputDirSource = FileController.PathCombine(AssetGraphSettings.BUNDLEBUILDER_CACHE_PLACE, nodeId);
            var recommendedBundleOutputDir       = FileController.PathCombine(recommendedBundleOutputDirSource, GraphStackController.Current_Platform_Package_Folder(package));

            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 + AssetGraphSettings.MANIFEST_FOOTER);
                }
            }



            /*
             *      platform's bundle & manifest.
             *      e.g. iOS & iOS.manifest.
             */
            var currentPlatform_Package_BundleFile         = GraphStackController.Current_Platform_Package_Folder(package);
            var currentPlatform_Package_BundleFileManifest = currentPlatform_Package_BundleFile + AssetGraphSettings.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;
                }
                }
            }

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


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

            var newAssetPaths             = new List <string>();
            var generatedAssetBundlePaths = FileController.FilePathsInFolder(recommendedBundleOutputDir);

            foreach (var newAssetPath in generatedAssetBundlePaths)
            {
                newAssetPaths.Add(newAssetPath);
                var newAssetData = InternalAssetData.InternalAssetDataGeneratedByBundleBuilder(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 + AssetGraphSettings.MANIFEST_FOOTER;
                    if (generatedAssetName == bundleManifestName)
                    {
                        containedAssetBundles.Add(generatedAssetPath);
                        continue;
                    }
                }
            }

            var diffs = newAssetPaths.Except(containedAssetBundles);

            foreach (var diff in diffs)
            {
                Debug.LogWarning("bundleBuilder:AssetBundle:" + diff + " is not intended bundle. please check if unnecessary importer or prefabricator node is exists in graph.");
            }

            outputDict["0"] = outputSources;

            var usedCache = new List <string>(alreadyCached);

            Output(nodeId, labelToNext, outputDict, usedCache);
        }
Beispiel #8
0
 public static string GetPathWithBasePath(string localPathWithoutBasePath, string basePath)
 {
     return(FileController.PathCombine(basePath, localPathWithoutBasePath));
 }
Beispiel #9
0
        public void Setup(string nodeId, string labelToNext, string unusedPackageInfo, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            var outputDict = new Dictionary <string, List <InternalAssetData> >();

            var first = true;

            // shrink group to 1 group.
            if (1 < groupedSources.Keys.Count)
            {
                Debug.LogWarning("importer shrinking group to \"" + groupedSources.Keys.ToList()[0] + "\" forcely.");
            }

            var inputSources = new List <InternalAssetData>();

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

            var assumedImportedAssetDatas = new List <InternalAssetData>();


            var samplingDirectoryPath = FileController.PathCombine(AssetGraphSettings.IMPORTER_SAMPLING_PLACE, nodeId, importerPackage);

            ValidateImportSample(samplingDirectoryPath,
                                 (string noSampleFolder) => {
                // do nothing. keep importing new asset for sampling.
            },
                                 (string noSampleFile) => {
                // do nothing. keep importing new asset for sampling.
            },
                                 (string samplePath) => {
                first = false;
            },
                                 (string tooManysample) => {
                first = false;
            }
                                 );

            var alreadyImported = new List <string>();
            var ignoredResource = new List <string>();

            foreach (var inputSource in inputSources)
            {
                if (string.IsNullOrEmpty(inputSource.absoluteSourcePath))
                {
                    if (!string.IsNullOrEmpty(inputSource.importedPath))
                    {
                        alreadyImported.Add(inputSource.importedPath);
                        continue;
                    }

                    ignoredResource.Add(inputSource.fileNameAndExtension);
                    continue;
                }

                var assumedImportedBasePath = inputSource.absoluteSourcePath.Replace(inputSource.sourceBasePath, AssetGraphSettings.IMPORTER_CACHE_PLACE);
                var assumedImportedPath     = FileController.PathCombine(assumedImportedBasePath, nodeId);

                var assumedType = AssumeTypeFromExtension();

                var newData = InternalAssetData.InternalAssetDataByImporter(
                    inputSource.traceId,
                    inputSource.absoluteSourcePath,
                    inputSource.sourceBasePath,
                    inputSource.fileNameAndExtension,
                    inputSource.pathUnderSourceBase,
                    assumedImportedPath,
                    null,
                    assumedType
                    );
                assumedImportedAssetDatas.Add(newData);

                if (first)
                {
                    if (!Directory.Exists(samplingDirectoryPath))
                    {
                        Directory.CreateDirectory(samplingDirectoryPath);
                    }

                    var absoluteFilePath = inputSource.absoluteSourcePath;
                    var targetFilePath   = FileController.PathCombine(samplingDirectoryPath, inputSource.fileNameAndExtension);

                    EditorUtility.DisplayProgressBar("AssetGraph Importer generating ImporterSetting...", targetFilePath, 0);
                    FileController.CopyFileFromGlobalToLocal(absoluteFilePath, targetFilePath);
                    first = false;
                    AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
                    EditorUtility.ClearProgressBar();
                }


                if (alreadyImported.Any())
                {
                    Debug.LogError("importer:" + string.Join(", ", alreadyImported.ToArray()) + " are already imported.");
                }
                if (ignoredResource.Any())
                {
                    Debug.LogError("importer:" + string.Join(", ", ignoredResource.ToArray()) + " are ignored.");
                }

                outputDict[groupedSources.Keys.ToList()[0]] = assumedImportedAssetDatas;
            }

            Output(nodeId, labelToNext, outputDict, new List <string>());
        }
Beispiel #10
0
        public void Run(string nodeId, string labelToNext, string package, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            var usedCache = new List <string>();


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


            // caution if import setting file is exists already or not.
            var samplingDirectoryPath = FileController.PathCombine(AssetGraphSettings.IMPORTER_SAMPLING_PLACE, nodeId, importerPackage);

            var sampleAssetPath = string.Empty;

            ValidateImportSample(samplingDirectoryPath,
                                 (string noSampleFolder) => {
                Debug.LogWarning("importer:" + noSampleFolder);
            },
                                 (string noSampleFile) => {
                throw new Exception("importer error:" + noSampleFile);
            },
                                 (string samplePath) => {
                Debug.Log("using import setting:" + samplePath);
                sampleAssetPath = samplePath;
            },
                                 (string tooManysample) => {
                throw new Exception("importer error:" + tooManysample);
            }
                                 );


            // ready.
            AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);


            // construct import path from package info.
            // importer's package is complicated.
            // 1. importer uses their own package informatiom.
            // 2. but imported assets are located at platform-package combined path.(same as other node.)
            // this is comes from the spec: importer node contains platform settings in themselves.
            var nodeDirectoryPath = FileController.PathCombine(AssetGraphSettings.IMPORTER_CACHE_PLACE, nodeId, GraphStackController.Current_Platform_Package_Folder(package));

            // shrink group to 1 group.
            if (1 < groupedSources.Keys.Count)
            {
                Debug.LogWarning("importer shrinking group to \"" + groupedSources.Keys.ToList()[0] + "\" forcely.");
            }

            var inputSources = new List <InternalAssetData>();

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

            var oldGeneratedRecord          = GraphStackController.LoadImporterRecord(nodeId, package);
            var oldRemainGeneratedAssetDict = new Dictionary <string, List <string> >();
            var newGeneratedAssetDict       = new Dictionary <string, List <string> >();

            /**
             *      delete unnecessary cache from node.
             */
            {
                var latestInputImportAssumePaths = inputSources.Select(latestImportAsset => FileController.PathCombine(nodeDirectoryPath, latestImportAsset.pathUnderSourceBase)).ToList();
                var oldGeneratedRecordPaths      = oldGeneratedRecord.Keys.ToList();

                var notExistInLatestButRecordedPaths = oldGeneratedRecordPaths.Except(latestInputImportAssumePaths);
                foreach (var shouldDeleteCachePath in notExistInLatestButRecordedPaths)
                {
                    var shouldDetelePaths = oldGeneratedRecord[shouldDeleteCachePath];
                    foreach (var deletingCachePath in shouldDetelePaths)
                    {
                        // unbundlize unused imported cached asset.
                        var assetImporter = AssetImporter.GetAtPath(deletingCachePath);
                        assetImporter.assetBundleName = string.Empty;

                        FileController.DeleteFileThenDeleteFolderIfEmpty(deletingCachePath);
                    }
                }
            }

            /*
             *      copy all sources from outside to inside of Unity.
             *      apply importSetting to new file.
             */
            {
                var samplingAssetImporter = AssetImporter.GetAtPath(sampleAssetPath);
                InternalSamplingImportAdopter.Attach(samplingAssetImporter);
                {
                    var alreadyImported = new List <string>();
                    var ignoredResource = new List <string>();

                    foreach (var inputSource in inputSources)
                    {
                        // non absoluteSoucePath -> not imported. generated one. or else.
                        if (string.IsNullOrEmpty(inputSource.absoluteSourcePath))
                        {
                            if (!string.IsNullOrEmpty(inputSource.importedPath))
                            {
                                alreadyImported.Add(inputSource.importedPath);
                                continue;
                            }

                            // already imported. should ignore.
                            ignoredResource.Add(inputSource.fileNameAndExtension);
                            continue;
                        }

                        // construct imported path.
                        var pathUnderSourceBase = inputSource.pathUnderSourceBase;
                        var targetFilePath      = FileController.PathCombine(nodeDirectoryPath, pathUnderSourceBase);

                        // skip if cached.
                        if (GraphStackController.IsCached(inputSource, alreadyCached, targetFilePath))
                        {
                            var alreadyImportedPathAndGeneratedPaths = oldGeneratedRecord[targetFilePath];

                            // continue using generated info.
                            oldRemainGeneratedAssetDict[targetFilePath] = oldGeneratedRecord[targetFilePath];

                            usedCache.AddRange(alreadyImportedPathAndGeneratedPaths);
                            continue;
                        }

                        var before = FileController.FilePathsOfFile(targetFilePath);

                        /*
                         *      copy files into local.
                         */
                        var absoluteFilePath = inputSource.absoluteSourcePath;
                        FileController.CopyFileFromGlobalToLocal(absoluteFilePath, targetFilePath);

                        AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);

                        var after = FileController.FilePathsOfFile(targetFilePath);

                        /*
                         *      record relationship of imported file & generated files.
                         */
                        var diff = after.Except(before).Where(path => !GraphStackController.IsMetaFile(path)).ToList();
                        newGeneratedAssetDict[targetFilePath] = diff;
                    }

                    if (alreadyImported.Any())
                    {
                        Debug.LogError("importer:" + string.Join(", ", alreadyImported.ToArray()) + " are already imported.");
                    }
                    if (ignoredResource.Any())
                    {
                        Debug.LogError("importer:" + string.Join(", ", ignoredResource.ToArray()) + " are ignored.");
                    }
                }
                InternalSamplingImportAdopter.Detach();
            }


            /*
             *      input sequence is over.
             */

            // get files, which are imported or cached assets.
            var localFilePathsAfterImport = FileController.FilePathsInFolder(nodeDirectoryPath);

            // modify to local path.
            var localFilePathsWithoutNodeDirectoryPath = localFilePathsAfterImport.Select(path => InternalAssetData.GetPathWithoutBasePath(path, nodeDirectoryPath)).ToList();


            var outputSources = new List <InternalAssetData>();

            /*
             *      treat all assets inside node.
             */
            foreach (var newAssetPath in localFilePathsWithoutNodeDirectoryPath)
            {
                var basePathWithNewAssetPath = InternalAssetData.GetPathWithBasePath(newAssetPath, nodeDirectoryPath);

                if (usedCache.Contains(basePathWithNewAssetPath))
                {
                    // already cached, not new.
                    var newInternalAssetData = InternalAssetData.InternalAssetDataGeneratedByImporterOrPrefabricator(
                        basePathWithNewAssetPath,
                        AssetDatabase.AssetPathToGUID(basePathWithNewAssetPath),
                        AssetGraphInternalFunctions.GetAssetType(basePathWithNewAssetPath),
                        false
                        );
                    outputSources.Add(newInternalAssetData);
                }
                else
                {
                    // now cached. new resource.
                    var newInternalAssetData = InternalAssetData.InternalAssetDataGeneratedByImporterOrPrefabricator(
                        basePathWithNewAssetPath,
                        AssetDatabase.AssetPathToGUID(basePathWithNewAssetPath),
                        AssetGraphInternalFunctions.GetAssetType(basePathWithNewAssetPath),
                        true
                        );
                    outputSources.Add(newInternalAssetData);
                }
            }

            outputDict[groupedSources.Keys.ToList()[0]] = outputSources;


            /*
             *      merge old remains record & new generated record.
             */
            {
                var newAndOldGeneratedAssetDict = new Dictionary <string, List <string> >();

                foreach (var oldRemainGeneratedAssetPath in oldRemainGeneratedAssetDict.Keys)
                {
                    newAndOldGeneratedAssetDict[oldRemainGeneratedAssetPath] = oldRemainGeneratedAssetDict[oldRemainGeneratedAssetPath];
                }
                foreach (var newGeneratedAssetPath in newGeneratedAssetDict.Keys)
                {
                    newAndOldGeneratedAssetDict[newGeneratedAssetPath] = newGeneratedAssetDict[newGeneratedAssetPath];
                }
                GraphStackController.UpdateImporterRecord(nodeId, package, newAndOldGeneratedAssetDict);
            }

            Output(nodeId, labelToNext, outputDict, usedCache);
        }
Beispiel #11
0
        public void Run(string nodeId, string labelToNext, string package, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            var usedCache = new List <string>();

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

            var targetDirectoryPath = FileController.PathCombine(AssetGraphSettings.IMPORTER_CACHE_PLACE, nodeId, GraphStackController.Current_Platform_Package_Folder(package));

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

                /*
                 *      ready import resources from outside of Unity to inside of Unity.
                 */
                InternalImporter.Attach(this);
                foreach (var inputSource in inputSources)
                {
                    var absoluteFilePath    = inputSource.absoluteSourcePath;
                    var pathUnderSourceBase = inputSource.pathUnderSourceBase;

                    var targetFilePath = FileController.PathCombine(targetDirectoryPath, pathUnderSourceBase);

                    if (GraphStackController.IsCached(inputSource, alreadyCached, targetFilePath))
                    {
                        usedCache.Add(targetFilePath);
                        continue;
                    }

                    try {
                        /*
                         *      copy files into local.
                         */
                        FileController.CopyFileFromGlobalToLocal(absoluteFilePath, targetFilePath);
                    } catch (Exception e) {
                        Debug.LogError("Importer:" + this + " error:" + e);
                    }
                }
                AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
                InternalImporter.Detach();

                // get files, which are already assets.
                var localFilePathsAfterImport = FileController.FilePathsInFolder(targetDirectoryPath);

                var localFilePathsWithoutTargetDirectoryPath = localFilePathsAfterImport.Select(path => InternalAssetData.GetPathWithoutBasePath(path, targetDirectoryPath)).ToList();

                var outputSources = new List <InternalAssetData>();

                // generate matching between source and imported assets.
                foreach (var localFilePathWithoutTargetDirectoryPath in localFilePathsWithoutTargetDirectoryPath)
                {
                    foreach (var inputtedSourceCandidate in inputSources)
                    {
                        var pathsUnderSourceBase = inputtedSourceCandidate.pathUnderSourceBase;

                        if (localFilePathWithoutTargetDirectoryPath == pathsUnderSourceBase)
                        {
                            var localFilePathWithTargetDirectoryPath = InternalAssetData.GetPathWithBasePath(localFilePathWithoutTargetDirectoryPath, targetDirectoryPath);

                            var newInternalAssetData = InternalAssetData.InternalAssetDataByImporter(
                                inputtedSourceCandidate.traceId,
                                inputtedSourceCandidate.absoluteSourcePath,                          // /SOMEWHERE_OUTSIDE_OF_UNITY/~
                                inputtedSourceCandidate.sourceBasePath,                              // /SOMEWHERE_OUTSIDE_OF_UNITY/
                                inputtedSourceCandidate.fileNameAndExtension,                        // A.png
                                inputtedSourceCandidate.pathUnderSourceBase,                         // (Temp/Imported/nodeId/)~
                                localFilePathWithTargetDirectoryPath,                                // Assets/~
                                AssetDatabase.AssetPathToGUID(localFilePathWithTargetDirectoryPath),
                                AssetGraphInternalFunctions.GetAssetType(localFilePathWithTargetDirectoryPath)
                                );
                            outputSources.Add(newInternalAssetData);
                        }
                    }
                }

                /*
                 *      check if new Assets are generated, trace it.
                 */
                var assetPathsWhichAreAlreadyTraced = outputSources.Select(path => path.pathUnderSourceBase).ToList();
                var assetPathsWhichAreNotTraced     = localFilePathsWithoutTargetDirectoryPath.Except(assetPathsWhichAreAlreadyTraced);
                foreach (var newAssetPath in assetPathsWhichAreNotTraced)
                {
                    var basePathWithNewAssetPath = InternalAssetData.GetPathWithBasePath(newAssetPath, targetDirectoryPath);
                    if (alreadyCached.Contains(basePathWithNewAssetPath))
                    {
                        var newInternalAssetData = InternalAssetData.InternalAssetDataGeneratedByImporterOrPrefabricator(
                            basePathWithNewAssetPath,
                            AssetDatabase.AssetPathToGUID(basePathWithNewAssetPath),
                            AssetGraphInternalFunctions.GetAssetType(basePathWithNewAssetPath),
                            false
                            );
                        outputSources.Add(newInternalAssetData);
                    }
                    else
                    {
                        var newInternalAssetData = InternalAssetData.InternalAssetDataGeneratedByImporterOrPrefabricator(
                            basePathWithNewAssetPath,
                            AssetDatabase.AssetPathToGUID(basePathWithNewAssetPath),
                            AssetGraphInternalFunctions.GetAssetType(basePathWithNewAssetPath),
                            true
                            );
                        outputSources.Add(newInternalAssetData);
                    }
                }

                outputDict[groupKey] = outputSources;
            }

            Output(nodeId, labelToNext, outputDict, usedCache);
        }
Beispiel #12
0
        public void Run(string nodeId, string labelToNext, string package, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            var usedCache = new List <string>();

            var invalids = new List <string>();

            foreach (var sources in groupedSources.Values)
            {
                foreach (var source in sources)
                {
                    if (string.IsNullOrEmpty(source.importedPath))
                    {
                        invalids.Add(source.pathUnderSourceBase);
                    }
                }
            }

            if (invalids.Any())
            {
                throw new Exception("prefabricator:" + string.Join(", ", invalids.ToArray()) + " are not imported yet, should import before prefabricate.");
            }

            var recommendedPrefabOutputDirectoryPath = FileController.PathCombine(AssetGraphSettings.PREFABRICATOR_CACHE_PLACE, nodeId, GraphStackController.Current_Platform_Package_Folder(package));

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

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

                var recommendedPrefabPath = FileController.PathCombine(recommendedPrefabOutputDirectoryPath, groupKey);
                if (!recommendedPrefabPath.EndsWith(AssetGraphSettings.UNITY_FOLDER_SEPARATOR.ToString()))
                {
                    recommendedPrefabPath = recommendedPrefabPath + AssetGraphSettings.UNITY_FOLDER_SEPARATOR.ToString();
                }

                /*
                 *      ready input resource info for execute. not contains cache in this node.
                 */
                var assets = new List <AssetInfo>();
                foreach (var assetData in inputSources)
                {
                    var assetName = assetData.fileNameAndExtension;
                    var assetType = assetData.assetType;
                    var assetPath = assetData.importedPath;
                    var assetId   = assetData.assetId;
                    assets.Add(new AssetInfo(assetName, assetType, assetPath, assetId));
                }

                // collect generated prefab path.
                var generated     = new List <string>();
                var outputSources = new List <InternalAssetData>();

                Func <GameObject, string, bool, string> Prefabricate = (GameObject baseObject, string prefabName, bool forceGenerate) => {
                    var newPrefabOutputPath = Path.Combine(recommendedPrefabPath, prefabName);

                    if (forceGenerate || !GraphStackController.IsCachedForEachSource(inputSources, alreadyCached, newPrefabOutputPath))
                    {
                        // not cached, create new.
                        UnityEngine.Object prefabFile = PrefabUtility.CreateEmptyPrefab(newPrefabOutputPath);

                        // export prefab data.
                        PrefabUtility.ReplacePrefab(baseObject, prefabFile);

                        // save prefab.
                        AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
                        AssetDatabase.SaveAssets();
                        generated.Add(newPrefabOutputPath);
                        cachedOrGenerated.Add(newPrefabOutputPath);
                        Debug.Log("AssetGraph prefab:" + newPrefabOutputPath + " is newly generated.");
                    }
                    else
                    {
                        // cached.
                        usedCache.Add(newPrefabOutputPath);
                        cachedOrGenerated.Add(newPrefabOutputPath);
                        Debug.Log("AssetGraph prefab:" + newPrefabOutputPath + " is already cached. if want to regenerate forcely, set Prefabricate(baseObject, prefabName, true) <- forcely regenerate prefab.");
                    }

                    // set used.
                    PrefabricateIsUsed();

                    return(newPrefabOutputPath);
                };

                if (!Directory.Exists(recommendedPrefabPath))
                {
                    // create recommended directory.
                    Directory.CreateDirectory(recommendedPrefabPath);
                }

                /*
                 *      execute inheritee's input method.
                 */
                try {
                    In(groupKey, assets, recommendedPrefabPath, Prefabricate);
                } catch (Exception e) {
                    Debug.LogError("Prefabricator:" + this + " error:" + e);
                }

                if (!isUsed)
                {
                    Debug.LogWarning("should use 'Prefabricate' method for create prefab in Prefabricator for cache.");
                }


                /*
                 *      add assets in this node to next output.
                 *      it contains "cached" or "generated as prefab" or "else" assets.
                 *      output all assets.
                 */
                var currentAssetsInThisNode = FileController.FilePathsInFolder(recommendedPrefabPath);
                foreach (var newAssetPath in currentAssetsInThisNode)
                {
                    if (generated.Contains(newAssetPath))
                    {
                        var newAsset = InternalAssetData.InternalAssetDataGeneratedByImporterOrPrefabricator(
                            newAssetPath,
                            AssetDatabase.AssetPathToGUID(newAssetPath),
                            AssetGraphInternalFunctions.GetAssetType(newAssetPath),
                            true
                            );
                        outputSources.Add(newAsset);
                    }
                    else
                    {
                        var newAsset = InternalAssetData.InternalAssetDataGeneratedByImporterOrPrefabricator(
                            newAssetPath,
                            AssetDatabase.AssetPathToGUID(newAssetPath),
                            AssetGraphInternalFunctions.GetAssetType(newAssetPath),
                            false
                            );
                        outputSources.Add(newAsset);
                    }
                }


                /*
                 *      add current resources to next node's resources.
                 */
                foreach (var assetData in inputSources)
                {
                    var inheritedInternalAssetData = InternalAssetData.InternalAssetDataByImporter(
                        assetData.traceId,
                        assetData.absoluteSourcePath,
                        assetData.sourceBasePath,
                        assetData.fileNameAndExtension,
                        assetData.pathUnderSourceBase,
                        assetData.importedPath,
                        assetData.assetId,
                        assetData.assetType
                        );
                    outputSources.Add(inheritedInternalAssetData);
                }

                outputDict[groupKey] = outputSources;
            }

            // delete unused cached prefabs.
            var unusedCachePaths = alreadyCached.Except(cachedOrGenerated).Where(path => !GraphStackController.IsMetaFile(path)).ToList();

            foreach (var unusedCachePath in unusedCachePaths)
            {
                // unbundlize unused prefabricated cached asset.
                var assetImporter = AssetImporter.GetAtPath(unusedCachePath);
                assetImporter.assetBundleName = string.Empty;

                FileController.DeleteFileThenDeleteFolderIfEmpty(unusedCachePath);
            }


            Output(nodeId, labelToNext, outputDict, usedCache);
        }