Beispiel #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"));
        }
Beispiel #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)));
        }
Beispiel #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));
        }
Beispiel #4
0
 public void Constructor()
 {
     {
         var p = new UnityPath(AsRootedPath(@"MyProject\Assets\Folder1/test.asset"));
         Assert.AreEqual(true, p.IsValid);
         Assert.AreEqual("Assets/Folder1/test.asset", p.Asset);
         Assert.AreEqual(AsRootedPath("MyProject/Assets/Folder1/test.asset"), p.Rooted);
         Assert.AreEqual(".asset", p.Extension);
     }
     {
         var p = new UnityPath(@"Assets\Folder1/test.asset");
         Assert.AreEqual(true, p.IsValid);
         Assert.AreEqual("Assets/Folder1/test.asset", p.Asset);
         Assert.AreEqual(Application.dataPath + "/Folder1/test.asset", p.Rooted);
         Assert.AreEqual(".asset", p.Extension);
     }
     {
         var p = new UnityPath(@"MyProject\Assets\Folder1/test.png");
         Assert.AreEqual(false, p.IsValid);
         Assert.AreEqual(string.Empty, p.Asset);
         Assert.AreEqual(string.Empty, p.Rooted);
         Assert.AreEqual(".png", p.Extension);
     }
 }
Beispiel #5
0
 public void ToAsset()
 {
     Assert.AreEqual("Assets/Folder1/test.asset",
                     UnityPath.ToAsset(AsRootedPath(@"MyProject\Assets\Folder1/test.asset")));
     Assert.AreEqual("Assets/test.asset", UnityPath.ToAsset(Application.dataPath + "/test.asset"));
 }