效果展示:
代码:
using LuaFramework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Policy;
using UnityEditor;
using UnityEngine;
namespace LuaDevelopTool
{
public class ReloadLuaFilesWindow : EditorWindow
{
public static string LUA_PATH;
public static FileSystemWatcher watcher = null;
public static bool autoReload = false;
public static bool reloaded = false;
public static Dictionary<string, long> luaFiles = new Dictionary<string, long>();
[MenuItem("Lua/Reload Lua Window", false, 200)]
public static void ShowWindow()
{
GetWindow(typeof(ReloadLuaFilesWindow), false, "Lua热重载");
}
private void OnEnable()
{
if (watcher == null)
{
LUA_PATH = Application.dataPath + "/Starwars/Lua/"; //lua文件存放地点
watcher = new FileSystemWatcher();
watcher.Filter = "*.lua";
watcher.Path = LUA_PATH;
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.Size;
watcher.IncludeSubdirectories = true;
EditorApplication.playModeStateChanged += OnPlayerModeStateChanged;
}
}
private void OnDestroy()
{
watcher.Dispose();
watcher = null;
EditorApplication.playModeStateChanged -= OnPlayerModeStateChanged;
}
private static void OnPlayerModeStateChanged(PlayModeStateChange playModeState)
{
if (playModeState == PlayModeStateChange.EnteredPlayMode)
{
watcher