-
-
Save arcv/d1269e6480629a015dedd6a50621f79f to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Net; | |
using UnityEditor; | |
using System.Net.Sockets; | |
using System.Threading.Tasks; | |
[InitializeOnLoad] | |
public class CompileClient | |
{ | |
public static bool setRefresh; | |
static TcpListener server = null; // this is the http server | |
static CompileClient() | |
{ | |
Task.Run(startServer); | |
EditorApplication.update += onUpdate; | |
} | |
private static void onUpdate() | |
{ | |
if (!setRefresh) return; | |
if (EditorApplication.isCompiling) return; | |
if (EditorApplication.isUpdating) return; | |
AssetDatabase.Refresh(); | |
setRefresh = false; | |
} | |
private static void startServer() | |
{ | |
server = new TcpListener(IPAddress.Parse("127.0.0.1"), 3001); | |
server.Start(); | |
Byte[] bytes = new Byte[256]; | |
while (true) | |
{ | |
TcpClient client = server.AcceptTcpClient(); | |
NetworkStream stream = client.GetStream(); | |
int i; | |
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) | |
{ | |
setRefresh = true; | |
} | |
client.Close(); | |
} | |
} | |
} |
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
# pip install watchgod | |
# copy this file to project's root | |
# run python watch.py | |
from watchgod import watch, AllWatcher, DefaultDirWatcher | |
import socket | |
import sys | |
import time | |
class CsharpWatcher(DefaultDirWatcher): | |
def should_watch_file(self, entry: 'DirEntry') -> bool: | |
return entry.name.endswith(('.cs')) | |
def notify(): | |
try: | |
time.sleep(0.2) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(('127.0.0.1', 3001)) | |
s.send(b"hi!") | |
except: | |
print("error! ", sys.exc_info()[0]) | |
for changes in watch('./Assets/', watcher_cls=CsharpWatcher): | |
notify() | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment