2024.5.23杨华提交3

This commit is contained in:
黄嘉宇 2024-05-23 10:07:48 +08:00
parent e1deaf94a3
commit f6a5646d44
4 changed files with 185 additions and 0 deletions

View File

@ -0,0 +1,60 @@
// 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_STANDALONE_OSX
#pragma warning disable CS0618
using System;
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Callbacks;
using UnityEngine.Rendering;
using Vuplex.WebView.Internal;
namespace Vuplex.WebView.Editor {
public class MacBuildScript : IPreprocessBuild {
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(BuildTarget buildTarget, string buildPath) {
if (buildTarget != BuildTarget.StandaloneOSX) {
return;
}
#if !VUPLEX_DISABLE_GRAPHICS_API_WARNING
var selectedGraphicsApi = PlayerSettings.GetGraphicsAPIs(buildTarget)[0];
var error = VXUtils.GetGraphicsApiErrorMessage(selectedGraphicsApi, new GraphicsDeviceType[] { GraphicsDeviceType.Metal });
if (error != null) {
throw new BuildFailedException(error);
}
#endif
}
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) {
if (target != BuildTarget.StandaloneOSX) {
return;
}
// Delete all of the .meta files added by Unity because they cause a codesign mismatch
// which causes app notarization to fail.
var metaFiles = Directory.GetFiles(pathToBuiltProject, "*.meta", SearchOption.AllDirectories);
foreach (var file in metaFiles) {
File.Delete(file);
}
}
}
}
#endif

View File

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

View File

@ -0,0 +1,103 @@
// 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_OSX
using System.Diagnostics;
using System.IO;
using UnityEditor;
namespace Vuplex.WebView.Editor {
/// <summary>
/// Mac editor script that modifies the VuplexWebViewMac
/// native plugin downloaded from the Asset Store to allow it to run.
/// </summary>
[InitializeOnLoad]
class MacEditorScript {
static MacEditorScript() {
var macPluginPath = EditorUtils.FindDirectory("Assets/Vuplex/WebView/Standalone/Mac/Plugins/VuplexWebViewMac.bundle");
// This removes the com.apple.quarantine attribute that
// macOS adds to the VuplexWebViewMac.bundle plugin when it's downloaded
// from the internet, which prevents the Unity editor from loading it.
//
// This is currently needed in order for the Unity
// editor to load 3rd party plugins, because the Unity editor app doesn't
// yet include the com.apple.security.cs.disable-library-validation
// entitlement that's required to be able to load 3rd party bundles
// with macOS 10.15 Catalina's hardened runtime. Without the
// com.apple.security.cs.disable-library-validation entitlement,
// the hardened runtime's library validation prevents an app from
// loading libraries unless theyre either signed by Apple or signed with the
// same team ID as the app (i.e. Unity's team ID in this case).
//
// References:
// • https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_disable-library-validation
// • https://bugzilla.mozilla.org/show_bug.cgi?id=1570840
// • https://bugzilla.mozilla.org/show_bug.cgi?id=1470597
_executeBashCommand("xattr -d com.apple.quarantine \"" + macPluginPath + "\"");
// When Unity's Asset Store tools compress and decompress the asset, the executable permission
// gets stripped off of the plugin's executables. So, we add the executable permission back
// on here using chmod.
var binaryRelativePaths = new string[] {
"Contents/Frameworks/Vuplex WebView.app/Contents/MacOS/Vuplex WebView",
"Contents/Frameworks/Vuplex WebView.app/Contents/Frameworks/Vuplex WebView Helper.app/Contents/MacOS/Vuplex WebView Helper",
"Contents/Frameworks/Vuplex WebView.app/Contents/Frameworks/Vuplex WebView Helper (GPU).app/Contents/MacOS/Vuplex WebView Helper (GPU)",
"Contents/Frameworks/Vuplex WebView.app/Contents/Frameworks/Vuplex WebView Helper (Plugin).app/Contents/MacOS/Vuplex WebView Helper (Plugin)",
"Contents/Frameworks/Vuplex WebView.app/Contents/Frameworks/Vuplex WebView Helper (Renderer).app/Contents/MacOS/Vuplex WebView Helper (Renderer)"
};
foreach (var relativePath in binaryRelativePaths) {
var path = Path.Combine(macPluginPath, relativePath);
_chmod("755 \"" + path + "\"");
}
}
static string _executeBashCommand(string command) {
// Escape quotes
command = command.Replace("\"","\"\"");
var proc = new Process {
StartInfo = new ProcessStartInfo {
FileName = "/bin/bash",
Arguments = "-c \""+ command + "\"",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
proc.WaitForExit();
return proc.StandardOutput.ReadToEnd();
}
static string _chmod(string arguments) {
var proc = new Process {
StartInfo = new ProcessStartInfo {
FileName = "/bin/chmod",
Arguments = arguments,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
proc.WaitForExit();
return proc.StandardOutput.ReadToEnd();
}
}
}
#endif

View File

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