Created
February 15, 2017 07:34
-
-
Save talecrafter/71fcaa222b986cd2bd40d2eaf6dec366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
public static class AssetFilesCounter | |
{ | |
[MenuItem("Utilities/Count Asset Files")] | |
public static void CountAssetFiles() | |
{ | |
EditorUtility.DisplayProgressBar("Counting Asset Files", "", 0); | |
try | |
{ | |
// using our own counting here, AssetDatabase.GetAllAssetPaths() would include directories | |
int assetFilesCount = GetAllFilesExcludingExtensions(Application.dataPath, "*.*", "meta").Length; | |
Debug.Log("Asset Files: " + assetFilesCount); | |
} | |
finally | |
{ | |
EditorUtility.ClearProgressBar(); | |
} | |
} | |
public static string[] GetAllFilesExcludingExtensions(string path, string searchPattern, params string[] extensions) | |
{ | |
if (!Directory.Exists(path)) | |
{ | |
throw new DirectoryNotFoundException("Directory " + path + " not found."); | |
} | |
// make sure extension has the right format | |
for (int i = 0; i < extensions.Length; i++) | |
{ | |
if (!extensions[i].StartsWith(".")) | |
{ | |
extensions[i] = "." + extensions[i]; | |
} | |
} | |
var allFiles = Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories); | |
List<string> validFiles = new List<string>(); | |
foreach (var file in allFiles) | |
{ | |
if (!PathHasExtension(file, extensions)) | |
{ | |
validFiles.Add(file); | |
} | |
} | |
return validFiles.ToArray(); | |
} | |
public static bool PathHasExtension(string path, params string[] extensions) | |
{ | |
for (int i = 0; i < extensions.Length; i++) | |
{ | |
if (path.EndsWith(extensions[i])) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment