Skip to content

Instantly share code, notes, and snippets.

@ngothanhtai
Last active October 9, 2015 08:41
Show Gist options
  • Save ngothanhtai/c508bdab51064b7feee0 to your computer and use it in GitHub Desktop.
Save ngothanhtai/c508bdab51064b7feee0 to your computer and use it in GitHub Desktop.
Detect save change in Editor mode - Unity3D C#
using UnityEngine;
using System.Collections;
using System.IO;
namespace TaiNgo
{
[ExecuteInEditMode]
public class Activator : MonoBehaviour {
#if UNITY_EDITOR
string currentOpenScene = "";
void OnEnable()
{
Debug.Log("OnEnable");
var m_SceneFileWatcher = new FileSystemWatcher(Path.GetFullPath("Assets"), "*.unity");
m_SceneFileWatcher.NotifyFilter = NotifyFilters.LastWrite;
m_SceneFileWatcher.EnableRaisingEvents = true;
m_SceneFileWatcher.Changed += OnSceneFileWatcher_Changed;
currentOpenScene = Path.GetFileNameWithoutExtension(UnityEditor.EditorApplication.currentScene);
}
void OnSceneFileWatcher_Changed(object sender, FileSystemEventArgs e)
{
var sceneName = Path.GetFileNameWithoutExtension(e.FullPath);
if(currentOpenScene.ToLower() == sceneName.ToLower())
{
}
}
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment