-
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,74 @@ | ||
/* | ||
* 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> | ||
/// NatCorder settings from the current project settings. | ||
/// </summary> | ||
internal static NatCorderSettings CurrentSettings { | ||
get { | ||
var settings = ScriptableObject.CreateInstance<NatCorderSettings>(); | ||
settings.token = SessionState.GetString(tokenKey, string.Empty); | ||
return settings; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Create NatCorder settings. | ||
/// </summary> | ||
/// <param name="platform">NatML platform identifier.</param> | ||
/// <param name="bundle">NatML app bundle.</param> | ||
/// <param name="accessKey">NatML access key.</param> | ||
internal static NatCorderSettings CreateSettings (string platform, string bundle, string accessKey) { | ||
var input = new CreateMediaSessionRequest.Input { | ||
api = NatCorderSettings.API, | ||
version = NatCorderSettings.Version, | ||
platform = platform, | ||
bundle = bundle, | ||
}; | ||
var session = Task.Run(() => NatMLHub.CreateMediaSession(input, accessKey)).Result; | ||
var settings = ScriptableObject.CreateInstance<NatCorderSettings>(); | ||
settings.token = session.token; | ||
return settings; | ||
} | ||
#endregion | ||
|
||
|
||
#region --Operations-- | ||
private static string tokenKey => $"{NatCorderSettings.API}.token"; | ||
|
||
[InitializeOnLoadMethod] | ||
private static void OnLoad () { | ||
NatCorderSettings.Instance = CurrentSettings; | ||
HubSettings.OnUpdateSettings += OnUpdateHubSettings; | ||
} | ||
|
||
private static void OnUpdateHubSettings (HubSettings hubSettings) { | ||
try { | ||
var settings = CreateSettings(NatMLHub.CurrentPlatform, NatMLHub.GetEditorBundle(), hubSettings.AccessKey); | ||
SessionState.SetString(tokenKey, settings.token); | ||
} catch (Exception ex) { | ||
SessionState.EraseString(tokenKey); | ||
Debug.LogWarning($"NatCorder Error: {ex.InnerException.Message}"); | ||
} | ||
NatCorderSettings.Instance = CurrentSettings; | ||
} | ||
#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,50 @@ | ||
/* | ||
* NatCorder | ||
* Copyright (c) 2022 NatML Inc. All rights reserved. | ||
*/ | ||
|
||
namespace NatML.Recorders.Editor { | ||
|
||
using System; | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEditor.Build.Reporting; | ||
using UnityEngine; | ||
using Hub; | ||
using Hub.Editor; | ||
using Hub.Internal; | ||
using Internal; | ||
|
||
internal sealed class NatCorderSettingsEmbed : 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 platform = ToPlatform(report.summary.platform); | ||
var bundle = BundleOverride?.identifier ?? NatMLHub.GetAppBundle(platform); | ||
var accessKey = HubSettings.Instance.AccessKey; | ||
var settings = NatCorderProjectSettings.CurrentSettings; | ||
try { | ||
settings = NatCorderProjectSettings.CreateSettings(platform, bundle, accessKey); | ||
} 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,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.