Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Rebuild Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
olokobayusuf committed Aug 30, 2022
0 parents commit 108abc5
Show file tree
Hide file tree
Showing 109 changed files with 4,217 additions and 0 deletions.
Binary file added .media/key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
275 changes: 275 additions & 0 deletions Changelog.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Changelog.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Editor/NatCorderMenu.cs
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");
}
}
11 changes: 11 additions & 0 deletions Editor/NatCorderMenu.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions Editor/NatCorderProjectSettings.cs
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
}
}
11 changes: 11 additions & 0 deletions Editor/NatCorderProjectSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Editor/NatML.Recorders.Editor.asmdef
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
}
7 changes: 7 additions & 0 deletions Editor/NatML.Recorders.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions Editor/SettingsEmbedHelper.cs
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);
}
}
}
11 changes: 11 additions & 0 deletions Editor/SettingsEmbedHelper.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Editor/WebGLBuildHelper.cs
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;
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/WebGLBuildHelper.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 108abc5

Please sign in to comment.