Coder Social home page Coder Social logo

cake.unity3d's Introduction

Cake.Unity3D

About

Unity3D build support for Cake (https://github.com/cake-build/cake).

GitHub Nuget

Methods

/// <summary>
/// Build a provided Unity3D project with the specified build options.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectFolder">The absolute path to the Unity3D project to build.</param>
/// <param name="options">The build options to use when building the project.</param>
public static void BuildUnity3DProject(this ICakeContext context, FilePath projectFolder, Unity3DBuildOptions options)
/// <summary>
/// Test a provided Unity3D project with the specified test options.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectFolder">The absolute path to the Unity3D project to test.</param>
/// <param name="options">The test options to use when testing the project.</param>
public static void TestUnity3DProject(this ICakeContext context, FilePath projectFolder, Unity3DTestOptions options)
/// <summary>
/// Locate all installed version of Unity3D.
/// Warning: This currently only works for Windows and has only been tested on Windows 10.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <returns>A dictionary containing 'key' Unity version, 'value' absolute install path</returns>
public static Dictionary<string, string> GetAllUnityInstalls(this ICakeContext context)
/// <summary>
/// Try and get the absolute install path for a specific Unity3D version.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="version">The version to try and locate.</param>
/// <param name="installPath">If found the absolute install path will be written to this out variable</param>
/// <returns>True if the editor version was found, false otherwise.</returns>
public static bool TryGetUnityInstall(this ICakeContext context, string version, out string installPath)
/// <summary>
/// Try and get the version of Unity3D a specified project uses.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectPath">The absolute path to the Unity3D project we want to get the Unity3D version for.</param>
/// <param name="unityVersion">If found the name of the Unity3D version used for the project.</param>
/// <returns>True if the editor version was found, false otherwise.</returns>
public static bool TryGetUnityVersionForProject(this ICakeContext context, string projectPath, out string unityVersion)

Example

Building a Project

#addin nuget:?package=Cake.Unity3D

var target = Argument("target", "Build");

Task("Build")
  .Does(() =>
{
	// Presuming the build.cake file is within the Unity3D project folder.
	var projectPath = System.IO.Path.GetFullPath("./");
	
	// The location we want the build application to go
	var outputPath = System.IO.Path.Combine(projectPath, "_build", "x64", "example.exe");
	
	// Get the version of Unity used by the Unity project
	string unityEditorVersion;
	if (!TryGetUnityVersionForProject(projectPath, out unityEditorVersion))
	{
		Error($"Failed to find Unity version for the project '{projectPath}'");
		return;
	}
	
	// Get the absolute path to the Unity3D editor.
	string unityEditorLocation;
	if (!TryGetUnityInstall(unityEditorVersion, out unityEditorLocation)) 
	{
		Error($"Failed to find '{unityEditorVersion}' install location");
		return;
	}
	
	// Create our build options.
	var options = new Unity3DBuildOptions()
	{
		Platform = Unity3DBuildPlatform.StandaloneWindows64,
		OutputPath = outputPath,
		UnityEditorLocation = unityEditorLocation,
		ForceScriptInstall = true,
		BuildVersion = "1.0.0"
	};
	
	// Perform the Unity3d build.
	BuildUnity3DProject(projectPath, options);
});

RunTarget(target);

Testing a Project

#addin nuget:?package=Cake.Unity3D

var target = Argument("target", "Test");

Task("Test")
  .Does(() =>
{
	// Presuming the build.cake file is within the Unity3D project folder.
	var projectPath = System.IO.Path.GetFullPath("./");
	
	// The location we want the test results to be output to (if this isn't specified the file will be output to 'test_results.xml' in the root Unity Project folder)
	var testResultsOutputPath = System.IO.Path.Combine(projectPath, "_test_results.xml");
	
	// Get the version of Unity used by the Unity project
	string unityEditorVersion;
	if (!TryGetUnityVersionForProject(projectPath, out unityEditorVersion))
	{
		Error($"Failed to find Unity version for the project '{projectPath}'");
		return;
	}
	
	// Get the absolute path to the Unity3D editor.
	string unityEditorLocation;
	if (!TryGetUnityInstall(unityEditorVersion, out unityEditorLocation)) 
	{
		Error($"Failed to find '{unityEditorVersion}' install location");
		return;
	}
	
	// Create our test options.
	var options = new Unity3DTestOptions()
	{
		TestMode = Unity3DTestMode.EditMode,
		TestResultOutputPath = testResultsOutputPath,
		UnityEditorLocation = unityEditorLocation
	};
	
	// Perform the Unity3d test.
	TestUnity3DProject(projectPath, options);
});

RunTarget(target);

Supported Platforms

Executing Platforms

Currently the addon only works on Windows and has only been tested on Windows 10. This is due to how the 'TryGetUnityInstall' works. What it does is look at all shortcuts in your Windows start menu and locate the Unity3D installs from that. In theory, if you just set the 'UnityEditorLocation' build option to the absolute path to your Unity3D install on Mac or Linux, this should also work.

Build Platforms

  • StandaloneWindows64
  • StandaloneWindows
  • WebGL

In theory, all platforms that the executing platform supports should work. However, I haven't test any apart from the above list.

cake.unity3d's People

Contributors

gep13 avatar jericho avatar samoatesgames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cake.unity3d's Issues

Build scenes

Hi,

is there a way to specify which scenes do into the build?

Add cake-contrib user

First of all, I wanted to thank you for adding to the Cake community by adding this addin.

I was just wondering if you had seen this blog post:

http://cakebuild.net/blog/2016/08/cake-contribution-organization

We are currently going through a process of increasing the visibility of addins, and also trying to ensure their long term maintainability.

To that end, we are asking addin creators to add the cake-contrib user on NuGet as a co-owner (this can be done through the NuGet website by clicking on Manage Owners on the package page).

Would you be interested in doing this? If you have any questions about this, please let me know. There was some initial concern that the Cake Team were trying to "take over" packages, and that couldn't be further from the truth, and if you have this concern, or others, I would like to address them.

Thanks!

Recommended changes resulting from automated audit

We performed an automated audit of your Cake addin and found that it does not follow all the best practices.

We encourage you to make the following modifications:

  • You are currently referencing Cake.Core 0.26.0. Please upgrade to 0.33.0
  • You are currently referencing Cake.Common 0.26.0. Please upgrade to 0.33.0
  • The nuget package for your addin should use the cake-contrib icon. Specifically, your addin's .csproj should have a line like this: <PackageIconUrl>https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png</PackageIconUrl>.

Apologies if this is already being worked on, or if there are existing open issues, this issue was created based on what is currently published for this package on NuGet.

This issue was created by a tool: Cake.AddinDiscoverer version 3.12.1

Use on Mac OSX

Info for anyone looking to use the build function only on a Mac:

I was able to get this working by specifying the Editor location in the Unity3DBuildOptions rather than using the helper functions.
You'll also need to trick the system into finding the editor log file by setting the LocalAppData Environment Variable and symlinking the log file to a new location.

export LocalAppData=~/Library/Logs
ln -s ~/Library/Logs/Unity/Editor.log ~/Library/Logs/Unity/Editor/Editor.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.