Skip to content

Commit 3bce557

Browse files
committed
adding custom project init script feature and settings
1 parent 6be6033 commit 3bce557

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,12 @@
11401140
<Label Content="Shortcut .bat files folder" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" />
11411141
</StackPanel>
11421142

1143-
1143+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4">
1144+
<CheckBox x:Name="chkUseInitScript" Content="Use Init script for new projects" ToolTip="..." HorizontalAlignment="Left"/>
1145+
<!--<Label Content="Init script for new projects" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" />-->
1146+
<TextBox x:Name="txtCustomInitFile" BorderBrush="Transparent" MinWidth="128" ToolTip="Default is InitProject.cs" Padding="0,3,0,0" Margin="5,0,0,0" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" Text="InitProject.cs" PreviewKeyDown="TxtCustomThemeFile_PreviewKeyDown" />
1147+
<Button Style="{StaticResource CustomButton}" ToolTip="Explore Scripts folder" x:Name="btnExploreScriptsFolder" Content="..." Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="btnExploreScriptsFolder_Click" Margin="5,0,0,0"/>
1148+
</StackPanel>
11441149

11451150
</StackPanel>
11461151
</StackPanel>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,10 +1649,11 @@ void CreateNewEmptyProject(string targetFolder = null)
16491649

16501650
if (results == true)
16511651
{
1652+
// TODO check if that folder already exists (automatic naming avoids it, but manual naming could cause it)
16521653
Console.WriteLine("Create project " + NewProject.newVersion + " : " + rootFolder);
16531654
if (string.IsNullOrEmpty(rootFolder)) return;
16541655

1655-
var p = Tools.FastCreateProject(NewProject.newVersion, rootFolder, NewProject.newProjectName, NewProject.templateZipPath, NewProject.platformsForThisUnity, NewProject.selectedPlatform);
1656+
var p = Tools.FastCreateProject(NewProject.newVersion, rootFolder, NewProject.newProjectName, NewProject.templateZipPath, NewProject.platformsForThisUnity, NewProject.selectedPlatform, (bool)chkUseInitScript.IsChecked, txtCustomInitFile.Text);
16561657

16571658
// add to list (just in case new project fails to start, then folder is already generated..)
16581659
if (p != null) AddNewProjectToList(p);
@@ -1675,6 +1676,7 @@ void CreateNewEmptyProject(string targetFolder = null)
16751676
{
16761677
newVersion = GetSelectedUnity().Version == null ? preferredVersion : GetSelectedUnity().Version;
16771678
}
1679+
// TODO custom init file here also
16781680
var p = Tools.FastCreateProject(newVersion, rootFolder);
16791681
if (p != null) AddNewProjectToList(p);
16801682
}
@@ -2751,6 +2753,12 @@ public int Compare(Object a, Object b)
27512753
}
27522754
}
27532755

2756+
private void btnExploreScriptsFolder_Click(object sender, RoutedEventArgs e)
2757+
{
2758+
// TODO later this script should be inside some unity project, for easier updating..
2759+
Tools.LaunchExplorer(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts"));
2760+
}
2761+
27542762
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
27552763
//{
27562764
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");

UnityLauncherPro/Tools.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public static void ExploreFolder(string path)
187187
}
188188

189189
// NOTE holding alt key (when using alt+o) brings up unity project selector
190-
public static Process LaunchProject(Project proj, DataGrid dataGridRef = null)
190+
public static Process LaunchProject(Project proj, DataGrid dataGridRef = null, bool useInitScript = false)
191191
{
192192
// validate
193193
if (proj == null) return null;
@@ -253,6 +253,11 @@ public static Process LaunchProject(Project proj, DataGrid dataGridRef = null)
253253
unitycommandlineparameters += " -buildTarget " + projTargetPlatform;
254254
}
255255

256+
if (useInitScript == true)
257+
{
258+
unitycommandlineparameters += " -executeMethod UnityLauncherProTools.InitProject.Init";
259+
}
260+
256261
Console.WriteLine("Start process: " + cmd + " " + unitycommandlineparameters);
257262

258263
newProcess.StartInfo.Arguments = unitycommandlineparameters;
@@ -1037,7 +1042,8 @@ public static string BrowseForOutputFolder(string title, string initialDirectory
10371042
return null;
10381043
}
10391044

1040-
public static Project FastCreateProject(string version, string baseFolder, string projectName = null, string templateZipPath = null, string[] platformsForThisUnity = null, string platform = null)
1045+
// TODO too many params..
1046+
public static Project FastCreateProject(string version, string baseFolder, string projectName = null, string templateZipPath = null, string[] platformsForThisUnity = null, string platform = null, bool useInitScript = false, string initScriptPath = null)
10411047
{
10421048
// check for base folders in settings tab
10431049
if (string.IsNullOrEmpty(baseFolder) == true)
@@ -1064,8 +1070,6 @@ public static Project FastCreateProject(string version, string baseFolder, strin
10641070
// if we didnt have name yet
10651071
if (string.IsNullOrEmpty(projectName) == true)
10661072
{
1067-
//Console.WriteLine("version=" + version);
1068-
//Console.WriteLine("baseFolder=" + baseFolder);
10691073
projectName = GetSuggestedProjectName(version, baseFolder);
10701074
// failed getting new path a-z
10711075
if (projectName == null) return null;
@@ -1081,6 +1085,21 @@ public static Project FastCreateProject(string version, string baseFolder, strin
10811085
TarLib.Tar.ExtractTarGz(templateZipPath, newPath);
10821086
}
10831087

1088+
// copy init file into project
1089+
if (useInitScript == true)
1090+
{
1091+
var initScriptFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts", initScriptPath);
1092+
Console.WriteLine("initScriptFile: " + initScriptFile);
1093+
if (File.Exists(initScriptFile) == true)
1094+
{
1095+
var editorTargetFolder = Path.Combine(baseFolder, projectName, "Assets", "Scripts", "Editor");
1096+
Console.WriteLine(editorTargetFolder);
1097+
if (Directory.Exists(editorTargetFolder) == false) Directory.CreateDirectory(editorTargetFolder);
1098+
var targetScriptFile = Path.Combine(editorTargetFolder, initScriptPath);
1099+
if (File.Exists(targetScriptFile) == false) File.Copy(initScriptFile, targetScriptFile);
1100+
}
1101+
}
1102+
10841103
// launch empty project
10851104
var proj = new Project();
10861105
proj.Title = projectName;
@@ -1089,8 +1108,10 @@ public static Project FastCreateProject(string version, string baseFolder, strin
10891108
proj.TargetPlatforms = platformsForThisUnity;
10901109
proj.TargetPlatform = platform;
10911110
proj.Modified = DateTime.Now;
1092-
var proc = LaunchProject(proj);
1111+
1112+
var proc = LaunchProject(proj, null, useInitScript);
10931113
ProcessHandler.Add(proj, proc);
1114+
10941115
return proj;
10951116
} // FastCreateProject
10961117

@@ -1628,7 +1649,7 @@ public static bool CreateDesktopShortCut(Project proj, string batchFolder)
16281649
internal static long GetFolderSizeInBytes(string currentBuildReportProjectPath)
16291650
{
16301651
if (Directory.Exists(currentBuildReportProjectPath) == false) return 0;
1631-
1652+
16321653
return DirSize(new DirectoryInfo(currentBuildReportProjectPath));
16331654
}
16341655

0 commit comments

Comments
 (0)