1
- using UnityEditor ;
1
+ using UnityEditor ;
2
2
using UnityEditor . PackageManager ;
3
3
using UnityEditor . PackageManager . Requests ;
4
4
using UnityEngine ;
@@ -8,115 +8,28 @@ namespace Unity.RenderStreaming.Editor
8
8
{
9
9
public static class RenderStreamingMenu
10
10
{
11
- const string URLRoot = "https://github.com/Unity-Technologies/UnityRenderStreaming" ;
12
- const string LatestKnownVersion = "1.1.1-preview" ;
13
-
14
- // TODO::fix release process of webserver runtime.
15
- const string PathWebAppForMac = "releases/download/{0}/webserver" ;
16
- const string PathWebAppForLinux = "releases/download/{0}/webserver" ;
17
- const string PathWebAppForWin = "releases/download/{0}/webserver.exe" ;
18
- //
19
-
20
- const string PathWebAppSourceCode = "tree/release/{0}/WebApp" ;
21
- const string PathWebAppDocumentation = "blob/release/{0}/Packages/com.unity.template.renderstreaming/Documentation~/en/webserver.md" ;
22
-
23
11
[ MenuItem ( "Edit/Render Streaming/Download web app" ) ]
24
- static void DownloadWebApp ( ) {
25
- RequestPackageVersion ( "com.unity.renderstreaming" , ( version ) => { DownloadWebApp ( version ) ; } ) ;
26
- }
27
-
28
- static void DownloadWebApp ( string version )
29
-
30
- {
31
- #if UNITY_EDITOR_WIN
32
- var url = System . IO . Path . Combine ( URLRoot , string . Format ( PathWebAppForWin , version ) ) ;
33
- #elif UNITY_EDITOR_OSX
34
- var url = System . IO . Path . Combine ( URLRoot , string . Format ( PathWebAppForMac , version ) ) ;
35
- #elif UNITY_EDITOR_LINUX
36
- var url = System . IO . Path . Combine ( URLRoot , string . Format ( PathWebAppForLinux , version ) ) ;
37
- #endif
38
- var client = new WebClient ( ) ;
39
- var filename = System . IO . Path . GetFileName ( url ) ;
40
- var tmpFilePath = System . IO . Path . Combine ( Application . temporaryCachePath , filename ) ;
41
-
42
- client . DownloadFileCompleted += ( object sender , System . ComponentModel . AsyncCompletedEventArgs e ) =>
43
- {
44
- EditorUtility . ClearProgressBar ( ) ;
45
- if ( e . Error != null ) {
46
- //Try downloading using the latest known version to work.
47
- if ( version != LatestKnownVersion ) {
48
- DownloadWebApp ( LatestKnownVersion ) ;
49
- } else {
50
- Debug . LogError ( "Failed downloading webserver from: " + url + " . Error: " + e . Error . ToString ( ) ) ;
51
- }
52
- return ;
53
- }
54
-
55
- if ( ! System . IO . File . Exists ( tmpFilePath ) )
56
- {
57
- Debug . LogErrorFormat ( "Download failed. url:{0}" , url ) ;
58
- return ;
59
- }
60
-
12
+ static void DownloadWebAppFromMenu ( ) {
13
+ WebAppDownloader . GetPackageVersion ( "com.unity.renderstreaming" , ( version ) => {
61
14
var dstPath = EditorUtility . OpenFolderPanel ( "Select download folder" , "" , "" ) ;
62
- if ( string . IsNullOrEmpty ( dstPath ) )
63
- {
64
- return ;
65
- }
66
- dstPath = System . IO . Path . Combine ( dstPath , filename ) ;
67
- if ( System . IO . File . Exists ( dstPath ) )
68
- {
69
- System . IO . File . Delete ( dstPath ) ;
70
- }
71
- System . IO . File . Move ( tmpFilePath , dstPath ) ;
72
- EditorUtility . RevealInFinder ( dstPath ) ;
73
- } ;
74
- client . DownloadProgressChanged += ( object sender , DownloadProgressChangedEventArgs e ) =>
75
- {
76
- var progress = e . ProgressPercentage / 100f ;
77
- if ( EditorUtility . DisplayCancelableProgressBar ( "Downloading" , url , progress ) )
78
- {
79
- client . CancelAsync ( ) ;
80
- }
81
- } ;
82
- client . DownloadFileAsync ( new System . Uri ( url ) , tmpFilePath ) ;
83
-
84
- }
85
-
86
- static void RequestPackageVersion ( string packageName , System . Action < string > callback )
87
- {
88
- // request package list to get package version
89
- RequestJobManager . CreateListRequest ( false , true , ( req ) =>
90
- {
91
- var packageInfo = req . FindPackage ( packageName ) ;
92
- if ( null == packageInfo )
93
- {
94
- Debug . LogErrorFormat ( "Not found package \" {0}\" " , packageName ) ;
95
- return ;
96
- }
97
- callback ( packageInfo . version ) ;
98
- } , null ) ;
15
+ WebAppDownloader . DownloadWebApp ( version , dstPath ) ;
16
+ } ) ;
99
17
}
100
18
101
19
[ MenuItem ( "Edit/Render Streaming/Show web app documentation" ) ]
102
20
static void ShowWepAppDocumentation ( )
103
21
{
104
- RequestPackageVersion ( "com.unity.renderstreaming" , ( version ) =>
105
- {
106
- var pattern = @"\d+.\d+.\d+" ;
107
- var result = System . Text . RegularExpressions . Regex . Match ( version , pattern ) ;
108
- var url = System . IO . Path . Combine ( URLRoot , string . Format ( PathWebAppDocumentation , result . Value ) ) ;
22
+ WebAppDownloader . GetPackageVersion ( "com.unity.renderstreaming" , ( version ) => {
23
+ var url = WebAppDownloader . GetURLDocumentation ( version ) ;
109
24
Application . OpenURL ( url ) ;
110
25
} ) ;
111
26
}
27
+
112
28
[ MenuItem ( "Edit/Render Streaming/Show web app source code" ) ]
113
29
static void ShowWepAppSourceCode ( )
114
30
{
115
- RequestPackageVersion ( "com.unity.renderstreaming" , ( version ) =>
116
- {
117
- var pattern = @"\d+.\d+.\d+" ;
118
- var result = System . Text . RegularExpressions . Regex . Match ( version , pattern ) ;
119
- var url = System . IO . Path . Combine ( URLRoot , string . Format ( PathWebAppSourceCode , result . Value ) ) ;
31
+ WebAppDownloader . GetPackageVersion ( "com.unity.renderstreaming" , ( version ) => {
32
+ var url = WebAppDownloader . GetURLSourceCode ( version ) ;
120
33
Application . OpenURL ( url ) ;
121
34
} ) ;
122
35
}
0 commit comments