This commit is contained in:
黄嘉宇 2024-05-23 10:06:43 +08:00
parent 09a5c704f2
commit e1deaf94a3
4 changed files with 286 additions and 0 deletions

View File

@ -0,0 +1,45 @@
// Copyright (c) 2023 Vuplex Inc. All rights reserved.
//
// Licensed under the Vuplex Commercial Software Library License, you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// https://vuplex.com/commercial-library-license
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
using UnityEditor;
using Vuplex.WebView.Internal;
namespace Vuplex.WebView.Editor {
/// <summary>
/// Editor script for Windows and macOS that checks if the editor preference
/// "Script Changes While Playing" is set to "Recompile And Continue Playing" and,
/// if so, automatically changes it "Recompile After Finished Playing".
/// </summary>
[InitializeOnLoad]
static class StandaloneEditorScript {
static StandaloneEditorScript() {
#if !VUPLEX_IGNORE_SCRIPT_COMPILATION_SETTING
// https://support.unity.com/hc/en-us/articles/210452343
var setting = EditorPrefs.GetInt(ScriptCompilationDuringPlay);
if (setting == RecompileAndContinuePlaying) {
EditorPrefs.SetInt(ScriptCompilationDuringPlay, RecompileAfterFinishedPlaying);
WebViewLogger.LogWarning("Just a heads-up: 3D WebView automatically changed the editor preference for \"Script Changes While Playing\" from \"Recompile And Continue Playing\" to \"Recompile After Finished Playing\" because 3D WebView doesn't currently support the former (it causes the editor to crash).");
}
#endif
}
const int RecompileAndContinuePlaying = 0;
const int RecompileAfterFinishedPlaying = 1;
const string ScriptCompilationDuringPlay = "ScriptCompilationDuringPlay";
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3baf398438b8b4544811069a971c2803
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,219 @@
// Copyright (c) 2023 Vuplex Inc. All rights reserved.
//
// Licensed under the Vuplex Commercial Software Library License, you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// https://vuplex.com/commercial-library-license
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using UnityEngine;
using UnityEditor;
using Vuplex.WebView.Internal;
namespace Vuplex.WebView.Editor {
/// <summary>
/// Implements the editor window for enabling proprietary video codecs:
/// https://support.vuplex.com/articles/how-to-enable-proprietary-video-codecs
/// </summary>
public class StandaloneVideoCodecsWindow : EditorWindow {
[MenuItem("Vuplex/Enable Proprietary Video Codecs")]
public static void ShowWindow() {
EditorWindow.GetWindowWithRect(
typeof(StandaloneVideoCodecsWindow),
new Rect(0, 0, 500, 500),
true,
"Enable Proprietary Video Codecs | Vuplex"
);
}
bool _checkboxEnabled;
bool _codecsEnabled;
string _errorMessage;
const string DESCRIPTION_TEXT = @"
3D WebView for Windows and macOS uses Chromium as its browser engine. <b>By default, Chromium doesn't include support for the proprietary H.264 video codec that is commonly used for MP4 and video streaming.</b> This is because companies must first sign an AVC/H.264 license agreement with MPEG-LA before they can legally distribute end-user software containing the H.264 codec. By default, 3D WebView for Windows and macOS uses a build of Chromium without proprietary video codecs so that customers can use 3D WebView in their applications without needing to sign a license agreement. That means that by default, 3D WebView supports open video codecs like WebM and Ogg, but MP4 and video streaming generally do not work because they rely on H.264.
However, 3D WebView also includes a second, optional build of Chromium with proprietary codecs enabled, which companies can opt into using if they have signed an MPEG-LA AVC/H.264 license agreement. Vuplex, Inc has signed such an agreement in order to be able to legally distribute this version of Chromium. <b>If your company has signed an AVC/H.264 license agreement with MPEG-LA, then you can use the button below to opt into using the version of Chromium with proprietary codecs enabled.</b> If your company has not signed a license agreement with MPEG-LA, then you are strictly prohibited from redistributing the version of Chromium with proprietary codecs enabled, but you may use it locally in the editor for personal use.
";
const string SUPPORT_LINK_URL = "https://support.vuplex.com/articles/how-to-enable-proprietary-video-codecs";
const string TOGGLE_TEXT = "<b>I acknowledge that I am prohibited from redistributing the version of Chromium with proprietary video codecs enabled unless I have signed an AVC/H.264 license agreement with MPEG-LA.</b>";
void _enableProprietaryVideoCodecs() {
try {
_enableProprietaryVideoCodecsForWindows();
} catch (Exception e) {
var message = "An error occurred while enabling proprietary video codecs for Windows: " + e.ToString();
// If running on Windows, show the error message and stop the process.
// If running on Mac, log the error to the console as a warning but continue to enabling Mac.
if (Application.platform == RuntimePlatform.WindowsEditor) {
WebViewLogger.LogError(message);
_errorMessage = message;
return;
} else {
WebViewLogger.LogWarning(message);
}
}
try {
_enableProprietaryVideoCodecsForMac();
} catch (Exception e) {
// If running on Mac, show the error message and stop the process.
// If running on Windows, log the error to the console as a warning but show the process has completed.
if (Application.platform == RuntimePlatform.OSXEditor) {
var message = "An error occurred while enabling proprietary video codecs for macOS: " + e.ToString();
WebViewLogger.LogError(message);
_errorMessage = message;
return;
} else {
WebViewLogger.LogWarning("An error occurred while enabling proprietary video codecs for macOS. This can happen if the file path is over 255 characters in length. Error: " + e.ToString());
}
}
_codecsEnabled = true;
}
void _enableProprietaryVideoCodecsForMac() {
var sourcePath = EditorUtils.FindDirectory(
Path.Combine(Application.dataPath, "Vuplex/WebView/Standalone/Mac/Plugins/VuplexWebViewMac_with_codecs.bundle")
);
var destinationPath = EditorUtils.FindDirectory(
Path.Combine(Application.dataPath, "Vuplex/WebView/Standalone/Mac/Plugins/VuplexWebViewMac.bundle")
);
EditorUtils.CopyAndReplaceDirectory(sourcePath, destinationPath, false);
}
void _enableProprietaryVideoCodecsForWindows() {
var sourcePath = EditorUtils.FindFile(
Path.Combine(Application.dataPath, "Vuplex/WebView/Standalone/Windows/Plugins/libcef_with_codecs.dll")
);
var destinationPath = EditorUtils.FindFile(
Path.Combine(Application.dataPath, "Vuplex/WebView/Standalone/Windows/Plugins/VuplexWebViewChromium/libcef.dll")
);
File.Copy(sourcePath, destinationPath, true);
}
void OnGUI() {
var textColor = EditorGUIUtility.isProSkin ? "white" : "black";
GUILayout.Box(
EditorUtils.TextWithColor(DESCRIPTION_TEXT, textColor),
new GUIStyle {
wordWrap = true,
richText = true,
padding = new RectOffset {
top = 20,
right = 20,
left = 20
}
},
null
);
// Add flexible space to center the button.
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
var learnMoreLinkClicked = GUILayout.Button(
EditorUtils.TextWithColor("Learn more", EditorUtils.GetLinkColor()),
new GUIStyle {
richText = true,
padding = new RectOffset {
top = 10,
bottom = 15
}
},
new GUILayoutOption[] { GUILayout.ExpandWidth(false) }
);
var linkRect = GUILayoutUtility.GetLastRect();
EditorGUIUtility.AddCursorRect(linkRect, MouseCursor.Link);
// Unity's editor GUI doesn't support underlines, so fake it.
GUI.Label(linkRect, EditorUtils.TextWithColor("____________", EditorUtils.GetLinkColor()), new GUIStyle {
richText = true,
padding = new RectOffset {
top = 12,
bottom = 15
}
});
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
if (learnMoreLinkClicked) {
Application.OpenURL(SUPPORT_LINK_URL);
}
if (_errorMessage != null) {
GUILayout.Label(
EditorUtils.TextWithColor(_errorMessage, "red"),
new GUIStyle {
wordWrap = true,
richText = true,
padding = new RectOffset {
right = 20,
left = 20
}
}
);
} else if (_codecsEnabled) {
GUILayout.Label(
$"<color=green>✔</color> <color={textColor}>Proprietary video codecs enabled</color>",
new GUIStyle {
wordWrap = true,
richText = true,
alignment = TextAnchor.MiddleCenter,
padding = new RectOffset {
top = 20,
right = 20,
left = 20
},
fontSize = 14
}
);
} else {
GUILayout.BeginHorizontal();
GUILayout.Space(20);
_checkboxEnabled = GUILayout.Toggle(
_checkboxEnabled,
""
);
GUILayout.Label(
EditorUtils.TextWithColor(TOGGLE_TEXT, textColor),
new GUIStyle {
wordWrap = true,
padding = new RectOffset {
right = 20,
},
richText = true
}
);
GUILayout.EndHorizontal();
GUILayout.Space(20);
// Add flexible space to center the button.
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUI.enabled = _checkboxEnabled;
var enableCodecsButtonClicked = GUILayout.Button(
"Enable Proprietary Video Codecs",
new GUILayoutOption[] { GUILayout.ExpandWidth(false) }
);
GUI.enabled = true;
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
if (enableCodecsButtonClicked) {
_enableProprietaryVideoCodecs();
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 57e4c6375145f42939e7b5623b250cad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: