Skip to content

Commit 5de034e

Browse files
committed
new project from template: workaround for cloneFromProject erasing init script, now its copied after small delay (if use clone from template)
1 parent 7232747 commit 5de034e

1 file changed

Lines changed: 32 additions & 13 deletions

File tree

UnityLauncherPro/Tools.cs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,19 +1843,6 @@ public static Project FastCreateProject(string version, string baseFolder, strin
18431843

18441844
}
18451845

1846-
// copy init file into project
1847-
if (useInitScript == true)
1848-
{
1849-
if (File.Exists(initScriptPath) == true)
1850-
{
1851-
var editorTargetFolder = Path.Combine(baseFolder, projectName, "Assets", "Editor");
1852-
if (Directory.Exists(editorTargetFolder) == false) Directory.CreateDirectory(editorTargetFolder);
1853-
var targetScriptFile = Path.Combine(editorTargetFolder, Path.GetFileName(initScriptPath));
1854-
// TODO overwrite old file, there shouldnt be anything here
1855-
if (File.Exists(targetScriptFile) == false) File.Copy(initScriptPath, targetScriptFile);
1856-
}
1857-
}
1858-
18591846
// launch empty project
18601847
var proj = new Project();
18611848

@@ -1874,13 +1861,45 @@ public static Project FastCreateProject(string version, string baseFolder, strin
18741861
proj.Arguments += " -cloneFromTemplate \"" + templateZipPath + "\"";
18751862
}
18761863
var proc = LaunchProject(proj, null, useInitScript, false, cloneFromTemplate);
1864+
18771865
if (cloneFromTemplate == true)
18781866
{
18791867
// remove the -cloneFromTemplate argument, since its not needed in the recent list
18801868
proj.Arguments = origArgs;
18811869
}
1870+
18821871
ProcessHandler.Add(proj, proc);
18831872

1873+
// copy init file into project
1874+
if (useInitScript == true)
1875+
{
1876+
Action copyInitScript = () =>
1877+
{
1878+
if (File.Exists(initScriptPath) == true)
1879+
{
1880+
var editorTargetFolder = Path.Combine(baseFolder, projectName, "Assets", "Editor");
1881+
if (Directory.Exists(editorTargetFolder) == false) Directory.CreateDirectory(editorTargetFolder);
1882+
var targetScriptFile = Path.Combine(editorTargetFolder, Path.GetFileName(initScriptPath));
1883+
// TODO overwrite old file, there shouldnt be anything here
1884+
if (File.Exists(targetScriptFile) == false) File.Copy(initScriptPath, targetScriptFile);
1885+
}
1886+
};
1887+
1888+
if (cloneFromTemplate == true)
1889+
{
1890+
// need to copy later, because cloning overwrites the folder?
1891+
_ = Task.Run(async () =>
1892+
{
1893+
await Task.Delay(7500);
1894+
copyInitScript();
1895+
});
1896+
}
1897+
else
1898+
{
1899+
copyInitScript();
1900+
}
1901+
}
1902+
18841903
return proj;
18851904
} // FastCreateProject
18861905

0 commit comments

Comments
 (0)