-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
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,27 @@ | ||
/* | ||
* NatCorder | ||
* Copyright (c) 2022 NatML Inc. All rights reserved. | ||
*/ | ||
|
||
namespace NatML.Recorders.Editor { | ||
|
||
using UnityEditor; | ||
using Internal; | ||
|
||
internal static class NatCorderMenu { | ||
|
||
private const int BasePriority = 0; | ||
|
||
[MenuItem(@"NatML/NatCorder " + NatCorderSettings.Version, false, BasePriority)] | ||
private static void Version () { } | ||
|
||
[MenuItem(@"NatML/NatCorder " + NatCorderSettings.Version, true, BasePriority)] | ||
private static bool DisableVersion () => false; | ||
|
||
[MenuItem(@"NatML/View NatCorder Docs", false, BasePriority + 1)] | ||
private static void OpenDocs () => Help.BrowseURL(@"https://docs.natml.ai/natcorder"); | ||
|
||
[MenuItem(@"NatML/Open a NatCorder Issue", false, BasePriority + 2)] | ||
private static void OpenIssue () => Help.BrowseURL(@"https://github.com/natmlx/NatCorder"); | ||
} | ||
} |
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,58 @@ | ||
/* | ||
* NatCorder | ||
* Copyright (c) 2022 NatML Inc. All rights reserved. | ||
*/ | ||
|
||
namespace NatML.Recorders.Editor { | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
using UnityEditor; | ||
using Hub; | ||
using Hub.Internal; | ||
using Hub.Requests; | ||
using Internal; | ||
|
||
[FilePath(@"ProjectSettings/NatCorder.asset", FilePathAttribute.Location.ProjectFolder)] | ||
internal sealed class NatCorderProjectSettings : ScriptableSingleton<NatCorderProjectSettings> { | ||
|
||
#region --Client API-- | ||
/// <summary> | ||
/// Create NatCorder settings from the current project settings. | ||
/// </summary> | ||
internal static NatCorderSettings CreateSettings () { | ||
var settings = ScriptableObject.CreateInstance<NatCorderSettings>(); | ||
settings.token = SessionState.GetString(tokenKey, string.Empty); | ||
return settings; | ||
} | ||
#endregion | ||
|
||
#region --Operations-- | ||
private static string tokenKey => $"{NatCorderSettings.API}.token"; | ||
|
||
[InitializeOnLoadMethod] | ||
private static void OnLoad () { | ||
NatCorderSettings.Instance = CreateSettings(); | ||
HubSettings.OnUpdateSettings += OnUpdateHubSettings; | ||
} | ||
|
||
private static void OnUpdateHubSettings (HubSettings settings) { | ||
var input = new CreateAppTokenRequest.Input { | ||
api = NatCorderSettings.API, | ||
version = NatCorderSettings.Version, | ||
platform = NatMLHub.CurrentPlatform, | ||
bundle = HubSettings.EditorBundle | ||
}; | ||
try { | ||
var token = Task.Run(() => NatMLHub.CreateAppToken(input, settings.AccessKey)).Result; | ||
SessionState.SetString(tokenKey, token); | ||
} catch (Exception ex) { | ||
SessionState.EraseString(tokenKey); | ||
Debug.LogWarning($"NatCorder Error: {ex.InnerException.Message}"); | ||
} | ||
NatCorderSettings.Instance = CreateSettings(); | ||
} | ||
#endregion | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"name": "NatML.Recorders.Editor", | ||
"references": [ | ||
"NatML.Hub", | ||
"NatML.Hub.Editor", | ||
"NatML.Recorders" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
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,59 @@ | ||
/* | ||
* NatCorder | ||
* Copyright (c) 2022 NatML Inc. All rights reserved. | ||
*/ | ||
|
||
namespace NatML.Recorders.Editor { | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using UnityEditor; | ||
using UnityEditor.Build.Reporting; | ||
using UnityEngine; | ||
using Hub; | ||
using Hub.Editor; | ||
using Hub.Internal; | ||
using Hub.Requests; | ||
using Internal; | ||
|
||
internal sealed class SettingsEmbedHelper : BuildEmbedHelper<NatCorderSettings> { | ||
|
||
protected override BuildTarget[] SupportedTargets => new [] { | ||
BuildTarget.Android, | ||
BuildTarget.iOS, | ||
BuildTarget.StandaloneOSX, | ||
BuildTarget.StandaloneWindows, | ||
BuildTarget.StandaloneWindows64, | ||
BuildTarget.WebGL, | ||
}; | ||
private const string CachePath = @"Assets/NMLBuildCache"; | ||
|
||
protected override NatCorderSettings[] CreateEmbeds (BuildReport report) { | ||
var webIdentifier = $"{Application.productName.Replace(' ', '-')}-{Application.version.Replace(' ', '-')}"; | ||
var identifier = report.summary.platform == BuildTarget.WebGL ? webIdentifier : Application.identifier; | ||
var input = new CreateAppTokenRequest.Input { | ||
api = NatCorderSettings.API, | ||
version = NatCorderSettings.Version, | ||
platform = ToPlatform(report.summary.platform), | ||
bundle = BundleOverride?.identifier ?? identifier | ||
}; | ||
var accessKey = HubSettings.Instance.AccessKey; | ||
var settings = NatCorderProjectSettings.CreateSettings(); | ||
settings.token = null; | ||
try { | ||
settings.token = Task.Run(() => NatMLHub.CreateAppToken(input, accessKey)).Result; | ||
} catch (Exception ex) { | ||
Debug.LogWarning($"NatCorder Error: {ex.InnerException.Message}"); | ||
} | ||
Directory.CreateDirectory(CachePath); | ||
AssetDatabase.CreateAsset(settings, $"{CachePath}/NatCorder.asset"); | ||
return new [] { settings }; | ||
} | ||
|
||
protected override void ClearEmbeds (BuildReport report) { | ||
base.ClearEmbeds(report); | ||
AssetDatabase.DeleteAsset(CachePath); | ||
} | ||
} | ||
} |
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,29 @@ | ||
/* | ||
* NatCorder | ||
* Copyright (c) 2022 NatML Inc. All rights reserved. | ||
*/ | ||
|
||
namespace NatML.Recorders.Editor { | ||
|
||
using UnityEditor; | ||
using UnityEditor.Build; | ||
using UnityEditor.Build.Reporting; | ||
|
||
internal sealed class WebGLBuildHelper : IPreprocessBuildWithReport { | ||
|
||
public int callbackOrder => 0; | ||
private readonly string[] EM_ARGS = new [] { | ||
@"--bind", | ||
}; | ||
|
||
void IPreprocessBuildWithReport.OnPreprocessBuild (BuildReport report) { | ||
if (report.summary.platform != BuildTarget.WebGL) | ||
return; | ||
foreach (var arg in EM_ARGS) { | ||
var standaloneArg = $" {arg} "; | ||
if (!PlayerSettings.WebGL.emscriptenArgs.Contains(standaloneArg)) | ||
PlayerSettings.WebGL.emscriptenArgs += standaloneArg; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.