Skip to content

Commit

Permalink
Merge pull request #86 from guitarrapc/feature/dedicated
Browse files Browse the repository at this point in the history
chore: Sandbox to support il2cpp / dedicated server build
  • Loading branch information
guitarrapc authored Jun 25, 2024
2 parents 1de84ce + dee440c commit 9246d8d
Show file tree
Hide file tree
Showing 69 changed files with 17,886 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sandbox/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sandbox.Unity/artifacts/
Sandbox.Unity/Library/
Sandbox.Unity/Logs/
Sandbox.Unity/Temp/
Sandbox.Unity/*.csproj
Sandbox.Unity/*.sln
artifacts/
Library/
Logs/
Temp/
*.csproj
*.sln
6 changes: 6 additions & 0 deletions sandbox/Sandbox.Unity.IL2CPPDedicatedServer/.vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System.IO;
using UnityEditor;
using UnityEditor.Build;

public class BuildUnityMenu
{
private static readonly string[] scenes = new[] { "Assets/Scenes/SampleScene.unity" };

[MenuItem("MyTools/Build Windows IL2CPP Player")]
public static void BuildWindowsIl2cppPlayer()
{
var path = "artifacts/WindowsPlayer/Build.il2cpp-player.exe";

var buildPlayerOptions = new BuildPlayerOptions();

// Platform & Architecture
buildPlayerOptions.target = BuildTarget.StandaloneWindows;
buildPlayerOptions.subtarget = (int)StandaloneBuildSubtarget.Player;

// IL2CPP
EnableIl2Cpp(NamedBuildTarget.Standalone);

// Path and Scenes
buildPlayerOptions.locationPathName = path;
buildPlayerOptions.scenes = scenes;

// Build
BuildPipeline.BuildPlayer(buildPlayerOptions);

// Cleanup
CleanupDontship(path);
}

[MenuItem("MyTools/Build Windows IL2CPP DedicatedServer")]
public static void BuildWindowsIl2cppServer()
{
var path = "artifacts/WindowsServer/Build.il2cpp-server.exe";

var buildPlayerOptions = new BuildPlayerOptions();

// Platform & Architecture
buildPlayerOptions.target = BuildTarget.StandaloneWindows;
buildPlayerOptions.subtarget = (int)StandaloneBuildSubtarget.Server;

// IL2CPP
EnableIl2Cpp(NamedBuildTarget.Server);

// Path and Scenes
buildPlayerOptions.locationPathName = path;
buildPlayerOptions.scenes = scenes;

// Build
BuildPipeline.BuildPlayer(buildPlayerOptions);

// Cleanup
CleanupDontship(path);
}

[MenuItem("MyTools/Build Linux IL2CPP Player")]
public static void BuildLinuxIl2cppPlayer()
{
var path = "artifacts/LinuxPlayer/Build.il2cpp-player.x86_64";

var buildPlayerOptions = new BuildPlayerOptions();

// Platform & Architecture
buildPlayerOptions.target = BuildTarget.StandaloneLinux64;
buildPlayerOptions.subtarget = (int)StandaloneBuildSubtarget.Player;

// IL2CPP
EnableIl2Cpp(NamedBuildTarget.Standalone);

// Path and Scenes
buildPlayerOptions.locationPathName = path;
buildPlayerOptions.scenes = scenes;

// Build
BuildPipeline.BuildPlayer(buildPlayerOptions);

// Cleanup
CleanupDontship(path);
}

[MenuItem("MyTools/Build Linux IL2CPP DedicatedServer")]
public static void BuildLinuxIl2cppServer()
{
var path = "artifacts/LinuxServer/Build.il2cpp-server.x86_64";

var buildPlayerOptions = new BuildPlayerOptions();

// Platform & Architecture
buildPlayerOptions.target = BuildTarget.StandaloneLinux64;
buildPlayerOptions.subtarget = (int)StandaloneBuildSubtarget.Server;

// IL2CPP
EnableIl2Cpp(NamedBuildTarget.Server);

// Path and Scenes
buildPlayerOptions.locationPathName = path;
buildPlayerOptions.scenes = scenes;

// Build
BuildPipeline.BuildPlayer(buildPlayerOptions);

// Cleanup
CleanupDontship(path);
}

/// <summary>
/// Enable IL2CPP ScriptingBackend
/// </summary>
/// <param name="buildTarget"></param>
private static void EnableIl2Cpp(NamedBuildTarget buildTarget)
{
// IL2CPP Code Generation = OptimizeSize => faster build than OptimizeSpeed
PlayerSettings.SetScriptingBackend(buildTarget, ScriptingImplementation.IL2CPP);
PlayerSettings.SetManagedStrippingLevel(buildTarget, ManagedStrippingLevel.Minimal);
PlayerSettings.SetIl2CppCompilerConfiguration(buildTarget, Il2CppCompilerConfiguration.Debug);
PlayerSettings.SetIl2CppCodeGeneration(buildTarget, Il2CppCodeGeneration.OptimizeSize);
}

/// <summary>
/// Enable Mono ScriptingBackend
/// </summary>
/// <param name="buildTarget"></param>
private static void EnableMono(NamedBuildTarget buildTarget)
{
PlayerSettings.SetScriptingBackend(buildTarget, ScriptingImplementation.Mono2x);
}

/// <summary>
/// Build Cleanup
/// </summary>
/// <param name="locationPathName"></param>
private static void CleanupDontship(string locationPathName)
{
// Cleanup IL2CPP debugger information directories
var dir = Path.GetDirectoryName(locationPathName);
var fileName = Path.GetFileNameWithoutExtension(locationPathName);
var removeTargets = new[] { $"{dir}/{fileName}_BackUpThisFolder_ButDontShipItWithYourGame" };

foreach (var target in removeTargets)
{
if (!Directory.Exists(target)) continue;
Directory.Delete(target, true);
}
}
}
Loading

0 comments on commit 9246d8d

Please sign in to comment.