IsMetaFile() public static method

public static IsMetaFile ( string filePath ) : bool
filePath string
return bool
        public static void RemoveBundleSettings(string nodePath)
        {
            EditorUtility.DisplayProgressBar("AssetBundleGraph unbundlize all resources...", nodePath, 0);
            var filePathsInFolder = FileUtility.FilePathsInFolder(nodePath);

            foreach (var filePath in filePathsInFolder)
            {
                if (FileUtility.IsMetaFile(filePath))
                {
                    continue;
                }
                if (FileUtility.ContainsHiddenFiles(filePath))
                {
                    continue;
                }
                var assetImporter = AssetImporter.GetAtPath(filePath);

                // assetImporter is null when the asset is not accepted by Unity.
                // e.g. file.my_new_extension is ignored by Unity.
                if (assetImporter == null)
                {
                    continue;
                }

                if (assetImporter.GetType() == typeof(UnityEditor.MonoImporter))
                {
                    continue;
                }

                assetImporter.assetBundleName = string.Empty;
            }
            EditorUtility.ClearProgressBar();
        }
Beispiel #2
0
        /**
         *      returns file paths which are located in the folder.
         *
         *      this method is main point for supporting path format of cross platform.
         *
         *      Usually Unity Editor uses '/' as folder delimter.
         *
         *      e.g.
         *              Application.dataPath returns
         *                      C:/somewhere/projectPath/Assets @ Windows.
         *                              or
         *                      /somewhere/projectPath/Assets @ Mac, Linux.
         *
         *
         *      but "Directory.GetFiles(localFolderPath + "/")" method returns different formatted path by platform.
         *
         *      @ Windows:
         *              localFolderPath + / + somewhere\folder\file.extention
         *
         *      @ Mac/Linux:
         *              localFolderPath + / + somewhere/folder/file.extention
         *
         *      the problem is, "Directory.GetFiles" returns mixed format path of files @ Windows.
         *      this is the point of failure.
         *
         *      this method replaces folder delimiters to '/'.
         */
        public static List <string> FilePathsInFolderOnly1Level(string localFolderPath)
        {
            // change platform-depends folder delimiter -> '/'
            var filePaths = ConvertSeparater(Directory.GetFiles(localFolderPath)
                                             .Where(path => !(Path.GetFileName(path).StartsWith(AssetBundleGraphSettings.DOTSTART_HIDDEN_FILE_HEADSTRING)))
                                             .ToList());

            if (AssetBundleGraphSettings.IGNORE_META)
            {
                filePaths = filePaths.Where(path => !FileUtility.IsMetaFile(path)).ToList();
            }

            return(filePaths);
        }
Beispiel #3
0
        // Get files under given path
        public static List <string> GetFilePathsInFolder(string folderPath, bool includeHidden = false, bool includeMeta = !AssetBundleGraphSettings.IGNORE_META)
        {
            var filePaths = Directory.GetFiles(folderPath).Select(p => p);

            if (!includeHidden)
            {
                filePaths = filePaths.Where(path => !(Path.GetFileName(path).StartsWith(AssetBundleGraphSettings.DOTSTART_HIDDEN_FILE_HEADSTRING)));
            }
            if (!includeMeta)
            {
                filePaths = filePaths.Where(path => !FileUtility.IsMetaFile(path));
            }

            // Directory.GetFiles() returns platform dependent delimiter, so make sure replace with "/"
            if (Path.DirectorySeparatorChar != AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR)
            {
                filePaths = filePaths.Select(filePath => filePath.Replace(Path.DirectorySeparatorChar.ToString(), AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR.ToString()));
            }

            return(filePaths.ToList());
        }
        public void Run(string nodeName, string nodeId, string connectionIdToNextNode, Dictionary <string, List <Asset> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, 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.importFrom))
                    {
                        invalids.Add(source.absoluteAssetPath);
                    }
                }
            }

            if (invalids.Any())
            {
                throw new NodeException(string.Join(", ", invalids.ToArray()) + " are not imported yet. These assets need to be imported before prefabricated.", nodeId);
            }

            var recommendedPrefabOutputDirectoryPath = FileUtility.PathCombine(AssetBundleGraphSettings.PREFABRICATOR_CACHE_PLACE, nodeId, SystemDataUtility.GetCurrentPlatformKey());

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

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

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

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

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


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

                    if (forceGenerate || !SystemDataUtility.IsAllAssetsCachedAndUpdated(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(nodeName + " created new prefab: " + newPrefabOutputPath);
                    }
                    else
                    {
                        // cached.
                        usedCache.Add(newPrefabOutputPath);
                        cachedOrGenerated.Add(newPrefabOutputPath);
                        Debug.Log(nodeName + " used cached prefab: " + newPrefabOutputPath);
                    }

                    isPrefabricateFunctionCalled = true;

                    return(newPrefabOutputPath);
                };

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

                /*
                 *      execute inheritee's input method.
                 */
                try {
                    CreatePrefab(nodeName, nodeId, groupKey, assets, recommendedPrefabPath, Prefabricate);
                } catch (Exception e) {
                    Debug.LogError(nodeName + " Error:" + e);
                    throw new NodeException(nodeName + " Error:" + e, nodeId);
                }

                if (!isPrefabricateFunctionCalled)
                {
                    Debug.LogWarning(nodeName + ": Prefabricate delegate was not called. Prefab might not be created properly.");
                }

                /*
                 *      ready assets-output-data from this node to next output.
                 *      it contains "cached" or "generated as prefab" or "else" assets.
                 *      output all assets.
                 */
                var currentAssetsInThisNode = FileUtility.FilePathsInFolder(recommendedPrefabPath);
                foreach (var generatedCandidateAssetPath in currentAssetsInThisNode)
                {
                    /*
                     *      candidate is new, regenerated prefab.
                     */
                    if (generated.Contains(generatedCandidateAssetPath))
                    {
                        var newAsset = Asset.CreateNewAssetWithImportPathAndStatus(
                            generatedCandidateAssetPath,
                            true,
                            false
                            );
                        outputSources.Add(newAsset);
                        continue;
                    }

                    /*
                     *      candidate is not new prefab.
                     */
                    var cachedPrefabAsset = Asset.CreateNewAssetWithImportPathAndStatus(
                        generatedCandidateAssetPath,
                        false,
                        false
                        );
                    outputSources.Add(cachedPrefabAsset);
                }


                /*
                 *      add current resources to next node's resources.
                 */
                outputSources.AddRange(inputSources);

                outputDict[groupKey] = outputSources;
            }

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

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

                FileUtility.DeleteFileThenDeleteFolderIfEmpty(unusedCachePath);
            }


            Output(nodeId, connectionIdToNextNode, outputDict, usedCache);
        }
Beispiel #5
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);
        }