Skip to content

Instantly share code, notes, and snippets.

@dimitarcl
Last active December 20, 2015 01:49
Show Gist options
  • Save dimitarcl/6051947 to your computer and use it in GitHub Desktop.
Save dimitarcl/6051947 to your computer and use it in GitHub Desktop.
Automatically reloading a Coherent UI view in Unity3D when the resources have changed.
// Disclaimer: This snippet illustrates an idea and may contain bugs. Use with caution.
using UnityEngine;
using System.IO;
public class UIResourcesMonitor : MonoBehaviour {
FileSystemWatcher m_Watcher;
void Start () {
m_Watcher = new FileSystemWatcher(PlayerPrefs.GetString("CoherentUIResources"));
m_Watcher.IncludeSubdirectories = true;
m_Watcher.EnableRaisingEvents = true;
var view = GetComponent<CoherentUIView>();
m_Watcher.Changed += (sender, e) => { view.Reload(true); };
view.OnViewDestroyed += () => {
m_Watcher.Dispose();
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment