Exemple #1
0
        public void ToRooted()
        {
            var r = Application.dataPath;

            Assert.AreEqual(r + "/test.asset", UnityPath.ToRooted("Assets/test.asset"));
            Assert.AreEqual(r + "/Folder/test.asset", UnityPath.ToRooted(@"Assets\\\Folder\test.asset"));
        }
Exemple #2
0
        /// <summary>
        ///     Get a enumerable collection of asset paths in the folder of specified path.
        /// </summary>
        /// <param name="folderPath">Asset path of the folder to enumerate.</param>
        /// <param name="filter">Determines whether to add certain path to the result collection.</param>
        /// <param name="searchOption">
        ///     One of the enumeration values that specifies whether the search operation should include only the current
        ///     directory or should include all subdirectories. The default value is <see cref="SearchOption.TopDirectoryOnly" />.
        /// </param>
        /// <returns>An enumerable collection of all asset paths in the folder of specified path.</returns>
        public static IEnumerable <string> EnumerateAssetPathsInFolder(string folderPath,
                                                                       Func <string, bool> filter = null, SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            Ensure.Argument.NotNullOrEmpty(folderPath, nameof(folderPath));
            if (!AssetDatabase.IsValidFolder(folderPath))
            {
                throw new ArgumentException("Asset folder path is required.", nameof(folderPath));
            }

            var rootedFolderPath = UnityPath.ToRooted(folderPath);

            return(Directory.EnumerateFileSystemEntries(rootedFolderPath, "*", searchOption)
                   .Where(p => Path.GetExtension(p) != ".meta")
                   .Select(UnityPath.ToAsset)
                   .Where(p => filter == null || filter(p)));
        }
Exemple #3
0
        /// <summary>
        ///     Get a enumerable collection of asset paths in the folder of specified path.
        /// </summary>
        /// <param name="folderPath">Asset path of the folder to enumerate.</param>
        /// <param name="includeFolder">Determines whether the enumeration includes folder asset.</param>
        /// <param name="searchPattern">
        ///     The search string to match against the names of files in path. This parameter can contain a combination
        ///     of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
        /// </param>
        /// <param name="searchOption">
        ///     One of the enumeration values that specifies whether the search operation should include only the current
        ///     directory or should include all subdirectories. The default value is <see cref="SearchOption.TopDirectoryOnly" />.
        /// </param>
        /// <returns>An enumerable collection of all asset paths in the folder of specified path.</returns>
        public static IEnumerable <string> EnumerateAssetPathsInFolder(
            string folderPath, bool includeFolder = false, string searchPattern = "*",
            SearchOption searchOption             = SearchOption.TopDirectoryOnly)
        {
            Ensure.Argument.NotNullOrEmpty(folderPath, nameof(folderPath));
            if (!AssetDatabase.IsValidFolder(folderPath))
            {
                throw new ArgumentException("Asset folder path is required.", nameof(folderPath));
            }

            var rootedFolderPath = UnityPath.ToRooted(folderPath);
            var assetPaths       = includeFolder
                ? Directory.EnumerateFileSystemEntries(rootedFolderPath, searchPattern, searchOption)
                : Directory.EnumerateFiles(rootedFolderPath, searchPattern, searchOption);

            return(assetPaths.Where(p => Path.GetExtension(p) != ".meta").Select(UnityPath.ToAsset));
        }