bool 当启用目录监视时返回 true。否则返回 false。
报告目录监视是否已启用。
在首选项设置中或使用脚本(EditorPrefs.SetBool("DirectoryMonitoring", boolValue))打开或关闭目录监视。
可以使用命令行标志 [[-DisableDirectoryMonitor]] 禁用目录监视,并且当 Unity 检测到项目中的符号链接时,会自动禁用目录监视。
using UnityEngine; using UnityEditor; using UnityEngine.Profiling; using System.IO;
public class DirectoryMonitoringTest { [MenuItem("AssetDatabase/Directory Monitoring Test")] static void DirectoryMonitoringBenchmark() { var BenchmarkCount = 1;
//Disabling the Directory Monitoring will use a brute force scanning method to evaluate which files in the project have been changed, and is much slower EditorPrefs.SetBool("DirectoryMonitoring", false); Debug.Log("Is Directory Monitoring Enabled? - " + AssetDatabase.IsDirectoryMonitoringEnabled());
Benchmark(BenchmarkCount); BenchmarkCount++;
EditorPrefs.SetBool("DirectoryMonitoring", true); Debug.Log("Is Directory Monitoring Enabled? - " + AssetDatabase.IsDirectoryMonitoringEnabled()); Benchmark(BenchmarkCount); }
//This test will show faster scan time when using Directory Monitoring static void Benchmark(int BenchmarkCount) { var relativePath = "Assets/test_file01.txt"; if (!File.Exists(relativePath)) { using (StreamWriter sw = File.CreateText(relativePath)) { sw.WriteLine("Hello"); sw.WriteLine("And"); sw.WriteLine("Welcome"); } }
Profiler.BeginSample("Benchmark " + BenchmarkCount); ; AssetDatabase.ImportAsset(relativePath); Profiler.EndSample();
AssetDatabase.DeleteAsset(relativePath); AssetDatabase.Refresh(); } }