using UnityEditor;
using UnityEngine;
public class MyClass: MonoBehaviour {
public static void MyMethod(){
BuildPipeline.BuildPlayer(
new string[] {"MySceneMenu","MySceneGame"},
"path/to/build",
BuildTarget.StandaloneLinuxUniversal,
BuildOptions.EnableHeadlessMode | BuildOptions.Development
);
}}
Next I created a simple file called Build.sh (Bash Linux) or Build.bat (PowerShell Windows).
To call unity through command line you need the path to the unity executable and pass arguments in the pattern "-parameterKey parameterValue".
The arguments to be used:
* projectPath: The project path you want to build
* batchmode: to signal no human interaction.
* nographics: so unity wont show windows or use any gpu graphics device.
* executeMethod: The method to execute and finally quit argument. Inside the file you have something like this:
#!/bin/sh
#Build.sh
/path/to/Unity -projectPath "/path/to/my/project" -batchmode -nographics -executeMethod MyClass.MyMethod -quit
#After this I added various commands to clean and zip the project folder.
cd /path/to/build/
rm Build.zip #remove last one
zip -r Build.zip BuildFolder/
ECHO Building...
"Path\To\Unity.exe" -projectPath "Path\To\Project" -batchmode -nographics -executeMethod MyClass.MyMethod -quit
ECHO "Build Completed"
ECHO "Compressing Build"
del "Path\To\Build.zip"
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem';[IO.Compression.ZipFile]::CreateFromDirectory('Path\To\Build', 'Path\To\Build.zip'); }"
ECHO "Compressing Completed"
Execute the bash file and Bam! Unity is building silently and doing the work while you drink more coffee and think about the cool parts of your game! In your script in c# or command line could have some automation like uploading to your testers, send a message/notification warning testers, add extra files like manuals,artwork, etc.
Using command line brings a lot of benefits. If you want to convert the extension of some file. In my case I wanted to convert json files to yaml, which is more compact and friendly format. I used the following code:
#./change-extension.sh "path/to/folder"
cd $1
for file in *.json; do
filename="${file%.*}"
echo "converting $filename"
json2yaml "$filename.json" > "$filename.yaml"
done
#!/bin/sh
#create gif
sudo rm -rf $1
mkdir $1
ffmpeg -i $1.mp4 -s 960x540 -r 5 $1'/frame-%03d.jpg'
#480x270
cd $1
convert -delay 10 -loop 0 *.jpg $1.gif
mv $1.gif ..
cd ..
sudo rm -rf $1
#!/bin/sh
for file in *.mp4; do
filename="${file%.*}"
./create_gif.sh $filename
done
...
Published © 2017 Mavega™
Version 4.3.5