Last active
July 13, 2020 11:08
-
-
Save korchoon/b2784156ee54bd030f23bc59a1e37871 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#if UNITY_EDITOR_WIN | |
using System; | |
using UnityEngine; | |
using UnityEditor; | |
using System.Diagnostics; | |
class CreateSymlinkProject { | |
[MenuItem("Tools/Create Symlink Project")] | |
static void SymlinkProject() { | |
var src = Application.dataPath.Replace("/Assets", string.Empty); | |
var dst = EditorUtility.SaveFolderPanel("Create new project root folder", string.Empty, string.Empty); | |
if (dst == string.Empty) | |
return; | |
var cmdBatch = new[] { | |
Symlink(src, dst, s => $"{s}/Assets"), | |
Symlink(src, dst, s => $"{s}/ProjectSettings"), | |
Symlink(src, dst, s => $"{s}/Packages"), | |
Copy(src, dst, s => $"{s}/Library"), | |
Copy(src, dst, s => $"{s}/Temp") | |
}; | |
foreach (var cmd in cmdBatch) | |
CmdAdmin(cmd); | |
Application.OpenURL(dst); | |
} | |
static string Symlink(string src, string dst, Func<string, string> local) { | |
return $"/c mklink /D \"{local(dst)}\" \"{local(src)}\""; | |
} | |
static string Copy(string src, string dst, Func<string, string> local) { | |
return $"/c robocopy \"{local(src)}\" \"{local(dst)}\" /MIR /R:0 /W:0"; | |
} | |
static void CmdAdmin(string command) { | |
// elevate permissions to admin | |
var processStartInfo = new ProcessStartInfo("cmd.exe", command) { | |
// CreateNoWindow = true, | |
// WindowStyle = ProcessWindowStyle.Hidden, | |
UseShellExecute = true, | |
Verb = "runas" | |
}; | |
Process.Start(processStartInfo).WaitForExit(); // waiting prevents Library folder modifications while copying | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment