Exemple #1
0
    public FileWatcher(string path, OnFileSystemChanged onChanged, string filter = "*.*", bool sub = true)
    {
        m_watcher = new FileSystemWatcher(path, filter);
        m_watcher.IncludeSubdirectories = sub;
        m_watcher.NotifyFilter          = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;

        m_handler = onChanged;
        m_thread  = new Thread(_StartWatch);

        UnityEditor.EditorApplication.update += Update;
    }
        private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            _fileSystemWatcher.EnableRaisingEvents = false;

            try
            {
                OnFileSystemChanged?.Invoke(this, e);
            }
            finally
            {
                // naive way
                _fileSystemWatcher.EnableRaisingEvents = true;
            }
        }