Ich brauche eine Thread-Safe-Klasse für File System Watcher im Unity Editor zu verwenden, weiß ich bereits, dass Threading ist nicht möglich, aus Korotinen, aber ich wusste nicht, dass Threading nicht war erlaubt auch im Editor.Thread-sicher File System Watcher für Unity Editor
So gibt es mein Fehler:
get_isEditor can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. 0x0000000140E431ED (Unity) StackWalker::GetCurrentCallstack 0x0000000140E44EE1 (Unity) StackWalker::ShowCallstack 0x00000001405FC603 (Unity) GetStacktrace 0x00000001405F97FE (Unity) DebugStringToFile 0x00000001405F9C5C (Unity) DebugStringToFile 0x000000014035F7B3 (Unity) ThreadAndSerializationSafeCheckReportError 0x0000000140E7B988 (Unity) Application_Get_Custom_PropIsEditor 0x0000000015AC46AA (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Application:get_isEditor() 0x0000000015AC42FE (Mono JIT Code) [Helpers.cs:585] Lerp2API.DebugHandler.Debug:Log (object) 0x0000000015AC41C2 (Mono JIT Code) [Helpers.cs:578] Lerp2API.DebugHandler.Debug:Log (string) 0x0000000015AC40F7 (Mono JIT Code) [LerpedEditorCore.cs:101] Lerp2APIEditor.LerpedEditorCore:Recompile (object,System.IO.FileSystemEventArgs) 0x0000000015AC3F2D (Mono JIT Code) (wrapper runtime-invoke) :runtime_invoke_void__this___object_object (object,intptr,intptr,intptr) 0x00007FFB400A519B (mono) [mini.c:4937] mono_jit_runtime_invoke 0x00007FFB3FFF84FD (mono) [object.c:2623] mono_runtime_invoke 0x00007FFB3FFFE8F7 (mono) [object.c:3827] mono_runtime_invoke_array 0x00007FFB3FFFEBCC (mono) [object.c:5457] mono_message_invoke 0x00007FFB4001EB8B (mono) [threadpool.c:1019] mono_async_invoke 0x00007FFB4001F5E2 (mono) [threadpool.c:1455] async_invoke_thread 0x00007FFB4002329F (mono) [threads.c:685] start_wrapper 0x00007FFB400D78C9 (mono) [win32_threads.c:599] thread_start 0x00007FFB77FC8364 (KERNEL32) BaseThreadInitThunk
ich volle Stack-Trace kopiert bewusst alle Helfer zu machen, wo das Problem sein kann. Weil ich nach einer Lösung gesucht, wie jeder sicher FWS Gewinde, und ja, es ist ein, aber nur für .NET 4, und ich brauche einen für .NET 2
Dies ist mein Code:
using System.IO; //class, namespace, redundant info...
private static FileSystemWatcher m_Watcher;
[InitializeOnLoadMethod]
static void HookWatcher()
{
m_Watcher = new FileSystemWatcher("path", "*.cs");
m_Watcher.NotifyFilter = NotifyFilters.LastWrite;
m_Watcher.IncludeSubdirectories = true;
//m_Watcher.Created += new FileSystemEventHandler(); //Add to the solution before compile
//m_Watcher.Renamed += new FileSystemEventHandler(); //Rename to the solution before compile
//m_Watcher.Deleted += new FileSystemEventHandler(); //Remove to the solution before compile
m_Watcher.Changed += Recompile;
m_Watcher.EnableRaisingEvents = true;
}
private static void Recompile(object sender, FileSystemEventArgs e)
{
Debug.Log("Origin files has been changed!");
}
Es gibt nichts besonderes, wie Sie sehen können ...
die FSW ich dies sah, war: https://gist.githubusercontent.com/bradsjm/2c839912294d0e2c008a/raw/c4a5c3d920ab46fdaa53b0e111e0d1204b1fe903/FileSystemWatcher.cs
mit dieser Mein Ziel ist es einfach, ich habe eine DLL getrennt von meinem aktuellen Unity-Projekt, die Idee ist einfach Ich möchte alles automatisch von Unity neu kompilieren, wenn sich etwas ändert aus dem Projekt der DLL ist geändert, aber das kann ich wegen Threads nicht erreichen, also was kann ich tun? Gibt es eine Alternative, um Dateien zu hören, die mit Unity kompatibel sind?
Danke.
Ich denke, schlanker wäre es, benutzerdefinierte SynchronizingObject zuweisen. – aeroson