Skip to content

Instantly share code, notes, and snippets.

@forestrf
Last active July 26, 2018 19:10
Show Gist options
  • Save forestrf/4c7b7ff702a241804aa049e858ac0fbf to your computer and use it in GitHub Desktop.
Save forestrf/4c7b7ff702a241804aa049e858ac0fbf to your computer and use it in GitHub Desktop.
[FIXED BY UNITY. This is not needed at all anymore] Unity sometimes does not reload my scripts when reimporting them. Apparently the .dlls inside /Library/ScriptAssemblies are not always replaced by the generated dlls inside /Temp, so this scripts moves those dlls automatically
using System;
using System.IO;
class Program {
static void Main(string[] args) {
Console.WriteLine("Close this window when you are finished doing cool progress");
Console.WriteLine("first argument: path to Library folder");
// Path
string path = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location).Directory.FullName;
if (args.Length == 0) {
Console.WriteLine("No path parameter. Using default");
path += "\\Library\\ScriptAssemblies";
} else {
path = args[0];
}
Console.WriteLine("Using path: " + path);
if (!Directory.Exists(path)) {
Console.WriteLine("The path does not exist");
return;
}
string tmpPath = Directory.CreateDirectory(new DirectoryInfo(path).Parent.FullName + "\\tmpAssemblies").FullName;
string TempProjectFolder = new DirectoryInfo(path).Parent.Parent.FullName + "\\Temp";
FileSystemWatcher watcher = new FileSystemWatcher(path);
while (true) {
var changed = watcher.WaitForChanged(WatcherChangeTypes.All);
Console.WriteLine("Change detected: " + changed.ChangeType + " - " + changed.Name);
if (changed.ChangeType == WatcherChangeTypes.Created && changed.Name == "BuiltinAssemblies.stamp") {
Console.WriteLine("Manually moving Assemblies from Temp to Library/ScriptAssemblies");
foreach (string filePath in Directory.GetFiles(TempProjectFolder)) {
if (!filePath.Contains(".dll")) continue;
var scrpAssmPath = path + "\\" + new FileInfo(filePath).Name;
if (File.Exists(scrpAssmPath)) File.Delete(scrpAssmPath);
File.Move(filePath, scrpAssmPath);
Console.WriteLine("Manually moved: " + new FileInfo(filePath).Name);
}
Console.WriteLine("Done");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment