-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#if UNITY_CLOUD_BUILD | ||
using UnityEditor; | ||
|
||
// TODO do we still need this? | ||
|
||
public class DisableBurstFromMenu | ||
{ | ||
/// This method is needed to disable Burst compilation on windows for our cloudbuild tests. | ||
/// Barracuda 0.4.0-preview depends on a version of Burst (1.1.1) which does not allow | ||
/// users to disable burst compilation on a per platform basis. The burst version 1.3.0-preview-1 | ||
/// allows for cross compilation, but is not released yet. | ||
/// | ||
/// We will be able to remove this when | ||
/// 1. Barracuda updates burst 1.3.0-preview-1 or | ||
/// 2. We update our edior version for our tests to 2019.1+ | ||
public static void DisableBurstCompilation() | ||
{ | ||
EditorApplication.ExecuteMenuItem("Jobs/Burst/Enable Compilation"); | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Unity.MLAgents | ||
{ | ||
public class SampleExporter | ||
{ | ||
const string k_MLAgentsSampleFile = "mlagents-sample.json"; | ||
const string k_PackageSampleFile = ".sample.json"; | ||
const string k_MLAgentsDir = "ML-Agents"; | ||
const string k_MLAgentsExamplesDir = "Examples"; | ||
const string k_MLAgentsPackageName = "com.unity.ml-agents"; | ||
const string k_MLAgentsSamplesDirName = "Samples"; | ||
const string k_MLAgentsScriptsDirName = "Scripts"; | ||
|
||
struct MLAgentsSampleJson | ||
{ | ||
#pragma warning disable 649 | ||
public string displayName; | ||
public string description; | ||
// ReSharper disable once CollectionNeverUpdated.Local | ||
public List<string> scenes; | ||
#pragma warning restore 649 | ||
} | ||
|
||
struct PackageSampleJson | ||
{ | ||
public string displayName; | ||
public string description; | ||
} | ||
|
||
public static void ExportCuratedSamples() | ||
{ | ||
var oldBurst = EditorPrefs.GetBool("BurstCompilation"); | ||
EditorPrefs.SetBool("BurstCompilation", false); | ||
try | ||
{ | ||
// Path to Project/Assets | ||
var assetsDir = Application.dataPath; | ||
var repoRoot = Directory.GetParent(Directory.GetParent(assetsDir).FullName).FullName; | ||
|
||
// Top level of where to store the samples | ||
var samplesDir = Path.Combine( | ||
repoRoot, | ||
k_MLAgentsPackageName, | ||
k_MLAgentsSamplesDirName); | ||
|
||
if (!Directory.Exists(samplesDir)) | ||
{ | ||
Directory.CreateDirectory(samplesDir); | ||
} | ||
|
||
// Path to the examples dir in the project | ||
var examplesDir = Path.Combine(Application.dataPath, k_MLAgentsDir, k_MLAgentsExamplesDir); | ||
foreach (var exampleDirectory in Directory.GetDirectories(examplesDir)) | ||
{ | ||
var mlAgentsSamplePath = Path.Combine(exampleDirectory, k_MLAgentsSampleFile); | ||
if (File.Exists(mlAgentsSamplePath)) | ||
{ | ||
var sampleJson = JsonConvert.DeserializeObject<MLAgentsSampleJson>(File.ReadAllText(mlAgentsSamplePath)); | ||
Debug.Log(JsonConvert.SerializeObject(sampleJson)); | ||
foreach (var scene in sampleJson.scenes) | ||
{ | ||
var scenePath = Path.Combine(exampleDirectory, scene); | ||
if (File.Exists(scenePath)) | ||
{ | ||
// Create a Sample Directory | ||
var currentSampleDir = Directory.CreateDirectory(Path.Combine(samplesDir, | ||
Path.GetFileNameWithoutExtension(scenePath))); | ||
|
||
|
||
var scriptsPath = Path.Combine(exampleDirectory, k_MLAgentsScriptsDirName); | ||
Debug.Log($"Scene Path: {scenePath}"); | ||
var assets = new List<string> { scenePath.Substring(scenePath.IndexOf("Assets")) }; | ||
if (!Directory.Exists(Path.Combine(scriptsPath))) | ||
{ | ||
scriptsPath = exampleDirectory; | ||
} | ||
|
||
scriptsPath = scriptsPath.Substring(scriptsPath.IndexOf("Assets")); | ||
foreach (var guid in AssetDatabase.FindAssets("t:Script", new[] { scriptsPath })) | ||
{ | ||
var path = AssetDatabase.GUIDToAssetPath(guid); | ||
assets.Add(path); | ||
Debug.Log($"Adding Asset: {path}"); | ||
} | ||
|
||
var packageFilePath = Path.GetFileNameWithoutExtension(scenePath) + ".unitypackage"; | ||
AssetDatabase.ExportPackage(assets.ToArray(), | ||
Path.Combine(Application.dataPath, packageFilePath), | ||
ExportPackageOptions.IncludeDependencies | ExportPackageOptions.Recurse); | ||
|
||
// Move the .unitypackage into the samples folder. | ||
var packageFileFullPath = Path.Combine(Application.dataPath, packageFilePath); | ||
|
||
var packageInSamplePath = Path.Combine(currentSampleDir.FullName, packageFilePath); | ||
Debug.Log($"Moving {packageFileFullPath} to {packageInSamplePath}"); | ||
File.Move(packageFileFullPath, packageInSamplePath); | ||
|
||
// write the .sample.json file to the sample directory | ||
File.WriteAllText(Path.Combine(currentSampleDir.FullName, k_PackageSampleFile), | ||
JsonConvert.SerializeObject(new PackageSampleJson | ||
{ | ||
description = sampleJson.description, | ||
displayName = sampleJson.displayName | ||
})); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.Log(e); | ||
EditorApplication.Exit(1); | ||
} | ||
EditorPrefs.SetBool("BurstCompilation", oldBurst); | ||
EditorApplication.Exit(0); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEditor.Build.Reporting; | ||
|
||
namespace Unity.MLAgents | ||
{ | ||
public class StandaloneBuildTest | ||
{ | ||
const string k_OutputCommandLineFlag = "--mlagents-build-output-path"; | ||
const string k_SceneCommandLineFlag = "--mlagents-build-scene-path"; | ||
private const string k_BuildTargetFlag = "--mlagents-build-target"; | ||
|
||
public static void BuildStandalonePlayerOSX() | ||
{ | ||
// Read commandline arguments for options | ||
var outputPath = "testPlayer"; | ||
var scenePath = "Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity"; | ||
var buildTarget = BuildTarget.StandaloneOSX; | ||
|
||
var args = Environment.GetCommandLineArgs(); | ||
for (var i = 0; i < args.Length - 1; i++) | ||
{ | ||
if (args[i] == k_OutputCommandLineFlag) | ||
{ | ||
outputPath = args[i + 1]; | ||
Debug.Log($"Overriding output path to {outputPath}"); | ||
} | ||
else if (args[i] == k_SceneCommandLineFlag) | ||
{ | ||
scenePath = args[i + 1]; | ||
} | ||
else if (args[i] == k_BuildTargetFlag) | ||
{ | ||
buildTarget = (BuildTarget)Enum.Parse(typeof(BuildTarget), args[i + 1], ignoreCase: true); | ||
} | ||
} | ||
|
||
string[] scenes = { scenePath }; | ||
var buildResult = BuildPipeline.BuildPlayer( | ||
scenes, | ||
outputPath, | ||
buildTarget, | ||
BuildOptions.Development | ||
); | ||
var isOk = buildResult.summary.result == BuildResult.Succeeded; | ||
var error = ""; | ||
foreach (var stepInfo in buildResult.steps) | ||
{ | ||
foreach (var msg in stepInfo.messages) | ||
{ | ||
if (msg.type != LogType.Log && msg.type != LogType.Warning) | ||
{ | ||
error += msg.content + "\n"; | ||
} | ||
} | ||
} | ||
if (isOk) | ||
{ | ||
EditorApplication.Exit(0); | ||
} | ||
else | ||
{ | ||
Console.Error.WriteLine(error); | ||
EditorApplication.Exit(1); | ||
|
||
} | ||
Debug.Log(error); | ||
|
||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.