备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 29f64101bcb907643b9e825838de020d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dbc2200488e7d45189f9a082caf5d637
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 59b3f9343bdac42318926c7944365bb9
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ea6387b3379b4458498b339bcd316c7c
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 70fc6af576ac24f6aa283eecbf393621
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5415c2bc4488c42739b36767bc7f8c83
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,539 @@
#if UNITY_EDITOR
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Text;
using System.Xml;
using System;
using UnityEditor.Android;
#if UNITY_2018_1_OR_NEWER
using UnityEditor.Build;
#endif
using UnityEditor.Callbacks;
using UnityEditor;
using UnityEngine;
#if UNITY_2018_1_OR_NEWER
public class UnityWebViewPostprocessBuild : IPreprocessBuild, IPostGenerateGradleAndroidProject
#else
public class UnityWebViewPostprocessBuild
#endif
{
private static bool nofragment = false;
//// for android/unity 2018.1 or newer
//// cf. https://forum.unity.com/threads/android-hardwareaccelerated-is-forced-false-in-all-activities.532786/
//// cf. https://github.com/Over17/UnityAndroidManifestCallback
#if UNITY_2018_1_OR_NEWER
public void OnPreprocessBuild(BuildTarget buildTarget, string path) {
if (buildTarget == BuildTarget.Android) {
var dev = "Packages/net.gree.unity-webview/Plugins/Android/WebViewPlugin-development.aar.tmpl";
var rel = "Packages/net.gree.unity-webview/Plugins/Android/WebViewPlugin-release.aar.tmpl";
if (!File.Exists(dev) || !File.Exists(rel)) {
dev = "Assets/Plugins/Android/WebViewPlugin-development.aar.tmpl";
rel = "Assets/Plugins/Android/WebViewPlugin-release.aar.tmpl";
}
var src = (EditorUserBuildSettings.development) ? dev : rel;
//Directory.CreateDirectory("Temp/StagingArea/aar");
//File.Copy(src, "Temp/StagingArea/aar/WebViewPlugin.aar", true);
Directory.CreateDirectory("Assets/Plugins/Android");
File.Copy(src, "Assets/Plugins/Android/WebViewPlugin.aar", true);
}
}
public void OnPostGenerateGradleAndroidProject(string basePath) {
var changed = false;
var androidManifest = new AndroidManifest(GetManifestPath(basePath));
if (!nofragment) {
changed = (androidManifest.AddFileProvider(basePath) || changed);
{
var path = GetBuildGradlePath(basePath);
var lines0 = File.ReadAllText(path).Replace("\r\n", "\n").Replace("\r", "\n").Split(new[]{'\n'});
{
var lines = new List<string>();
var independencies = false;
foreach (var line in lines0) {
if (line == "dependencies {") {
independencies = true;
} else if (independencies && line == "}") {
independencies = false;
lines.Add(" implementation 'androidx.core:core:1.6.0'");
} else if (independencies) {
if (line.Contains("implementation(name: 'core")
|| line.Contains("implementation(name: 'androidx.core.core")
|| line.Contains("implementation 'androidx.core:core")) {
break;
}
}
lines.Add(line);
}
if (lines.Count > lines0.Length) {
File.WriteAllText(path, string.Join("\n", lines) + "\n");
}
}
}
{
var path = GetGradlePropertiesPath(basePath);
var lines0 = "";
var lines = "";
if (File.Exists(path)) {
lines0 = File.ReadAllText(path).Replace("\r\n", "\n").Replace("\r", "\n") + "\n";
lines = lines0;
}
if (!lines.Contains("android.useAndroidX=true")) {
lines += "android.useAndroidX=true\n";
}
if (!lines.Contains("android.enableJetifier=true")) {
lines += "android.enableJetifier=true\n";
}
if (lines != lines0) {
File.WriteAllText(path, lines);
}
}
}
changed = (androidManifest.SetExported(true) || changed);
changed = (androidManifest.SetWindowSoftInputMode("adjustPan") || changed);
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
changed = (androidManifest.AddCamera() || changed);
changed = (androidManifest.AddGallery() || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
changed = (androidManifest.AddMicrophone() || changed);
#endif
if (changed) {
androidManifest.Save();
Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
}
}
#endif
public int callbackOrder {
get {
return 1;
}
}
private string GetManifestPath(string basePath) {
var pathBuilder = new StringBuilder(basePath);
pathBuilder.Append(Path.DirectorySeparatorChar).Append("src");
pathBuilder.Append(Path.DirectorySeparatorChar).Append("main");
pathBuilder.Append(Path.DirectorySeparatorChar).Append("AndroidManifest.xml");
return pathBuilder.ToString();
}
private string GetBuildGradlePath(string basePath) {
var pathBuilder = new StringBuilder(basePath);
pathBuilder.Append(Path.DirectorySeparatorChar).Append("build.gradle");
return pathBuilder.ToString();
}
private string GetGradlePropertiesPath(string basePath) {
var pathBuilder = new StringBuilder(basePath);
if (basePath.EndsWith("unityLibrary")) {
pathBuilder.Append(Path.DirectorySeparatorChar).Append("..");
}
pathBuilder.Append(Path.DirectorySeparatorChar).Append("gradle.properties");
return pathBuilder.ToString();
}
//// for others
[PostProcessBuild(100)]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
#if UNITY_2018_1_OR_NEWER
try {
File.Delete("Assets/Plugins/Android/WebViewPlugin.aar");
File.Delete("Assets/Plugins/Android/WebViewPlugin.aar.meta");
Directory.Delete("Assets/Plugins/Android");
File.Delete("Assets/Plugins/Android.meta");
Directory.Delete("Assets/Plugins");
File.Delete("Assets/Plugins.meta");
} catch (Exception) {
}
#else
if (buildTarget == BuildTarget.Android) {
string manifest = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml");
if (!File.Exists(manifest)) {
string manifest0 = Path.Combine(Application.dataPath, "../Temp/StagingArea/AndroidManifest-main.xml");
if (!File.Exists(manifest0)) {
Debug.LogError("unitywebview: cannot find both Assets/Plugins/Android/AndroidManifest.xml and Temp/StagingArea/AndroidManifest-main.xml. please build the app to generate Assets/Plugins/Android/AndroidManifest.xml and then rebuild it again.");
return;
} else {
File.Copy(manifest0, manifest, true);
}
}
var changed = false;
if (EditorUserBuildSettings.development) {
if (!File.Exists("Assets/Plugins/Android/WebView.aar")
|| !File.ReadAllBytes("Assets/Plugins/Android/WebView.aar").SequenceEqual(File.ReadAllBytes("Assets/Plugins/Android/WebViewPlugin-development.aar.tmpl"))) {
File.Copy("Assets/Plugins/Android/WebViewPlugin-development.aar.tmpl", "Assets/Plugins/Android/WebView.aar", true);
changed = true;
}
} else {
if (!File.Exists("Assets/Plugins/Android/WebView.aar")
|| !File.ReadAllBytes("Assets/Plugins/Android/WebView.aar").SequenceEqual(File.ReadAllBytes("Assets/Plugins/Android/WebViewPlugin-release.aar.tmpl"))) {
File.Copy("Assets/Plugins/Android/WebViewPlugin-release.aar.tmpl", "Assets/Plugins/Android/WebView.aar", true);
changed = true;
}
}
var androidManifest = new AndroidManifest(manifest);
if (!nofragment) {
changed = (androidManifest.AddFileProvider("Assets/Plugins/Android") || changed);
var files = Directory.GetFiles("Assets/Plugins/Android/");
var found = false;
foreach (var file in files) {
if (Regex.IsMatch(file, @"^Assets/Plugins/Android/(androidx\.core\.)?core-.*.aar$")) {
found = true;
break;
}
}
if (!found) {
foreach (var file in files) {
var match = Regex.Match(file, @"^Assets/Plugins/Android/(core.*.aar).tmpl$");
if (match.Success) {
var name = match.Groups[1].Value;
File.Copy(file, "Assets/Plugins/Android/" + name, true);
break;
}
}
}
}
changed = (androidManifest.SetWindowSoftInputMode("adjustPan") || changed);
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
changed = (androidManifest.AddCamera() || changed);
changed = (androidManifest.AddGallery() || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
changed = (androidManifest.AddMicrophone() || changed);
#endif
#if UNITY_5_6_0 || UNITY_5_6_1
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
#endif
if (changed) {
androidManifest.Save();
Debug.LogError("unitywebview: adjusted AndroidManifest.xml and/or WebView.aar. Please rebuild the app.");
}
}
#endif
if (buildTarget == BuildTarget.iOS) {
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
var type = Type.GetType("UnityEditor.iOS.Xcode.PBXProject, UnityEditor.iOS.Extensions.Xcode");
if (type == null)
{
Debug.LogError("unitywebview: failed to get PBXProject. please install iOS build support.");
return;
}
var src = File.ReadAllText(projPath);
//dynamic proj = type.GetConstructor(Type.EmptyTypes).Invoke(null);
var proj = type.GetConstructor(Type.EmptyTypes).Invoke(null);
//proj.ReadFromString(src);
{
var method = type.GetMethod("ReadFromString");
method.Invoke(proj, new object[]{src});
}
var target = "";
#if UNITY_2019_3_OR_NEWER
//target = proj.GetUnityFrameworkTargetGuid();
{
var method = type.GetMethod("GetUnityFrameworkTargetGuid");
target = (string)method.Invoke(proj, null);
}
#else
//target = proj.TargetGuidByName("Unity-iPhone");
{
var method = type.GetMethod("TargetGuidByName");
target = (string)method.Invoke(proj, new object[]{"Unity-iPhone"});
}
#endif
//proj.AddFrameworkToProject(target, "WebKit.framework", false);
{
var method = type.GetMethod("AddFrameworkToProject");
method.Invoke(proj, new object[]{target, "WebKit.framework", false});
}
var cflags = "";
if (EditorUserBuildSettings.development) {
cflags += " -DUNITYWEBVIEW_DEVELOPMENT";
}
#if UNITYWEBVIEW_IOS_ALLOW_FILE_URLS
cflags += " -DUNITYWEBVIEW_IOS_ALLOW_FILE_URLS";
#endif
cflags = cflags.Trim();
if (!string.IsNullOrEmpty(cflags)) {
// proj.AddBuildProperty(target, "OTHER_LDFLAGS", cflags);
var method = type.GetMethod("AddBuildProperty", new Type[]{typeof(string), typeof(string), typeof(string)});
method.Invoke(proj, new object[]{target, "OTHER_CFLAGS", cflags});
}
var dst = "";
//dst = proj.WriteToString();
{
var method = type.GetMethod("WriteToString");
dst = (string)method.Invoke(proj, null);
}
File.WriteAllText(projPath, dst);
}
}
}
internal class AndroidXmlDocument : XmlDocument {
private string m_Path;
protected XmlNamespaceManager nsMgr;
public readonly string AndroidXmlNamespace = "http://schemas.android.com/apk/res/android";
public AndroidXmlDocument(string path) {
m_Path = path;
using (var reader = new XmlTextReader(m_Path)) {
reader.Read();
Load(reader);
}
nsMgr = new XmlNamespaceManager(NameTable);
nsMgr.AddNamespace("android", AndroidXmlNamespace);
}
public string Save() {
return SaveAs(m_Path);
}
public string SaveAs(string path) {
using (var writer = new XmlTextWriter(path, new UTF8Encoding(false))) {
writer.Formatting = Formatting.Indented;
Save(writer);
}
return path;
}
}
internal class AndroidManifest : AndroidXmlDocument {
private readonly XmlElement ManifestElement;
private readonly XmlElement ApplicationElement;
public AndroidManifest(string path) : base(path) {
ManifestElement = SelectSingleNode("/manifest") as XmlElement;
ApplicationElement = SelectSingleNode("/manifest/application") as XmlElement;
}
private XmlAttribute CreateAndroidAttribute(string key, string value) {
XmlAttribute attr = CreateAttribute("android", key, AndroidXmlNamespace);
attr.Value = value;
return attr;
}
internal XmlNode GetActivityWithLaunchIntent() {
return
SelectSingleNode(
"/manifest/application/activity[intent-filter/action/@android:name='android.intent.action.MAIN' and "
+ "intent-filter/category/@android:name='android.intent.category.LAUNCHER']",
nsMgr);
}
internal bool SetUsesCleartextTraffic(bool enabled) {
// android:usesCleartextTraffic
bool changed = false;
if (ApplicationElement.GetAttribute("usesCleartextTraffic", AndroidXmlNamespace) != ((enabled) ? "true" : "false")) {
ApplicationElement.SetAttribute("usesCleartextTraffic", AndroidXmlNamespace, (enabled) ? "true" : "false");
changed = true;
}
return changed;
}
// for api level 33
internal bool SetExported(bool enabled) {
bool changed = false;
var activity = GetActivityWithLaunchIntent() as XmlElement;
if (activity.GetAttribute("exported", AndroidXmlNamespace) != ((enabled) ? "true" : "false")) {
activity.SetAttribute("exported", AndroidXmlNamespace, (enabled) ? "true" : "false");
changed = true;
}
return changed;
}
internal bool SetWindowSoftInputMode(string mode) {
bool changed = false;
var activity = GetActivityWithLaunchIntent() as XmlElement;
if (activity.GetAttribute("windowSoftInputMode", AndroidXmlNamespace) != mode) {
activity.SetAttribute("windowSoftInputMode", AndroidXmlNamespace, mode);
changed = true;
}
return changed;
}
internal bool SetHardwareAccelerated(bool enabled) {
bool changed = false;
var activity = GetActivityWithLaunchIntent() as XmlElement;
if (activity.GetAttribute("hardwareAccelerated", AndroidXmlNamespace) != ((enabled) ? "true" : "false")) {
activity.SetAttribute("hardwareAccelerated", AndroidXmlNamespace, (enabled) ? "true" : "false");
changed = true;
}
return changed;
}
internal bool SetActivityName(string name) {
bool changed = false;
var activity = GetActivityWithLaunchIntent() as XmlElement;
if (activity.GetAttribute("name", AndroidXmlNamespace) != name) {
activity.SetAttribute("name", AndroidXmlNamespace, name);
changed = true;
}
return changed;
}
internal bool AddFileProvider(string basePath) {
bool changed = false;
var authorities = PlayerSettings.applicationIdentifier + ".unitywebview.fileprovider";
if (SelectNodes("/manifest/application/provider[@android:authorities='" + authorities + "']", nsMgr).Count == 0) {
var elem = CreateElement("provider");
elem.Attributes.Append(CreateAndroidAttribute("name", "androidx.core.content.FileProvider"));
elem.Attributes.Append(CreateAndroidAttribute("authorities", authorities));
elem.Attributes.Append(CreateAndroidAttribute("exported", "false"));
elem.Attributes.Append(CreateAndroidAttribute("grantUriPermissions", "true"));
var meta = CreateElement("meta-data");
meta.Attributes.Append(CreateAndroidAttribute("name", "android.support.FILE_PROVIDER_PATHS"));
meta.Attributes.Append(CreateAndroidAttribute("resource", "@xml/unitywebview_file_provider_paths"));
elem.AppendChild(meta);
ApplicationElement.AppendChild(elem);
changed = true;
var xml = GetFileProviderSettingPath(basePath);
if (!File.Exists(xml)) {
Directory.CreateDirectory(Path.GetDirectoryName(xml));
File.WriteAllText(
xml,
"<paths xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <external-path name=\"unitywebview_file_provider_images\" path=\".\"/>\n" +
"</paths>\n");
}
}
return changed;
}
private string GetFileProviderSettingPath(string basePath) {
var pathBuilder = new StringBuilder(basePath);
pathBuilder.Append(Path.DirectorySeparatorChar).Append("src");
pathBuilder.Append(Path.DirectorySeparatorChar).Append("main");
pathBuilder.Append(Path.DirectorySeparatorChar).Append("res");
pathBuilder.Append(Path.DirectorySeparatorChar).Append("xml");
pathBuilder.Append(Path.DirectorySeparatorChar).Append("unitywebview_file_provider_paths.xml");
return pathBuilder.ToString();
}
internal bool AddCamera() {
bool changed = false;
if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.CAMERA']", nsMgr).Count == 0) {
var elem = CreateElement("uses-permission");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.CAMERA"));
ManifestElement.AppendChild(elem);
changed = true;
}
if (SelectNodes("/manifest/uses-feature[@android:name='android.hardware.camera']", nsMgr).Count == 0) {
var elem = CreateElement("uses-feature");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.hardware.camera"));
ManifestElement.AppendChild(elem);
changed = true;
}
// cf. https://developer.android.com/training/data-storage/shared/media#media-location-permission
if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.ACCESS_MEDIA_LOCATION']", nsMgr).Count == 0) {
var elem = CreateElement("uses-permission");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.ACCESS_MEDIA_LOCATION"));
ManifestElement.AppendChild(elem);
changed = true;
}
// cf. https://developer.android.com/training/package-visibility/declaring
if (SelectNodes("/manifest/queries", nsMgr).Count == 0) {
var elem = CreateElement("queries");
ManifestElement.AppendChild(elem);
changed = true;
}
if (SelectNodes("/manifest/queries/intent/action[@android:name='android.media.action.IMAGE_CAPTURE']", nsMgr).Count == 0) {
var action = CreateElement("action");
action.Attributes.Append(CreateAndroidAttribute("name", "android.media.action.IMAGE_CAPTURE"));
var intent = CreateElement("intent");
intent.AppendChild(action);
var queries = SelectSingleNode("/manifest/queries") as XmlElement;
queries.AppendChild(intent);
changed = true;
}
return changed;
}
internal bool AddGallery() {
bool changed = false;
// for api level 33
if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.READ_MEDIA_IMAGES']", nsMgr).Count == 0) {
var elem = CreateElement("uses-permission");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.READ_MEDIA_IMAGES"));
ManifestElement.AppendChild(elem);
changed = true;
}
if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.READ_MEDIA_VIDEO']", nsMgr).Count == 0) {
var elem = CreateElement("uses-permission");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.READ_MEDIA_VIDEO"));
ManifestElement.AppendChild(elem);
changed = true;
}
if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.READ_MEDIA_AUDIO']", nsMgr).Count == 0) {
var elem = CreateElement("uses-permission");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.READ_MEDIA_AUDIO"));
ManifestElement.AppendChild(elem);
changed = true;
}
// cf. https://developer.android.com/training/package-visibility/declaring
if (SelectNodes("/manifest/queries", nsMgr).Count == 0) {
var elem = CreateElement("queries");
ManifestElement.AppendChild(elem);
changed = true;
}
if (SelectNodes("/manifest/queries/intent/action[@android:name='android.media.action.GET_CONTENT']", nsMgr).Count == 0) {
var action = CreateElement("action");
action.Attributes.Append(CreateAndroidAttribute("name", "android.media.action.GET_CONTENT"));
var intent = CreateElement("intent");
intent.AppendChild(action);
var queries = SelectSingleNode("/manifest/queries") as XmlElement;
queries.AppendChild(intent);
changed = true;
}
return changed;
}
internal bool AddMicrophone() {
bool changed = false;
if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.MICROPHONE']", nsMgr).Count == 0) {
var elem = CreateElement("uses-permission");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.MICROPHONE"));
ManifestElement.AppendChild(elem);
changed = true;
}
if (SelectNodes("/manifest/uses-feature[@android:name='android.hardware.microphone']", nsMgr).Count == 0) {
var elem = CreateElement("uses-feature");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.hardware.microphone"));
ManifestElement.AppendChild(elem);
changed = true;
}
// cf. https://github.com/gree/unity-webview/issues/679
// cf. https://github.com/fluttercommunity/flutter_webview_plugin/issues/138#issuecomment-559307558
// cf. https://stackoverflow.com/questions/38917751/webview-webrtc-not-working/68024032#68024032
// cf. https://stackoverflow.com/questions/40236925/allowing-microphone-accesspermission-in-webview-android-studio-java/47410311#47410311
if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.MODIFY_AUDIO_SETTINGS']", nsMgr).Count == 0) {
var elem = CreateElement("uses-permission");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.MODIFY_AUDIO_SETTINGS"));
ManifestElement.AppendChild(elem);
changed = true;
}
if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.RECORD_AUDIO']", nsMgr).Count == 0) {
var elem = CreateElement("uses-permission");
elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.RECORD_AUDIO"));
ManifestElement.AppendChild(elem);
changed = true;
}
return changed;
}
}
#endif

View File

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

View File

@@ -0,0 +1,58 @@
fileFormatVersion: 2
guid: 60e7bf38137eb4950b2f02b7d57c1ad3
folderAsset: yes
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
platformData:
Android:
enabled: 0
settings:
CPU: AnyCPU
Any:
enabled: 0
settings: {}
Editor:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: OSX
Linux:
enabled: 0
settings:
CPU: x86
Linux64:
enabled: 0
settings:
CPU: x86_64
OSXIntel:
enabled: 1
settings:
CPU: AnyCPU
OSXIntel64:
enabled: 1
settings:
CPU: AnyCPU
OSXUniversal:
enabled: 1
settings:
CPU: AnyCPU
Win:
enabled: 0
settings:
CPU: AnyCPU
Win64:
enabled: 0
settings:
CPU: AnyCPU
iOS:
enabled: 0
settings:
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee2bc92b52f924630bfd4aff89395583
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>23G93</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>WebView</string>
<key>CFBundleIdentifier</key>
<string>net.gree.unitywebview.WebView</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>WebView</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string></string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>14.5</string>
<key>DTSDKBuild</key>
<string>23F73</string>
<key>DTSDKName</key>
<string>macosx14.5</string>
<key>DTXcode</key>
<string>1540</string>
<key>DTXcodeBuild</key>
<string>15F31d</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
</dict>
</plist>

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f5cac4b018fc441519472619c00b4a19
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7583463a0bdf148919eb1819ff8790ab
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3472ba57f3d2c40728fe4fa686337555
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b8d99a8979b8445dc8d524538cf76521
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6d60a4326049747b58f27bc930bcd7f4
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b4f429b11407f476894734317eaa0089
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict>
<key>Resources/InfoPlist.strings</key>
<data>
MiLKDDnrUKr4EmuvhS5VQwxHGK8=
</data>
</dict>
<key>files2</key>
<dict>
<key>Resources/InfoPlist.strings</key>
<dict>
<key>hash2</key>
<data>
Oc8u4Ht7Mz58F50L9NeYpbcq9qTlhPUeZCcDu/pPyCg=
</data>
</dict>
</dict>
<key>rules</key>
<dict>
<key>^Resources/</key>
<true/>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^.*</key>
<true/>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^[^/]+$</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7484b160ebd7c40bd9c42038fa7b69a8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a53a54acdc5d64291aa49766bb494025
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 2cabb4f60971742a28f3bd04e65de504
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: fc99cbfa2b53248b18d60e327b478581
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
mergeInto(LibraryManager.library, {
_gree_unity_webview_init: function(name) {
var stringify = (UTF8ToString === undefined) ? Pointer_stringify : UTF8ToString;
unityWebView.init(stringify(name));
},
_gree_unity_webview_setMargins: function (name, left, top, right, bottom) {
var stringify = (UTF8ToString === undefined) ? Pointer_stringify : UTF8ToString;
unityWebView.setMargins(stringify(name), left, top, right, bottom);
},
_gree_unity_webview_setVisibility: function(name, visible) {
var stringify = (UTF8ToString === undefined) ? Pointer_stringify : UTF8ToString;
unityWebView.setVisibility(stringify(name), visible);
},
_gree_unity_webview_loadURL: function(name, url) {
var stringify = (UTF8ToString === undefined) ? Pointer_stringify : UTF8ToString;
unityWebView.loadURL(stringify(name), stringify(url));
},
_gree_unity_webview_evaluateJS: function(name, js) {
var stringify = (UTF8ToString === undefined) ? Pointer_stringify : UTF8ToString;
unityWebView.evaluateJS(stringify(name), stringify(js));
},
_gree_unity_webview_destroy: function(name) {
var stringify = (UTF8ToString === undefined) ? Pointer_stringify : UTF8ToString;
unityWebView.destroy(stringify(name));
},
});

View File

@@ -0,0 +1,32 @@
fileFormatVersion: 2
guid: 1353be0798ab043d992cd72e4d92970b
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6998a6685c550584b8750c4260418c85
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,231 @@
/*
* Copyright (C) 2012 GREE, Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
using System.Collections;
using UnityEngine;
#if UNITY_2018_4_OR_NEWER
using UnityEngine.Networking;
#endif
public class WebView : MonoBehaviour
{
string Url;
int left; int top; int right; int bottom;
WebViewObject webViewObject;
IEnumerator OnStart()
{
webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
webViewObject.canvas = GameObject.Find("Canvas");
#endif
webViewObject.Init(
cb: (msg) =>
{
Debug.Log(string.Format("CallFromJS[{0}]", msg));
},
err: (msg) =>
{
Debug.Log(string.Format("CallOnError[{0}]", msg));
},
httpErr: (msg) =>
{
Debug.Log(string.Format("CallOnHttpError[{0}]", msg));
},
started: (msg) =>
{
Debug.Log(string.Format("CallOnStarted[{0}]", msg));
},
hooked: (msg) =>
{
Debug.Log(string.Format("CallOnHooked[{0}]", msg));
},
cookies: (msg) =>
{
Debug.Log(string.Format("CallOnCookies[{0}]", msg));
},
ld: (msg) =>
{
Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS
// NOTE: the following js definition is required only for UIWebView; if
// enabledWKWebView is true and runtime has WKWebView, Unity.call is defined
// directly by the native plugin.
#if true
var js = @"
if (!(window.webkit && window.webkit.messageHandlers)) {
window.Unity = {
call: function(msg) {
window.location = 'unity:' + msg;
}
};
}
";
#else
// NOTE: depending on the situation, you might prefer this 'iframe' approach.
// cf. https://github.com/gree/unity-webview/issues/189
var js = @"
if (!(window.webkit && window.webkit.messageHandlers)) {
window.Unity = {
call: function(msg) {
var iframe = document.createElement('IFRAME');
iframe.setAttribute('src', 'unity:' + msg);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
};
}
";
#endif
#elif UNITY_WEBPLAYER || UNITY_WEBGL
var js = @"
window.Unity = {
call:function(msg) {
parent.unityWebView.sendMessage('WebViewObject', msg);
}
};
";
#else
var js = "";
#endif
webViewObject.EvaluateJS(js + @"Unity.call('ua=' + navigator.userAgent)");
}
);
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
webViewObject.bitmapRefreshCycle = 1;
webViewObject.devicePixelRatio = 1; // 1 or 2
#endif
webViewObject.SetMargins(left, top, right, bottom);
webViewObject.SetTextZoom(100); // android only. cf. https://stackoverflow.com/questions/21647641/android-webview-set-font-size-system-default/47017410#47017410
webViewObject.SetVisibility(true);
#if !UNITY_WEBPLAYER && !UNITY_WEBGL
if (Url.StartsWith("http"))
{
webViewObject.LoadURL(Url.Replace(" ", "%20"));
}
else
{
var exts = new string[]{
".jpg",
".js",
".html" // should be last
};
foreach (var ext in exts)
{
var url = Url.Replace(".html", ext);
var src = System.IO.Path.Combine(Application.streamingAssetsPath, url);
var dst = System.IO.Path.Combine(Application.temporaryCachePath, url);
byte[] result = null;
if (src.Contains("://"))
{ // for Android
#if UNITY_2018_4_OR_NEWER
// NOTE: a more complete code that utilizes UnityWebRequest can be found in https://github.com/gree/unity-webview/commit/2a07e82f760a8495aa3a77a23453f384869caba7#diff-4379160fa4c2a287f414c07eb10ee36d
var unityWebRequest = UnityWebRequest.Get(src);
yield return unityWebRequest.SendWebRequest();
result = unityWebRequest.downloadHandler.data;
#else
var www = new WWW(src);
yield return www;
result = www.bytes;
#endif
}
else
{
result = System.IO.File.ReadAllBytes(src);
}
System.IO.File.WriteAllBytes(dst, result);
if (ext == ".html")
{
webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
break;
}
}
}
#else
if (Url.StartsWith("http")) {
webViewObject.LoadURL(Url.Replace(" ", "%20"));
} else {
webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
}
#endif
yield break;
}
public void GoBack()
{
webViewObject?.GoBack();
}
public void GoForward()
{
webViewObject?.GoForward();
}
public void Reload()
{
webViewObject?.Reload();
}
public WebViewObject OnOpen(string url, int left, int top, int right, int bottom)
{
Url = url;
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
if (webViewObject != null)
{
Destroy(webViewObject.gameObject);
webViewObject = null;
}
else
{
StartCoroutine(OnStart());
}
return webViewObject;
}
public void OnClose()
{
if (webViewObject != null)
{
Destroy(webViewObject.gameObject);
webViewObject = null;
}
}
public void GetCookies()
{
webViewObject?.GetCookies(Url);
}
public void ClearCookies()
{
webViewObject?.ClearCookies();
}
public void SetInteractionEnabled(bool value)
{
webViewObject?.SetInteractionEnabled(value);
}
public void SetVisibility(bool value)
{
webViewObject.SetVisibility(value);
}
private void OnDestroy()
{
OnClose();
}
}

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -0,0 +1,8 @@
{
"name": "net.gree.unity-webview",
"displayName": "unity-webview",
"version": "1.0.0",
"unity": "2019.1",
"description": "A plugin to display native webview views.",
"dependencies": {}
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d863dd473116e4930a3d4f7444365973
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
{
"name": "unity-webview",
"references": [],
"optionalUnityReferences": [],
"includePlatforms": [
"Android",
"Editor",
"iOS",
"macOSStandalone",
"WebGL",
"WindowsStandalone64"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: df2a24f83ece042be84d3276a68393ed
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: