Skip to content

Commit

Permalink
refactor: Prepared template testing (Unity-Technologies#218)
Browse files Browse the repository at this point in the history
* add patch file to replace "manifest.json" for testing template

* add template unittest

* exclude RenderStreaming test on MacOS

* move the place where web application executable file

* cp WebApp folder to resolve the path searching of the webserver

* added method "ChangeGraphicsApi"

* fixed build script to copy webserver

* fixed build error

* exclude macos platform from template test

* test

* test

* add meta

* test

* test

* remove trigger to stop template test

* fixed warning

* upgrade input system 1.0.0-preview.4

* fixed comment
  • Loading branch information
karasusan authored Jan 31, 2020
1 parent 4001722 commit 428044c
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 118 deletions.
5 changes: 2 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ indent_style = space

# Code files
[*.{cs,csx,cpp,h,ts}]
end_of_line = crlf
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
charset = utf-8-bom
charset = utf-8
trim_trailing_whitespace = true

###############################
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ MigrationBackup/
[Oo]bj/
[Bb]uild/

# Exclude Documentation folder
# Exclude folder
!Documentation~
!BuildScripts~

# Exclude webrtc source
Plugin/webrtc
Expand Down
4 changes: 2 additions & 2 deletions .yamato/upm-ci-publish-github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ publish_github_release:
- npm install github-release-cli -g
- github-release upload -o "Unity-Technologies" -r "UnityRenderStreaming" -t "%GIT_TAG%" -n "%GIT_TAG%" "upm-ci~/packages/com.unity.renderstreaming-%GIT_TAG%.tgz"
- github-release upload -o "Unity-Technologies" -r "UnityRenderStreaming" -t "%GIT_TAG%" -n "%GIT_TAG%" "upm-ci~/packages/com.unity.template.renderstreaming-%GIT_TAG%.tgz"
- github-release upload -o "Unity-Technologies" -r "UnityRenderStreaming" -t "%GIT_TAG%" -n "%GIT_TAG%" "Assets/bin~/webserver"
- github-release upload -o "Unity-Technologies" -r "UnityRenderStreaming" -t "%GIT_TAG%" -n "%GIT_TAG%" "Assets/bin~/webserver.exe"
- github-release upload -o "Unity-Technologies" -r "UnityRenderStreaming" -t "%GIT_TAG%" -n "%GIT_TAG%" "WebApp/bin~/webserver"
- github-release upload -o "Unity-Technologies" -r "UnityRenderStreaming" -t "%GIT_TAG%" -n "%GIT_TAG%" "WebApp/bin~/webserver.exe"
triggers:
tags:
only:
Expand Down
11 changes: 10 additions & 1 deletion .yamato/upm-ci-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ test_{{ platform.name }}_{{ editor.version }}:
image: {{ platform.image }}
flavor: {{ platform.flavor}}
commands:
- patch -u Packages/manifest.json < BuildScripts~/add_internal_registry_manifest.patch
{% if platform.name == "win" %}
- mkdir upm-ci~\templates\ProjectData~\WebApp
- xcopy WebApp upm-ci~\templates\ProjectData~\WebApp /s/e/i
{% else %}
- cp -r WebApp upm-ci~/templates/ProjectData~/
{% endif %}
- npm install upm-ci-utils -g --registry https://api.bintray.com/npm/unity/unity-npm
- upm-ci template test -u {{ editor.version }}
# TODO:: `upm-ci template test` is failed using the package on the internal registry.
# TODO:: `upm-ci template test` is failed using the package on the internal registry.
# triggers:
# branches:
# only:
Expand All @@ -49,6 +56,8 @@ test_{{ platform.name }}_{{ editor.version }}:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/upm-ci-template.yml#pack
- .yamato/upm-ci-webapp.yml#pack_{{ platform.name }}
- .yamato/upm-ci-webapp.yml#test_{{ platform.name }}
{% endfor %}
{% endfor %}

Expand Down
2 changes: 1 addition & 1 deletion .yamato/upm-ci-webapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pack_{{ platform.name }}:
artifacts:
packages:
paths:
- "Assets/bin~/**/*"
- "WebApp/bin~/**/*"
{% endfor %}

{% for platform in platforms %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using UnityEngine;

#if UNITY_2019_1 || UNITY_2019_2 //HDRP 5.x, 6.x
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
#else //HDRP 7.x and above
using UnityEngine.Rendering.HighDefinition;
#endif

[RequireComponent(typeof(Camera)), RequireComponent(typeof(HDAdditionalCameraData))]
[RequireComponent(typeof(Camera), typeof(HDAdditionalCameraData))]
public class HDRPRenderTextureBlitter : MonoBehaviour
{
[SerializeField] Camera m_rtCamera = null;
Expand All @@ -18,9 +18,9 @@ private void OnEnable() {
m_cam = GetComponent<Camera>();
m_hdData = GetComponent<HDAdditionalCameraData>();

//Render nothing
//Render nothing
m_cam.clearFlags = CameraClearFlags.Nothing;
m_cam.cullingMask = 0;
m_cam.cullingMask = 0;
m_hdData.fullscreenPassthrough = true;
m_hdData.customRender += BlitRenderStreamingRT;
}
Expand Down
15 changes: 15 additions & 0 deletions BuildScripts~/add_internal_registry_manifest.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- manifest.json
+++ manifest.json
@@ -1,4 +1,11 @@
-{
+{
+ "scopedRegistries": [{
+ "name": "Internal registry",
+ "url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates",
+ "scopes": [
+ "com.unity.webrtc"
+ ]
+ }],
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
107 changes: 10 additions & 97 deletions Packages/com.unity.renderstreaming/Editor/RenderStreamingMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEditor;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
Expand All @@ -8,115 +8,28 @@ namespace Unity.RenderStreaming.Editor
{
public static class RenderStreamingMenu
{
const string URLRoot = "https://github.com/Unity-Technologies/UnityRenderStreaming";
const string LatestKnownVersion = "1.1.1-preview";

// TODO::fix release process of webserver runtime.
const string PathWebAppForMac = "releases/download/{0}/webserver";
const string PathWebAppForLinux = "releases/download/{0}/webserver";
const string PathWebAppForWin = "releases/download/{0}/webserver.exe";
//

const string PathWebAppSourceCode = "tree/release/{0}/WebApp";
const string PathWebAppDocumentation = "blob/release/{0}/Packages/com.unity.template.renderstreaming/Documentation~/en/webserver.md";

[MenuItem("Edit/Render Streaming/Download web app")]
static void DownloadWebApp() {
RequestPackageVersion("com.unity.renderstreaming", (version) => { DownloadWebApp(version); });
}

static void DownloadWebApp(string version)

{
#if UNITY_EDITOR_WIN
var url = System.IO.Path.Combine(URLRoot, string.Format(PathWebAppForWin, version));
#elif UNITY_EDITOR_OSX
var url = System.IO.Path.Combine(URLRoot, string.Format(PathWebAppForMac, version));
#elif UNITY_EDITOR_LINUX
var url = System.IO.Path.Combine(URLRoot, string.Format(PathWebAppForLinux, version));
#endif
var client = new WebClient();
var filename = System.IO.Path.GetFileName(url);
var tmpFilePath = System.IO.Path.Combine(Application.temporaryCachePath, filename);

client.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
{
EditorUtility.ClearProgressBar();
if (e.Error != null) {
//Try downloading using the latest known version to work.
if (version != LatestKnownVersion) {
DownloadWebApp(LatestKnownVersion);
} else {
Debug.LogError("Failed downloading webserver from: " + url + " . Error: " + e.Error.ToString());
}
return;
}

if (!System.IO.File.Exists(tmpFilePath))
{
Debug.LogErrorFormat("Download failed. url:{0}", url);
return;
}

static void DownloadWebAppFromMenu() {
WebAppDownloader.GetPackageVersion("com.unity.renderstreaming", (version) => {
var dstPath = EditorUtility.OpenFolderPanel("Select download folder", "", "");
if (string.IsNullOrEmpty(dstPath))
{
return;
}
dstPath = System.IO.Path.Combine(dstPath, filename);
if (System.IO.File.Exists(dstPath))
{
System.IO.File.Delete(dstPath);
}
System.IO.File.Move(tmpFilePath, dstPath);
EditorUtility.RevealInFinder(dstPath);
};
client.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
{
var progress = e.ProgressPercentage / 100f;
if(EditorUtility.DisplayCancelableProgressBar("Downloading", url, progress))
{
client.CancelAsync();
}
};
client.DownloadFileAsync(new System.Uri(url), tmpFilePath);

}

static void RequestPackageVersion(string packageName, System.Action<string> callback)
{
// request package list to get package version
RequestJobManager.CreateListRequest(false, true, (req) =>
{
var packageInfo = req.FindPackage(packageName);
if (null == packageInfo)
{
Debug.LogErrorFormat("Not found package \"{0}\"", packageName);
return;
}
callback(packageInfo.version);
}, null);
WebAppDownloader.DownloadWebApp(version, dstPath);
});
}

[MenuItem("Edit/Render Streaming/Show web app documentation")]
static void ShowWepAppDocumentation()
{
RequestPackageVersion("com.unity.renderstreaming", (version) =>
{
var pattern = @"\d+.\d+.\d+";
var result = System.Text.RegularExpressions.Regex.Match(version, pattern);
var url = System.IO.Path.Combine(URLRoot, string.Format(PathWebAppDocumentation, result.Value));
WebAppDownloader.GetPackageVersion("com.unity.renderstreaming", (version) => {
var url = WebAppDownloader.GetURLDocumentation(version);
Application.OpenURL(url);
});
}

[MenuItem("Edit/Render Streaming/Show web app source code")]
static void ShowWepAppSourceCode()
{
RequestPackageVersion("com.unity.renderstreaming", (version) =>
{
var pattern = @"\d+.\d+.\d+";
var result = System.Text.RegularExpressions.Regex.Match(version, pattern);
var url = System.IO.Path.Combine(URLRoot, string.Format(PathWebAppSourceCode, result.Value));
WebAppDownloader.GetPackageVersion("com.unity.renderstreaming", (version) => {
var url = WebAppDownloader.GetURLSourceCode(version);
Application.OpenURL(url);
});
}
Expand Down
122 changes: 122 additions & 0 deletions Packages/com.unity.renderstreaming/Editor/WebAppDownloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
using System.Net;

namespace Unity.RenderStreaming.Editor
{
public static class WebAppDownloader
{
const string URLRoot = "https://github.com/Unity-Technologies/UnityRenderStreaming";
const string LatestKnownVersion = "1.1.1-preview";

// TODO::fix release process of webserver runtime.
const string PathWebAppForMac = "releases/download/{0}/webserver";
const string PathWebAppForLinux = "releases/download/{0}/webserver";
const string PathWebAppForWin = "releases/download/{0}/webserver.exe";
//

const string PathWebAppSourceCode = "tree/release/{0}/WebApp";
const string PathWebAppDocumentation = "blob/release/{0}/Packages/com.unity.template.renderstreaming/Documentation~/en/webserver.md";


static string GetWebAppURL(string version)
{
#if UNITY_EDITOR_WIN
var url = System.IO.Path.Combine(URLRoot, string.Format(PathWebAppForWin, version));
#elif UNITY_EDITOR_OSX
var url = System.IO.Path.Combine(URLRoot, string.Format(PathWebAppForMac, version));
#elif UNITY_EDITOR_LINUX
var url = System.IO.Path.Combine(URLRoot, string.Format(PathWebAppForLinux, version));
#endif
return url;
}

public static string GetURLDocumentation(string version)
{
var pattern = @"\d+.\d+.\d+";
var result = System.Text.RegularExpressions.Regex.Match(version, pattern);
return System.IO.Path.Combine(URLRoot, string.Format(PathWebAppDocumentation, result.Value));
}

public static string GetURLSourceCode(string version)
{
var pattern = @"\d+.\d+.\d+";
var result = System.Text.RegularExpressions.Regex.Match(version, pattern);
return System.IO.Path.Combine(URLRoot, string.Format(PathWebAppSourceCode, result.Value));
}

public static void DownloadCurrentVersionWebApp(string dstPath) {
GetPackageVersion("com.unity.renderstreaming", (version) => {
DownloadWebApp(version, dstPath);
});
}

public static void DownloadWebApp(string version, string dstPath)
{
var url = GetWebAppURL(version);
var client = new WebClient();
var filename = System.IO.Path.GetFileName(url);
var tmpFilePath = System.IO.Path.Combine(Application.temporaryCachePath, filename);

client.DownloadFileCompleted += (sender, e) =>
{
EditorUtility.ClearProgressBar();
if (e.Error != null) {
//Try downloading using the latest known version to work.
if (version != LatestKnownVersion) {
DownloadWebApp(LatestKnownVersion, dstPath);
} else {
Debug.LogError("Failed downloading webserver from: " + url + " . Error: " + e.Error.ToString());
}
return;
}

if (!System.IO.File.Exists(tmpFilePath))
{
Debug.LogErrorFormat("Download failed. url:{0}", url);
return;
}

if (string.IsNullOrEmpty(dstPath))
{
return;
}
dstPath = System.IO.Path.Combine(dstPath, filename);
if (System.IO.File.Exists(dstPath))
{
System.IO.File.Delete(dstPath);
}
System.IO.File.Move(tmpFilePath, dstPath);
EditorUtility.RevealInFinder(dstPath);
};
client.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
{
var progress = e.ProgressPercentage / 100f;
if(EditorUtility.DisplayCancelableProgressBar("Downloading", url, progress))
{
client.CancelAsync();
}
};
client.DownloadFileAsync(new System.Uri(url), tmpFilePath);

}

public static void GetPackageVersion(string packageName, System.Action<string> callback)
{
// request package list to get package version
RequestJobManager.CreateListRequest(false, true, (req) =>
{
var packageInfo = req.FindPackage(packageName);
if (null == packageInfo)
{
Debug.LogErrorFormat("Not found package \"{0}\"", packageName);
return;
}
callback(packageInfo.version);
}, null);
}
}
}

11 changes: 11 additions & 0 deletions Packages/com.unity.renderstreaming/Editor/WebAppDownloader.cs.meta

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

2 changes: 1 addition & 1 deletion Packages/com.unity.renderstreaming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "This is HDRP sample scene project integrated with Unity Render Streaming technology.\n\nAlong with its signaling web server, you could play around the scene in any webrtc supported web browser.",
"dependencies": {
"com.unity.webrtc": "1.1.0-preview.2",
"com.unity.inputsystem": "0.9.6-preview"
"com.unity.inputsystem": "1.0.0-preview.4"
},
"samples": [ {
"displayName": "HDRP",
Expand Down
2 changes: 1 addition & 1 deletion Packages/com.unity.template.renderstreaming/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.unity.template.renderstreaming",
"displayName": "Unity Render Streaming Template",
"displayName": "Render Streaming Template",
"version": "1.1.1-preview",
"type": "template",
"unity": "2019.3",
Expand Down
Loading

0 comments on commit 428044c

Please sign in to comment.