Last active
December 20, 2015 01:49
-
-
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.
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
// 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