问题
I am porting my game to UWP from the full desktop .net and one thing I need to work out is how to live load texture, shaders etc... into the UWP version of the game.
In the desktop version I use a FileSystemWatcher to do this but FileSystemWatcher doesn't exist in UWP, even on directory's that I have full control over.
Is there an equivalent for UWP?
What is the best way to implement this with the limited set of API's in UWP?
回答1:
Is there an equivalent for UWP?
You can subscribe the ContentChanged event for the queried storage files.
For example:
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".txt");
fileTypeFilter.Add(".png");
var options = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByName, fileTypeFilter);
var query = ApplicationData.Current.LocalFolder.CreateFileQueryWithOptions(options);
//subscribe on query's ContentsChanged event
query.ContentsChanged += Query_ContentsChanged;
var files = await query.GetFilesAsync();
private void Query_ContentsChanged(Windows.Storage.Search.IStorageQueryResultBase sender, object args)
{
//TODO:
}
This searches and returns all .txt and .png files in app's local folder, if the files in the query are added to, deleted from, or modified, this event will be fired.
来源:https://stackoverflow.com/questions/39737147/how-can-i-watch-for-file-changes-in-a-uwp-project