diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/UniWebView |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/UniWebView')
20 files changed, 2012 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/UniWebView/Readme.txt b/Client/Assets/Scripts/UniWebView/Readme.txt new file mode 100644 index 00000000..7a772134 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Readme.txt @@ -0,0 +1,19 @@ +## UniWebView - An easier solution for integrating WebView to your mobile games
+
+Thank you for purchasing UniWebView!
+
+To get started with this asset, we strongly suggest to open demo scenes to play
+with the main features of UniWebView. You could use `0.Top` scene as a start point.
+Once you get familiar with UniWebView and ready to publish your game, you could
+feel free to remove the demo folder under UniWebView, to prevent the demo scripts
+compiled to your game.
+
+For more information (including manual and script refernce), please visit our
+officail website of UniWebView: http://uniwebview.onevcat.com
+
+If you encountered any problem when using UniWebView, please refer to our help
+desk to get support: https://onevcat.zendesk.com
+
+Best regards.
+
+From UniWebView Team.
diff --git a/Client/Assets/Scripts/UniWebView/Readme.txt.meta b/Client/Assets/Scripts/UniWebView/Readme.txt.meta new file mode 100644 index 00000000..a703c298 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Readme.txt.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2
+guid: 41f76c893d26c445d8762c1c8cb9d088
+TextScriptImporter:
+ userData:
+ assetBundleName:
diff --git a/Client/Assets/Scripts/UniWebView/Script.meta b/Client/Assets/Scripts/UniWebView/Script.meta new file mode 100644 index 00000000..3078bfbe --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2
+guid: 687577cf7b4fedc4ba252385fd342bdc
+folderAsset: yes
+timeCreated: 1497248060
+licenseType: Pro
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Client/Assets/Scripts/UniWebView/Script/Helper.meta b/Client/Assets/Scripts/UniWebView/Script/Helper.meta new file mode 100644 index 00000000..67841d99 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/Helper.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2
+guid: fa57d53780777cd49a2c5b454fba02c6
+folderAsset: yes
+timeCreated: 1497248060
+licenseType: Pro
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs b/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs new file mode 100644 index 00000000..17e810b1 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs @@ -0,0 +1,91 @@ +using UnityEngine;
+
+/// <summary>
+/// Supply some helper utility method for UniWebView
+/// </summary>
+public class UniWebViewHelper{
+ /// <summary>
+ /// Get the height of the screen.
+ /// </summary>
+ /// <value>
+ /// The height of screen.
+ /// </value>
+ /// <description>
+ /// In iOS devices, it will always return the screen height in "point",
+ /// instead of "pixel". It would be useful to use this value to calculate webview size.
+ /// On other platforms, it will just return Unity's Screen.height.
+ /// For example, a portrait iPhone 5 will return 568 and a landscape one 320. You should
+ /// always use this value to do screen-size-based insets calculation.
+ /// </description>
+ public static int screenHeight {
+ get {
+#if UNITY_IOS && !UNITY_EDITOR
+ return UniWebViewPlugin.ScreenHeight();
+#else
+ return Screen.height;
+#endif
+ }
+ }
+
+ /// <summary>
+ /// Get the height of the screen.
+ /// </summary>
+ /// <value>
+ /// The height of screen.
+ /// </value>
+ /// <description>
+ /// In iOS devices, it will always return the screen width in "point",
+ /// instead of "pixel". It would be useful to use this value to calculate webview size.
+ /// On other platforms, it will just return Unity's Screen.height.
+ /// For example, a portrait iPhone 5 will return 320 and a landscape one 568. You should
+ /// always use this value to do screen-size-based insets calculation.
+ /// </description>
+ public static int screenWidth {
+ get {
+#if UNITY_IOS && !UNITY_EDITOR
+ return UniWebViewPlugin.ScreenWidth();
+#else
+ return Screen.width;
+#endif
+ }
+ }
+
+ /// <summary>
+ /// Get the screen scale. In iOS or OS X Editor, it could be 1, 2 or 3 now, depending on the type of your screen.
+ /// </summary>
+ /// <value>The screen scale.</value>
+ public static int screenScale {
+ get {
+#if UNITY_IOS || UNITY_EDITOR
+ return UniWebViewPlugin.ScreenScale();
+#else
+ return 1;
+#endif
+ }
+ }
+
+ /// <summary>
+ /// Get the local streaming asset path for a given file path related to the StreamingAssets folder.
+ /// </summary>
+ /// <description>
+ /// This method will help you to concat a URL string for a file under your StreamingAssets folder for different platforms.
+ /// </description>
+ /// <param name="path">The relative path to the Assets/StreamingAssets of your file.
+ /// For example, if you placed a html file under Assets/StreamingAssets/www/index.html, you should pass `www/demo.html` as parameter.
+ /// </param>
+ /// <returns>The path you could use as the url for the web view.</returns>
+ public static string streamingAssetURLForPath(string path)
+ {
+#if UNITY_EDITOR
+ return Application.streamingAssetsPath + "/" + path;
+#elif UNITY_IOS
+ return Application.streamingAssetsPath + "/" + path;
+#elif UNITY_ANDROID
+ return "file:///android_asset/" + path;
+#elif UNITY_WP8
+ return "Data/StreamingAssets/" + path;
+#else
+ return string.Empty;
+#endif
+ }
+}
diff --git a/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs.meta b/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs.meta new file mode 100644 index 00000000..33e5071d --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2
+guid: 140fc92629361465289bcaf88e465b88
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebView.cs b/Client/Assets/Scripts/UniWebView/Script/UniWebView.cs new file mode 100644 index 00000000..fd591922 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebView.cs @@ -0,0 +1,1028 @@ +#if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
+//
+// UniWebView.cs
+// Created by Wang Wei(@onevcat) on 2013-10-20.
+//
+using UnityEngine;
+using System.Collections;
+using System;
+
+/// <summary>
+/// The main class of UniWebView.
+/// </summary>
+/// <description>
+/// Each gameObject with this script represent a webview object
+/// in system. Be careful: when this script's Awake() get called, it will change the name of
+/// the gameObject to make it unique in the game. So make sure this script is appeneded to a
+/// gameObject that you don't care its name.
+/// </description>
+public class UniWebView : MonoBehaviour {
+ #region Events and Delegate
+ //Delegate and event
+ public delegate void LoadCompleteDelegate(UniWebView webView, bool success, string errorMessage);
+ /// <summary>
+ /// Occurs when a UniWebView finished loading a webpage.
+ /// </summary>
+ /// <description>
+ /// If loading finished successfully, success will be true, otherwise false and with an errorMessage.
+ /// </description>
+ public event LoadCompleteDelegate OnLoadComplete;
+
+ public delegate void LoadBeginDelegate(UniWebView webView, string loadingUrl);
+ /// <summary>
+ /// Occurs when a UniWebView began to load a webpage.
+ /// </summary>
+ /// <description>
+ /// You can do something with the UniWebView passed by parameter to get some info
+ /// or do your things when a url begins to load
+ /// Sometimes, the webpage contains some other parts besides of the main frame. Whenever these parts
+ /// begin to load, this event will be fired. You can get the url from parameter to know what url is
+ /// about to be loaded.
+ /// It is useful when you want to get some parameters from url when user clicked a link.
+ /// </description>
+ public event LoadBeginDelegate OnLoadBegin;
+
+ public delegate void ReceivedMessageDelegate(UniWebView webView, UniWebViewMessage message);
+ /// <summary>
+ /// Occurs when a UniWebView received message.
+ /// </summary>
+ /// <description>
+ /// If a url with format of "uniwebview://yourPath?param1=value1¶m2=value2" clicked,
+ /// this event will get raised with a <see cref="UniWebViewMessage"/> object.
+ /// </description>
+ public event ReceivedMessageDelegate OnReceivedMessage;
+
+ public delegate void EvalJavaScriptFinishedDelegate(UniWebView webView, string result);
+ /// <summary>
+ /// Occurs when a UniWebView finishes eval a javascript and returned something.
+ /// </summary>
+ /// <description>
+ /// You can use EvaluatingJavaScript method to make the webview to eval a js.
+ /// The string-returned version of EvaluatingJavaScript is removed. You should
+ /// always listen this event to get the result of js.
+ /// </description>
+ public event EvalJavaScriptFinishedDelegate OnEvalJavaScriptFinished;
+
+ public delegate bool WebViewShouldCloseDelegate(UniWebView webView);
+ /// <summary>
+ /// Occurs when on web view will be closed by native. Ask if this webview should be closed or not.
+ /// </summary>
+ /// The users can close the webView by tapping back button (Android) or done button (iOS).
+ /// When the webview will be closed, this event will be raised.
+ /// If you return false, the webview will not be closed. If you did not implement it, webview will be closed.
+ /// </description>
+ public event WebViewShouldCloseDelegate OnWebViewShouldClose;
+
+ public delegate void ReceivedKeyCodeDelegate(UniWebView webView, int keyCode);
+ /// <summary>
+ /// Occurs when users clicks or taps any key while webview is actived. This event only fired on Android.
+ /// </summary>
+ /// <description>
+ /// On Android, the key down event can not be passed back to Unity due to some issue in Unity 4.3's Android Player.
+ /// As result, you are not able to get the key input on Android by just using Unity's Input.GetKeyDown or GetKey method.
+ /// If you want to know the user input while the webview on, you can subscribe this event.
+ /// This event will be fired with a int number indicating the key code tapped as parameter.
+ /// You can refer to Android's documentation to find out which key is tapped (http://developer.android.com/reference/android/view/KeyEvent.html)
+ /// This event will be never raised on iOS, because iOS forbids the tracking of user's keyboard or device button events.
+ /// </description>
+ public event ReceivedKeyCodeDelegate OnReceivedKeyCode;
+
+ public delegate UniWebViewEdgeInsets InsetsForScreenOreitationDelegate(UniWebView webView, UniWebViewOrientation orientation);
+ /// <summary>
+ /// Called when the webview need to know the insets for calculating webview's frame.
+ /// </summary>
+ /// <description>
+ /// If you need to show web content in both portrait and landscpace mode, you might want to
+ /// specify different insets for the screen orientation separately.
+ /// This event will be called when the Show() method gets called and the screen orientation
+ /// changes. You can implement this method and check current orientation, then return correct insets.
+ /// If this event is not implemented, the old insets value will be used to resize the webview size.
+ /// If you do not use auto-rotating in your webview, you can ignore this method and just set the <see cref="insets"/>
+ /// property directly.
+ /// </description>
+ public event InsetsForScreenOreitationDelegate InsetsForScreenOreitation;
+
+ #endregion
+
+ [SerializeField]
+ private UniWebViewEdgeInsets _insets = new UniWebViewEdgeInsets(0,0,0,0);
+
+ /// <summary>
+ /// Gets or sets the insets of a UniWebView object.
+ /// </summary>
+ /// <value>The insets in point from top, left, bottom and right edge from the screen.</value>
+ /// <description>
+ /// Default value is UniWebViewEdgeInsets(0,0,0,0), which means a full screen webpage.
+ /// If you want use different insets in portrait and landscape screen, use <see cref="InsetsForScreenOreitation"/>
+ /// </description>
+ public UniWebViewEdgeInsets insets {
+ get {
+ return _insets;
+ }
+ set {
+ if (_insets != value) {
+ ForceUpdateInsetsInternal(value);
+ }
+ }
+ }
+
+ private void ForceUpdateInsetsInternal(UniWebViewEdgeInsets insets) {
+ _insets = insets;
+ UniWebViewPlugin.ChangeInsets(gameObject.name,
+ this.insets.top,
+ this.insets.left,
+ this.insets.bottom,
+ this.insets.right);
+ #if UNITY_EDITOR
+ CreateTexture(this.insets.left,
+ this.insets.bottom,
+ Screen.width - this.insets.left - this.insets.right,
+ Screen.height - this.insets.top - this.insets.bottom
+ );
+ #endif
+ }
+
+ /// <summary>
+ /// The url this UniWebView should load. You should set it before loading webpage.
+ /// Do not use this value when you want to get the url of current page. It is only for loading the first page.
+ /// The value will not change as the users navigating between the pages.
+ /// Use <seealso cref="currentUrl"/> if you want to know current url.
+ /// </summary>
+ public string url;
+
+ /// <summary>
+ /// If true, load the set url when in script's Start() method.
+ /// Otherwise, you should call Load() method yourself.
+ /// </summary>
+ public bool loadOnStart;
+
+ /// <summary>
+ /// If true, show the webview automatically when it finished loading.
+ /// Otherwise, you should listen the OnLoadComplete event and call Show() method your self.
+ /// </summary>
+ public bool autoShowWhenLoadComplete;
+
+ /// <summary>
+ /// Gets the current URL of the web page.
+ /// </summary>
+ /// <value>The current URL of this webview.</value>
+ /// <description>
+ /// This value indicates the main frame url of the webpage.
+ /// It will be updated only when the webpage finishs or fails loading.
+ /// </description>
+ public string currentUrl {
+ get {
+ return UniWebViewPlugin.GetCurrentUrl(gameObject.name);
+ }
+ }
+
+ private bool _backButtonEnable = true;
+ private bool _bouncesEnable;
+ private bool _zoomEnable;
+ private string _currentGUID;
+ private int _lastScreenHeight;
+ private bool _immersiveMode = true;
+
+ private Action _showTransitionAction = null;
+ private Action _hideTransitionAction = null;
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the back button of this <see cref="UniWebView"/> is enabled.
+ /// </summary>
+ /// <description>
+ /// It is only for Android and Windows Phone 8. If set true, users can use the back button of these devices to goBack or close the web view
+ /// if there is nothing to goBack. Otherwise, the back button will do nothing when the webview is shown.
+ /// When set true, Unity will not receive the Input.KeyDown or other similar event in Android. You could use <seealso cref="OnReceivedKeyCode"/> to watch the key event instead.
+ /// This value means nothing for iOS, since there is no back button for iOS devices.
+ /// </description>
+ /// <value><c>true</c> if back button enabled; otherwise, <c>false</c>. Default is true</value>.
+ public bool backButtonEnable {
+ get {
+ return _backButtonEnable;
+ }
+ set {
+ if (_backButtonEnable != value) {
+ _backButtonEnable = value;
+ #if (UNITY_ANDROID || UNITY_WP8) && !UNITY_EDITOR
+ UniWebViewPlugin.SetBackButtonEnable(gameObject.name, _backButtonEnable);
+ #endif
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this <see cref="UniWebView"/> can bounces or not.
+ /// </summary>
+ /// <description>
+ /// The default iOS webview has a bounces effect when drag out of edge.
+ /// The default Android webview has a color indicator when drag beyond the edge.
+ /// UniWebView disabled these bounces effect by default. If you want the bounces, set this property to true.
+ /// This property does noting in editor or Windows Phone 8.
+ /// </description>
+ /// <value><c>true</c> if bounces enable; otherwise, <c>false</c>.</value>
+ public bool bouncesEnable {
+ get {
+ return _bouncesEnable;
+ }
+ set {
+ if (_bouncesEnable != value) {
+ _bouncesEnable = value;
+ #if !UNITY_EDITOR
+ UniWebViewPlugin.SetBounces(gameObject.name, _bouncesEnable);
+ #endif
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this <see cref="UniWebView"/> can be zoomed or not.
+ /// </summary>
+ /// <description>
+ /// If true, users can zoom in or zoom out the webpage by a pinch gesture.
+ /// This propery will valid immediately on Android. But on iOS, it will not valid until the next page loaded.
+ /// You can set this property before page loading, or use Reload() to refresh current page to make it valid.
+ /// This property does noting in Windows Phone 8, since there is no way to control the default behavior for it.
+ /// If you need to disable users zoom or pinch guesture, you need to add a viewport tag with "user-scalable=no" to your page.
+ /// </description>
+ /// <value><c>true</c> if zoom enabled; otherwise, <c>false</c>.</value> Default is false.
+ public bool zoomEnable {
+ get {
+ return _zoomEnable;
+ }
+ set {
+ if (_zoomEnable != value) {
+ _zoomEnable = value;
+ #if !UNITY_EDITOR
+ UniWebViewPlugin.SetZoomEnable(gameObject.name, _zoomEnable);
+ #endif
+ }
+ }
+ }
+
+ /// <summary>
+ /// Get the user agent of this webview.
+ /// </summary>
+ /// <value>The string of user agent using by the webview.</value>
+ /// <description>
+ /// It is a read-only property of webview. Once it is set when the webview gets created, the user agent can not be changed again.
+ /// If you want to use a customized user agent, you should call <see cref="SetUserAgent"/> method before create a webview component.
+ /// </description>
+ public string userAgent {
+ get {
+ return UniWebViewPlugin.GetUserAgent(gameObject.name);
+ }
+ }
+
+ /// <summary>
+ /// Get or set the alpha of current webview.
+ /// </summary>
+ /// <value>The alpha.</value>
+ /// <description>
+ /// This value indicates the alpha of webview.
+ /// The value should be between 0.0~1.0, which 1.0 means opaque and 0.0 is transparent.
+ /// This property will work on iOS, Android and WP8. In editor it will be always 1.0 and opaque.
+ /// </description>
+ public float alpha {
+ get {
+ return UniWebViewPlugin.GetAlpha(gameObject.name);
+ }
+ set {
+ UniWebViewPlugin.SetAlpha(gameObject.name, Mathf.Clamp01(value));
+ }
+ }
+
+ /// <summary>
+ /// Whether the new page should be opened in an external browser when user clicks a link.
+ /// </summary>
+ /// <value>A boolean indicates link clicking should be opened externally or not.</value>
+ /// <description>
+ /// If true, when user clicks on a link, an external web page browser on the device will be opened
+ /// and direct to the target link. It will be useful if you need navigate your user to a device installed
+ /// browser (like Mobile Safari on iOS or Chrome on Android).
+ /// This will only work when your user click a link in your page. Due to the lack detection of Android web view,
+ /// some javascript embedded link will not be able to open externally correctly. If you need more control of it,
+ /// consider to add all http/https scheme with AddUrlScheme method and handle them case by case in the OnReceivedMessage callback.
+ /// The default value is false, which means all link clicking will be opened in place.
+ /// </description>
+ public bool openLinksInExternalBrowser {
+ get {
+ return UniWebViewPlugin.GetOpenLinksInExternalBrowser(gameObject.name);
+ }
+ set {
+ UniWebViewPlugin.SetOpenLinksInExternalBrowser(gameObject.name, value);
+ }
+ }
+
+ /// <summary>
+ /// Get or set a value indicating whether this <see cref="UniWebView"/> is in immersive mode.
+ /// </summary>
+ /// <value><c>true</c> if immersive mode; otherwise, <c>false</c>.</value>
+ /// <description>
+ ///
+ /// </description>
+ public bool immersiveMode {
+ get {
+ return _immersiveMode;
+ }
+ set {
+ #if UNITY_ANDROID && !UNITY_EDITOR
+ _immersiveMode = value;
+ UniWebViewPlugin.SetImmersiveModeEnabled(gameObject.name, _immersiveMode);
+ #endif
+ }
+ }
+
+ /// <summary>
+ /// Set user agent string for webview. This method has no effect on the webviews which are already initiated.
+ /// The user agent of a UniWebView component can not be changed once it is created.
+ /// If you want to change the user agent for the webview, you have to call it before creating the UniWebView instance.
+ /// </summary>
+ /// <param name="value">The value user agent should be. Set it to null will reset the user agent to the default one.</param>
+ public static void SetUserAgent(string value) {
+ UniWebViewPlugin.SetUserAgent(value);
+ }
+
+ /// <summary>
+ /// Reset the user agent of webview. This method has no effect on the webviews which are already initiated.
+ /// The user agent of a UniWebView component can not be changed once it is created.
+ /// If you want to set user agent, use the <see cref="SetUserAgent"/> method.
+ /// </summary>
+ public static void ResetUserAgent() {
+ SetUserAgent(null);
+ }
+
+ /// <summary>
+ /// Set the text in Done button of tool bar in iOS.
+ /// User could use this button in iOS to close the web view. By default, "Done" will be shown for this button.
+ /// If you want to change the text of tool bar done button for the webview, you have to call it before creating the UniWebView instance.
+ /// This method only works for iOS. See <seealso cref="ShowToolBar"/>.
+ /// </summary>
+ /// <param name="text">The text you want to show for the Done button. Set it to null will reset it to "Done".</param>
+ public static void SetDoneButtonText(string text) {
+ #if UNITY_IOS && !UNITY_EDITOR
+ UniWebViewPlugin.SetDoneButtonText(text);
+ #endif
+ }
+
+ /// <summary>
+ /// Load the url set in <seealso cref="url"/> property of this UniWebView.
+ /// </summary>
+ public void Load() {
+ string loadUrl = String.IsNullOrEmpty(url) ? "about:blank" : url.Trim();
+ UniWebViewPlugin.Load(gameObject.name, loadUrl);
+ }
+
+ /// <summary>
+ /// A alias method to load a specified url.
+ /// </summary>
+ /// <param name="aUrl">A url to set and load</param>
+ /// <description>
+ /// It will set the url of this UniWebView and then call Load it.
+ /// </description>
+ public void Load(string aUrl) {
+ url = aUrl;
+ Load();
+ }
+
+ /// <summary>
+ /// Load a HTML string.
+ /// </summary>
+ /// <param name="htmlString">The content HTML string for the web page.</param>
+ /// <param name="baseUrl">The base URL in which the webview should to refer other resources</param>
+ /// <description>
+ /// If you want to specify a local baseUrl, you need to encode it to proper format.
+ /// See the "Can I load some html string by using UniWebView?" section in FAQ page (http://uniwebview.onevcat.com/faqs.html) for more.
+ /// </description>
+ public void LoadHTMLString(string htmlString, string baseUrl) {
+ UniWebViewPlugin.LoadHTMLString(gameObject.name, htmlString, baseUrl);
+ }
+
+ /// <summary>
+ /// Reload current page.
+ /// </summary>
+ public void Reload() {
+ UniWebViewPlugin.Reload(gameObject.name);
+ }
+
+ /// <summary>
+ /// Stop loading the current request. It will do nothing if the webpage is not loading.
+ /// </summary>
+ public void Stop() {
+ UniWebViewPlugin.Stop(gameObject.name);
+ }
+
+ /// <summary>
+ /// Show this UniWebView on screen.
+ /// </summary>
+ /// <description>
+ /// Usually, it should be called when you get the LoadCompleteDelegate raised with a success flag true.
+ /// The webview will not be visible until this method is called.
+ /// </description>
+ public void Show(bool fade = false, UniWebViewTransitionEdge direction = UniWebViewTransitionEdge.None, float duration = 0.4f, Action finishAction = null) {
+ _lastScreenHeight = UniWebViewHelper.screenHeight;
+ ResizeInternal();
+
+ UniWebViewPlugin.Show(gameObject.name, fade, (int)direction, duration);
+ _showTransitionAction = finishAction;
+
+ if (toolBarShow) {
+ ShowToolBar(true);
+ }
+
+ #if UNITY_EDITOR
+ _webViewId = UniWebViewPlugin.GetId(gameObject.name);
+ _hidden = false;
+ #endif
+ }
+
+ /// <summary>
+ /// Hide this UniWebView.
+ /// </summary>
+ /// <description>
+ /// Calling this method on a UniWebView will hide it.
+ /// </description>
+ public void Hide(bool fade = false, UniWebViewTransitionEdge direction = UniWebViewTransitionEdge.None, float duration = 0.4f, Action finishAction = null) {
+ #if UNITY_EDITOR
+ _hidden = true;
+ #endif
+ UniWebViewPlugin.Hide(gameObject.name, fade, (int)direction, duration);
+ _hideTransitionAction = finishAction;
+ }
+
+
+ /// <summary>
+ /// Send a piece of javascript to the web page and evaluate (execute) it.
+ /// </summary>
+ /// <param name="javaScript">A single javascript method call to be sent to and executed in web page</param>
+ /// <description>
+ /// Although you can write complex javascript code and evaluate it at once, a suggest way is calling this method with a single js method name.
+ /// The webview will try evaluate (execute) the javascript. When it finished, OnEvalJavaScriptFinished will be raised with the result.
+ /// You can add your js function to the html page by referring to the js file in your html page, or add it by using AddJavaScript(string javaScript) method.
+ /// </description>
+ public void EvaluatingJavaScript(string javaScript) {
+ UniWebViewPlugin.EvaluatingJavaScript(gameObject.name, javaScript);
+ }
+
+ /// <summary>
+ /// Add some javascript to the web page.
+ /// </summary>
+ /// <param name="javaScript">Some javascript code you want to add to the page.</param>
+ /// <description>
+ /// This method will execute the input javascript code without raising an
+ /// OnEvalJavaScriptFinished event. You can use this method to add some customized js
+ /// function to the web page, then use EvaluatingJavaScript(string javaScript) to execute it.
+ /// This method will add js in a async way in Android, so you should call it earlier than EvaluatingJavaScript
+ /// </description>
+ public void AddJavaScript(string javaScript) {
+ UniWebViewPlugin.AddJavaScript(gameObject.name, javaScript);
+ }
+
+ /// <summary>
+ /// Clean the cache of this UniWebView.
+ /// </summary>
+ public void CleanCache() {
+ UniWebViewPlugin.CleanCache(gameObject.name);
+ }
+
+ /// <summary>
+ /// Clean the cookie using in the app.
+ /// </summary>
+ /// <param name="key">The key under which you want to clean the cache.</param>
+ /// <description>
+ /// Try to clean cookies under the specified key using in the app.
+ /// If you leave the key as null or send an empty string as key, all cache will be cleared.
+ /// This method will clear the cookies in memory and try to
+ /// sync the change to disk. The memory opreation will return
+ /// right away, but the disk operation is async and could take some time.
+ /// Caution, in Android, there is no way to remove a specified cookie.
+ /// So this method will call setCookie method with the key to set
+ /// it to an empty value instead. Please refer to Android
+ /// documentation on CookieManager for more information.
+ /// The key parameter will be ignored at all on Windows Phone 8. All cookie will be cleared.
+ /// </description>
+ public void CleanCookie(string key = null) {
+ UniWebViewPlugin.CleanCookie(gameObject.name, key);
+ }
+
+ /// <summary>
+ /// Set the background of webview to transparent.
+ /// </summary>
+ /// <description>
+ /// In iOS, there is a grey background in webview. If you don't want it, just call this method to set it transparent.
+ /// There is no way to set Windows Phone 8 background to transparent, so this method will do noting on Windows Phone.
+ /// </description>
+ [Obsolete("SetTransparentBackground is deprecated, please use SetBackgroundColor instead.")]
+ public void SetTransparentBackground(bool transparent = true) {
+ UniWebViewPlugin.TransparentBackground(gameObject.name, transparent);
+ }
+
+ /// <summary>
+ /// Set the background color of webview.
+ /// </summary>
+ /// <description>
+ /// Set the background color of the webview. In iOS, it will only take in action when the web page has no background color from css.
+ /// There is no way to set Windows Phone 8, so this method will do noting on Windows Phone.
+ /// And in OSX Editor, it is limited and can be only used to set white or clear background.
+ /// </description>
+ public void SetBackgroundColor(Color color) {
+ UniWebViewPlugin.SetBackgroundColor(gameObject.name, color.r, color.g, color.b, color.a);
+ }
+
+ /// <summary>
+ /// If the tool bar is showing or not.
+ /// </summary>
+ /// <description>
+ /// This parameter is only available in iOS. In other platform, it will be always false.
+ /// It will take no effect when you set this after you call Show on the webview. Use `ShowToolBar` and `HideToolBar` instead if the webview is already showing.
+ /// </description>
+ public bool toolBarShow = false;
+
+ /// <summary>
+ /// Show the tool bar. The tool bar contains three buttons: go back, go forward and close webview.
+ /// </summary>
+ /// <param name="animate">If set to <c>true</c>, show it with an animation.</param>
+ /// <description>
+ /// The tool bar is only available in iOS. In Android and Windows Phone, you can use the back button of device to go back.
+ /// </description>
+ public void ShowToolBar(bool animate) {
+ #if UNITY_IOS && !UNITY_EDITOR
+ toolBarShow = true;
+ UniWebViewPlugin.ShowToolBar(gameObject.name,animate);
+ #endif
+ }
+
+ /// <summary>
+ /// Hide the tool bar. The tool bar contains three buttons: go back, go forward and close webview.
+ /// </summary>
+ /// <param name="animate">If set to <c>true</c>, show it with an animation.</param>
+ /// <description>
+ /// The tool bar is only available in iOS. For Android and Windows Phone, you can use the back button of device to go back.
+ /// </description>
+ public void HideToolBar(bool animate) {
+ #if UNITY_IOS && !UNITY_EDITOR
+ toolBarShow = false;
+ UniWebViewPlugin.HideToolBar(gameObject.name,animate);
+ #endif
+ }
+
+ /// <summary>
+ /// Set if a default spinner should show when loading the webpage.
+ /// </summary>
+ /// <description>
+ /// The default value is true, which means a spinner will show when the webview is on, and it is loading some thing.
+ /// The spinner contains a label and you can set a message to it. <see cref=""/>
+ /// You can set it false if you do not want a spinner show when loading.
+ /// A progress bar will be used in Windows Phone instead of a spinner.
+ /// </description>
+ /// <param name="show">If set to <c>true</c> show.</param>
+ public void SetShowSpinnerWhenLoading(bool show) {
+ UniWebViewPlugin.SetSpinnerShowWhenLoading(gameObject.name, show);
+ }
+
+ /// <summary>
+ /// Set the label text for the spinner showing when webview loading.
+ /// The default value is "Loading..."
+ /// </summary>
+ /// <param name="text">Text.</param>
+ /// <description>
+ /// There is no text for Windows Phone spinner, so it will do noting for it.
+ /// </description>
+ public void SetSpinnerLabelText(string text) {
+ UniWebViewPlugin.SetSpinnerText(gameObject.name, text);
+ }
+
+ /// <summary>
+ /// Set to use wide view port support or not.
+ /// </summary>
+ /// <param name="use">If set to <c>true</c> use view port tag in the html to determine the layout.</param>
+ /// <description>
+ /// This method only works (and be necessary) for Android. If you are using viewport tag in you page, you may
+ /// want to enable it before you loading and showing your page.
+ /// </description>
+ public void SetUseWideViewPort(bool use) {
+ #if UNITY_ANDROID && !UNITY_EDITOR
+ UniWebViewPlugin.SetUseWideViewPort(gameObject.name, use);
+ #endif
+ }
+
+ /// <summary>
+ /// Set to load with overview mode or not.
+ /// </summary>
+ /// <param name="overview">
+ /// If set to <c>true</c>, use overview mode to load the page.
+ /// </param>
+ /// <description>
+ /// This method only works for Android. If you need to load your page with overview mode, you may
+ /// want to enable it before you loading and showing your page.
+ /// </description>
+ public void LoadWithOverviewMode(bool overview) {
+ #if UNITY_ANDROID && !UNITY_EDITOR
+ UniWebViewPlugin.LoadWithOverviewMode(gameObject.name, overview);
+ #endif
+ }
+
+ /// <summary>
+ /// Determines whether the webview can go back.
+ /// </summary>
+ /// <returns><c>true</c> if this instance can go back, which means there is at least one page in the navigation stack below;
+ /// otherwise, <c>false</c>.</returns>
+ public bool CanGoBack() {
+ return UniWebViewPlugin.CanGoBack(gameObject.name);
+ }
+
+ /// <summary>
+ /// Determines whether this webview can go forward.
+ /// </summary>
+ /// <returns><c>true</c> if this instance can go forward, which means the user did at least once back;
+ /// otherwise, <c>false</c>.</returns>
+ public bool CanGoForward() {
+ return UniWebViewPlugin.CanGoForward(gameObject.name);
+ }
+
+ /// <summary>
+ /// Go to the previous page if there is any one.
+ /// </summary>
+ public void GoBack() {
+ UniWebViewPlugin.GoBack(gameObject.name);
+ }
+
+ /// <summary>
+ /// Go to the next page if there is any one.
+ /// </summary>
+ public void GoForward() {
+ UniWebViewPlugin.GoForward(gameObject.name);
+ }
+
+ /// <summary>
+ /// Add a url to white list of permission request trust sites.
+ /// </summary>
+ /// <description>
+ /// This method only works in Android. In Android, if you request audio or video accessibility from web page,
+ /// you should add the site url to a white list by using this method, or it will not be granted to use those protected resources.
+ /// There is no need to call it in iOS, and this method will do nothing in platforms other than Android.
+ /// For more about Android protected permission, see https://developer.android.com/reference/android/webkit/PermissionRequest.html.
+ /// </description>
+ /// <param name="url">URL.</param>
+ public void AddPermissionRequestTrustSite(string url) {
+ #if UNITY_ANDROID && !UNITY_EDITOR
+ UniWebViewPlugin.AddPermissionRequestTrustSite(gameObject.name, url);
+ #endif
+ }
+
+ /// <summary>
+ /// Adds the URL scheme. After be added, all link of this scheme will send a message when clicked.
+ /// </summary>
+ /// <param name="scheme">Scheme.</param>
+ /// <description>
+ /// The scheme should not contain "://". For example, if you want to receive a url like "xyz://mydomian.com", you can pass "xyz" here.
+ /// </description>
+ public void AddUrlScheme(string scheme) {
+ UniWebViewPlugin.AddUrlScheme(gameObject.name, scheme);
+ }
+
+ /// <summary>
+ /// Removes the URL scheme. After be removed, this kind of url will be handled by the webview.
+ /// </summary>
+ /// <param name="scheme">Scheme.</param>
+ public void RemoveUrlScheme(string scheme) {
+ UniWebViewPlugin.RemoveUrlScheme(gameObject.name, scheme);
+ }
+
+ /// <summary>
+ /// Set the header field.
+ /// </summary>
+ /// <description>
+ /// Specify customized header field for the next url loading.
+ /// You could call this method multiple times to add key/value pairs for different fields.
+ /// Only the requests by using Load() method of current web view will use these setting for header.
+ /// </description>
+ /// <param name="key">Key of the header field. Empty string or null will be ignored.</param>
+ /// <param name="value">Value of the header field. Pass null to remove an existing value. Empty string will be ignored.</param>
+ public void SetHeaderField(string key, string value) {
+ #if UNITY_WP8
+ Debug.LogWarning("Not implemented for Windows Phone 8.");
+ #else
+ UniWebViewPlugin.SetHeaderField(gameObject.name, key, value);
+ #endif
+ }
+
+ /// <summary>
+ /// Set visibility of vertical bar for the web view.
+ /// </summary>
+ /// <description>
+ /// This method will not work for editor and Windows Phone 8.
+ /// </description>
+ /// <param name="show">Whether the vertical scroll bar should be visible or not when the web view is being scrolled.</param>
+ public void SetVerticalScrollBarShow(bool show) {
+ #if UNITY_WP8
+ Debug.LogWarning("Not implemented for Windows Phone 8.");
+ #else
+ UniWebViewPlugin.SetVerticalScrollBarShow(gameObject.name, show);
+ #endif
+ }
+
+ /// <summary>
+ /// Set visibility of horizontal bar for the web view.
+ /// </summary>
+ /// <description>
+ /// This method will not work for editor and Windows Phone 8.
+ /// </description>
+ /// <param name="show">Whether the horizontal scroll bar should be visible or not when the web view is being scrolled.</param>
+ public void SetHorizontalScrollBarShow(bool show) {
+ #if UNITY_WP8
+ Debug.LogWarning("Not implemented for Windows Phone 8.");
+ #else
+ UniWebViewPlugin.SetHorizontalScrollBarShow(gameObject.name, show);
+ #endif
+ }
+
+ /// <summary>
+ /// Set web content could be debug or not. Only works for Android.
+ /// </summary>
+ /// <description>
+ /// You can enable Remote Debugging for Android devices by calling this method and passing true. See Google's
+ /// Remote Debugging Android Devices documentation for more about it.
+ /// https://developers.google.com/web/tools/chrome-devtools/debug/remote-debugging/remote-debugging
+ ///
+ /// This method will do nothing for iOS or editor.
+ /// </description>
+ /// <param name="enabled">Whether this page could be debug or not.</param>
+ public static void SetWebContentsDebuggingEnabled(bool enabled) {
+ #if UNITY_ANDROID && !UNITY_EDITOR
+ UniWebViewPlugin.SetWebContentsDebuggingEnabled(enabled);
+ #endif
+ }
+
+ private bool OrientationChanged() {
+ int newHeight = UniWebViewHelper.screenHeight;
+ if (_lastScreenHeight != newHeight) {
+ _lastScreenHeight = newHeight;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ public void ForceResize()
+ {
+ ResizeInternal();
+ }
+
+ private void ResizeInternal() {
+ int newHeight = UniWebViewHelper.screenHeight;
+ int newWidth = UniWebViewHelper.screenWidth;
+
+ UniWebViewEdgeInsets newInset = this.insets;
+ if (InsetsForScreenOreitation != null) {
+ UniWebViewOrientation orientation =
+ newHeight >= newWidth ? UniWebViewOrientation.Portrait : UniWebViewOrientation.LandScape;
+ newInset = InsetsForScreenOreitation(this, orientation);
+ }
+
+ ForceUpdateInsetsInternal(newInset);
+ }
+
+ #region Messages from native
+ public void LoadWebViewComplete(string message)
+ {
+ LoadComplete(message);
+ }
+
+ private void LoadComplete(string message) {
+ bool loadSuc = string.Equals(message, "");
+ bool hasCompleteListener = (OnLoadComplete != null);
+
+ if (loadSuc) {
+ if (hasCompleteListener) {
+ OnLoadComplete(this, true, null);
+ }
+ if (autoShowWhenLoadComplete) {
+ Show();
+ }
+ } else {
+ Debug.LogWarning("Web page load failed: " + gameObject.name + "; url: " + url + "; error:" + message);
+
+#if UNITY_EDITOR
+ if (message.Contains("App Transport Security")) {
+ Debug.LogWarning("It seems that ATS is enabled in Editor. You can not load http pages when it is on. Please visit our help center for more information: https://onevcat.zendesk.com/hc/en-us/articles/215527307-I-cannot-open-the-web-page-in-Unity-Editor-");
+ }
+#endif
+ if (hasCompleteListener) {
+ OnLoadComplete(this, false, message);
+ }
+ }
+ }
+
+ private void LoadBegin(string url) {
+ if (OnLoadBegin != null) {
+ OnLoadBegin(this, url);
+ }
+ }
+
+ private void ReceivedMessage(string rawMessage) {
+ UniWebViewMessage message = new UniWebViewMessage(rawMessage);
+ if (OnReceivedMessage != null) {
+ OnReceivedMessage(this,message);
+ }
+ }
+
+ private void WebViewDone(string message) {
+ bool destroy = true;
+ if (OnWebViewShouldClose != null) {
+ destroy = OnWebViewShouldClose(this);
+ }
+
+ if (destroy) {
+ Hide();
+ Destroy(this);
+ }
+ }
+
+ private void WebViewKeyDown(string message) {
+ int keyCode = Convert.ToInt32(message);
+ if (OnReceivedKeyCode != null) {
+ OnReceivedKeyCode(this, keyCode);
+ }
+ }
+
+ private void EvalJavaScriptFinished(string result) {
+ if (OnEvalJavaScriptFinished != null) {
+ OnEvalJavaScriptFinished(this, result);
+ }
+ }
+
+ private void AnimationFinished(string identifier) {
+
+ }
+
+ private void ShowTransitionFinished(string message) {
+ if (_showTransitionAction != null) {
+ _showTransitionAction();
+ _showTransitionAction = null;
+ }
+ }
+
+ private void HideTransitionFinished(string message) {
+ if (_hideTransitionAction != null) {
+ _hideTransitionAction();
+ _hideTransitionAction = null;
+ }
+ }
+
+ private IEnumerator LoadFromJarPackage(string jarFilePath) {
+ WWW stream = new WWW(jarFilePath);
+ yield return stream;
+ if (stream.error != null) {
+ if (OnLoadComplete != null) {
+ OnLoadComplete(this,false,stream.error);
+ }
+ yield break;
+ } else {
+ LoadHTMLString(stream.text, "");
+ }
+ }
+
+ #endregion
+
+ #region Life Cycle
+ void Awake() {
+ _currentGUID = System.Guid.NewGuid().ToString();
+ gameObject.name = gameObject.name + _currentGUID;
+ UniWebViewPlugin.Init(gameObject.name,
+ this.insets.top,
+ this.insets.left,
+ this.insets.bottom,
+ this.insets.right);
+ _lastScreenHeight = UniWebViewHelper.screenHeight;
+
+ #if UNITY_EDITOR
+ _screenScale = UniWebViewHelper.screenScale;
+ CreateTexture(this.insets.left,
+ this.insets.bottom,
+ Screen.width - this.insets.left - this.insets.right,
+ Screen.height - this.insets.top - this.insets.bottom
+ );
+ #endif
+ }
+
+ void Start() {
+ if (loadOnStart) {
+ Load();
+ }
+ }
+
+ private void OnDestroy() {
+ #if UNITY_EDITOR
+ Clean();
+ #endif
+
+ RemoveAllListeners();
+
+ UniWebViewPlugin.Destroy(gameObject.name);
+ gameObject.name = gameObject.name.Replace(_currentGUID, "");
+ }
+
+ private void RemoveAllListeners() {
+ this.OnLoadBegin = null;
+ this.OnLoadComplete = null;
+ this.OnReceivedMessage = null;
+ this.OnReceivedKeyCode = null;
+ this.OnEvalJavaScriptFinished = null;
+ this.OnWebViewShouldClose = null;
+ this.InsetsForScreenOreitation = null;
+ }
+
+ #endregion
+
+ private void Update() {
+ #if UNITY_EDITOR
+ if (Application.platform == RuntimePlatform.OSXEditor) {
+ if (_webViewId != 0 && !_hidden) {
+ if (Input.GetKeyDown(KeyCode.Escape)) {
+ if (UniWebViewPlugin.CanGoBack(gameObject.name)) {
+ UniWebViewPlugin.GoBack(gameObject.name);
+ } else {
+ WebViewDone("");
+ }
+ } else {
+ _inputString += Input.inputString;
+ }
+ }
+ }
+ #endif
+
+ //Handle screen auto orientation.
+ if (OrientationChanged()) {
+ ResizeInternal();
+ }
+ }
+
+ #region UnityEditor Debug
+ #if UNITY_EDITOR
+ private Rect _webViewRect;
+ private Texture2D _texture;
+ private string _inputString;
+ private int _webViewId;
+ private bool _hidden;
+ private IntPtr _renderCallback;
+ private int _screenScale;
+
+ private void CreateTexture(int x, int y, int width, int height) {
+ if (Application.platform == RuntimePlatform.OSXEditor) {
+ _webViewRect = new Rect(x, y, width, height);
+ _texture = new Texture2D(width * 2, height * 2, TextureFormat.ARGB32, false);
+ _texture = new Texture2D(width * _screenScale, height * _screenScale, TextureFormat.ARGB32, false);
+ }
+ }
+
+ private void Clean() {
+ if (Application.platform == RuntimePlatform.OSXEditor) {
+ Destroy(_texture);
+ _webViewId = 0;
+ _texture = null;
+ }
+ }
+
+ private void OnGUI()
+ {
+ if (Application.platform == RuntimePlatform.OSXEditor) {
+ if (_webViewId != 0 && !_hidden) {
+ Vector3 pos = Input.mousePosition;
+ bool down = Input.GetMouseButton(0);
+ bool press = Input.GetMouseButtonDown(0);
+ bool release = Input.GetMouseButtonUp(0);
+ float deltaY = Input.GetAxis("Mouse ScrollWheel");
+ bool keyPress = false;
+ string keyChars = "";
+ short keyCode = 0;
+ if (!string.IsNullOrEmpty(_inputString)) {
+ keyPress = true;
+ keyChars = _inputString.Substring(0, 1);
+ keyCode = (short)_inputString[0];
+ _inputString = _inputString.Substring(1);
+ }
+
+ var id = _texture.GetNativeTexturePtr().ToInt32();
+ UniWebViewPlugin.InputEvent(gameObject.name,
+ (int)(pos.x - _webViewRect.x), (int)(pos.y - _webViewRect.y), deltaY,
+ down, press, release, keyPress, keyCode, keyChars,
+ id);
+#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2_0
+ GL.IssuePluginEvent(_webViewId);
+#else
+
+ GL.IssuePluginEvent(UniWebViewPlugin.GetRenderEventFunc(), _webViewId);
+#endif
+ Matrix4x4 m = GUI.matrix;
+ GUI.matrix = Matrix4x4.TRS(new Vector3(0, Screen.height, 0),
+ Quaternion.identity, new Vector3(1, -1, 1));
+ GUI.DrawTexture(_webViewRect, _texture);
+ GUI.matrix = m;
+ }
+ }
+ }
+ #endif
+ #endregion
+}
+#endif //UNITY_IOS || UNITY_ANDROID
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebView.cs.meta b/Client/Assets/Scripts/UniWebView/Script/UniWebView.cs.meta new file mode 100644 index 00000000..385b2b90 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebView.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2
+guid: 2a9fa304a8f3e4a829df11f36289fdc3
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewEdgeInsets.cs b/Client/Assets/Scripts/UniWebView/Script/UniWebViewEdgeInsets.cs new file mode 100644 index 00000000..88cb8755 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewEdgeInsets.cs @@ -0,0 +1,55 @@ +//
+// UniWebViewEdgeInsets.cs
+// Created by Wang Wei(@onevcat) on 2013-10-20.
+//
+
+[System.Serializable]
+/// <summary>
+/// This class defined the edge inset of a UniWebView
+/// </summary>
+public class UniWebViewEdgeInsets {
+
+ public int top, left, bottom, right;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UniWebViewEdgeInsets"/> class.
+ /// </summary>
+ /// <param name="aTop">Top inset by point.</param>
+ /// <param name="aLeft">Left inset by point.</param>
+ /// <param name="aBottom">Bottominset by point.</param>
+ /// <param name="aRight">Rightinset by point.</param>
+ public UniWebViewEdgeInsets(int aTop, int aLeft, int aBottom, int aRight) {
+ top = aTop;
+ left = aLeft;
+ bottom = aBottom;
+ right = aRight;
+ }
+
+ public static bool operator ==(UniWebViewEdgeInsets inset1, UniWebViewEdgeInsets inset2)
+ {
+ return inset1.Equals(inset2);
+ }
+
+ public static bool operator !=(UniWebViewEdgeInsets inset1, UniWebViewEdgeInsets inset2)
+ {
+ return !inset1.Equals(inset2);
+ }
+
+ public override int GetHashCode()
+ {
+ var calculation = top + left + bottom + right;
+ return calculation.GetHashCode();
+ }
+
+ public override bool Equals (object obj)
+ {
+ if (obj == null || GetType() != obj.GetType()) {
+ return false;
+ }
+ UniWebViewEdgeInsets anInset = (UniWebViewEdgeInsets)obj;
+ return (top == anInset.top) &&
+ (left == anInset.left) &&
+ (bottom == anInset.bottom) &&
+ (right == anInset.right);
+ }
+}
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewEdgeInsets.cs.meta b/Client/Assets/Scripts/UniWebView/Script/UniWebViewEdgeInsets.cs.meta new file mode 100644 index 00000000..07f4e238 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewEdgeInsets.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2
+guid: 070d3680690c740efb440eb36c6afa09
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs b/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs new file mode 100644 index 00000000..b9a2f225 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs @@ -0,0 +1,87 @@ +//
+// UniWebViewMessage.cs
+// Created by Wang Wei(@onevcat) on 2013-10-20.
+//
+using System.Collections.Generic;
+using UnityEngine;
+
+/// <summary>
+/// This structure represent a message from webview.
+/// </summary>
+/// <description>
+/// All url with a scheme of "uniwebview" in the webpage clicked will raise
+/// the OnReceivedMessage with a UniWebViewMessage object. You can listen to
+/// that event and get path and param from webpage.
+/// </description>
+public struct UniWebViewMessage {
+ /// <summary>
+ /// Gets the raw message.
+ /// </summary>
+ /// <value>
+ /// The raw message received from UniWebView. It should be a url containing information
+ /// delivered from webview.
+ /// </value>
+ public string rawMessage {get; private set;}
+
+ /// <summary>
+ /// The url scheme of this UniWebViewMessage
+ /// </summary>
+ /// <value>The scheme.</value>
+ /// <description>
+ /// Every message UniWebView can get is a url in a registered scheme.
+ /// The default scheme is "uniwebview". You can register your own scheme by
+ /// using the RegisterScheme method on UniWebView object.
+ /// </description>
+ public string scheme {get; private set;}
+
+ /// <summary>
+ /// The path of this UniWebViewMessage
+ /// </summary>
+ /// <value>The path.</value>
+ /// <description>
+ /// A url "uniwebview://yourPath?param1=value1¶m2=value2", path = yourPath
+ /// </description>
+ public string path {get; private set;}
+
+ /// <summary>
+ /// The arguments of this UniWebViewMessage
+ /// </summary>
+ /// <value>The arguments.</value>
+ /// <description>
+ /// A url "uniwebview://yourPath?param1=value1¶m2=value2", args[param1] = value1, args[param2] = value2
+ /// </description>
+ public Dictionary<string, string> args{get; private set;}
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UniWebViewMessage"/> struct.
+ /// </summary>
+ /// <param name="rawMessage">Raw message which will be parsed to a UniWebViewMessage.</param>
+ public UniWebViewMessage(string rawMessage) : this() {
+ this.rawMessage = rawMessage;
+ string[] schemeSplit = rawMessage.Split(new string[] {"://"}, System.StringSplitOptions.None);
+ if (schemeSplit.Length >= 2) {
+ this.scheme = schemeSplit[0];
+ string pathAndArgsString = "";
+ int index = 1;
+ while (index < schemeSplit.Length) {
+ pathAndArgsString = string.Concat(pathAndArgsString, schemeSplit[index]);
+ index++;
+ }
+
+ string[] split = pathAndArgsString.Split("?"[0]);
+
+ this.path = split[0].TrimEnd('/');
+ this.args = new Dictionary<string, string>();
+ if (split.Length > 1) {
+ foreach (string pair in split[1].Split("&"[0])) {
+ string[] elems = pair.Split("="[0]);
+ if (elems.Length > 1) {
+ args[elems[0]] = WWW.UnEscapeURL(elems[1]);
+ }
+ }
+ }
+ } else {
+ Debug.LogError("Bad url scheme. Can not be parsed to UniWebViewMessage: " + rawMessage);
+ }
+ }
+}
\ No newline at end of file diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs.meta b/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs.meta new file mode 100644 index 00000000..f17ab581 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2
+guid: 241fb3bc494b043f6be899ec7ebc5c87
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewOrientation.cs b/Client/Assets/Scripts/UniWebView/Script/UniWebViewOrientation.cs new file mode 100644 index 00000000..3431794f --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewOrientation.cs @@ -0,0 +1,12 @@ +//
+// UniWebViewOrientation.cs
+// Created by Wang Wei(@onevcat) on 2014-10-7.
+//
+/// <summary>
+/// The orientation of screen. If screen height larger than width, landscape. Otherwise, portrait.
+/// </summary>
+public enum UniWebViewOrientation
+{
+ Portrait,
+ LandScape
+}
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewOrientation.cs.meta b/Client/Assets/Scripts/UniWebView/Script/UniWebViewOrientation.cs.meta new file mode 100644 index 00000000..62d08043 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewOrientation.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2
+guid: 0189ece6d321b47c1a315290f463d8d6
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewTransitionEdge.cs b/Client/Assets/Scripts/UniWebView/Script/UniWebViewTransitionEdge.cs new file mode 100644 index 00000000..06fd3e56 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewTransitionEdge.cs @@ -0,0 +1,31 @@ +//
+// UniWebViewTransitionEdge.cs
+// Created by Wang Wei(@onevcat) on 2015-11-16.
+//
+
+/// <summary>
+/// Transition edges of webview. You can specify an edge in Show() or Hide() methods of web view.
+/// </summary>
+public enum UniWebViewTransitionEdge
+{
+ /// <summary>
+ /// No transition when showing or hiding.
+ /// </summary>
+ None = 0,
+ /// <summary>
+ /// Transit the web view from/to top.
+ /// </summary>
+ Top,
+ /// <summary>
+ /// Transit the web view from/to left.
+ /// </summary>
+ Left,
+ /// <summary>
+ /// Transit the web view from/to bottom.
+ /// </summary>
+ Bottom,
+ /// <summary>
+ /// Transit the web view from/to right.
+ /// </summary>
+ Right
+}
diff --git a/Client/Assets/Scripts/UniWebView/Script/UniWebViewTransitionEdge.cs.meta b/Client/Assets/Scripts/UniWebView/Script/UniWebViewTransitionEdge.cs.meta new file mode 100644 index 00000000..97174fb3 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/UniWebViewTransitionEdge.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2
+guid: 88d71017250e84edab8ca0ddd686b55d
+timeCreated: 1447685868
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Client/Assets/Scripts/UniWebView/ThirdPartyJar.zip b/Client/Assets/Scripts/UniWebView/ThirdPartyJar.zip Binary files differnew file mode 100644 index 00000000..bbad27bb --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/ThirdPartyJar.zip diff --git a/Client/Assets/Scripts/UniWebView/ThirdPartyJar.zip.meta b/Client/Assets/Scripts/UniWebView/ThirdPartyJar.zip.meta new file mode 100644 index 00000000..85aa78f1 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/ThirdPartyJar.zip.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2
+guid: 7e38bfa74a56c43588a3bc92c6753645
+timeCreated: 1428204772
+licenseType: Free
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Client/Assets/Scripts/UniWebView/UniWeb.cs b/Client/Assets/Scripts/UniWebView/UniWeb.cs new file mode 100644 index 00000000..65467956 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/UniWeb.cs @@ -0,0 +1,589 @@ +using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+using Assets.SDK;
+using XUtliPoolLib;
+using System;
+using System.IO;
+
+/// <summary>
+/// This is a demo script to show how to use UniWebView.
+/// You can follow the step 1 to 10 and get started with the basic use of UniWebView.
+/// </summary>
+///
+
+
+public class UniWeb : MonoBehaviour
+{
+#if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
+
+#if !DISABLE_JOYSDK
+ private JoyYouSDK _interface;
+#endif
+
+ private string mAppId = "1105309683";
+ private string mOpenid = "0";
+ private string mServerid = "0";
+ private string mRoleid = "0";
+ private string mToken = "0";
+ private string mNickName = "";
+ public static IUiUtility m_uiUtility;
+ private int _gap = 90;
+ ulong mOpenTime = 0;
+ string mWebViewUrl = "https://apps.game.qq.com/gts/gtp3.0/customize/dn/end.php";
+
+ //Just let it compile on platforms beside of iOS and Android
+ //If you are just targeting for iOS and Android, you can ignore this
+
+ void Awake()
+ {
+#if !DISABLE_JOYSDK
+ _interface = new JoyYouSDK();
+#endif
+
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+ }
+
+ public void InitWebInfo(int platform, string openid, string serverid, string roleid, string nickname)
+ {
+ if (m_uiUtility == null)
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+
+ if (platform == 0)
+ mAppId = "1105309683";
+ else
+ mAppId = "wxfdab5af74990787a";
+
+ mOpenid = openid;
+ mServerid = serverid;
+ mRoleid = roleid;
+ mNickName = nickname;
+
+#if !DISABLE_JOYSDK
+ string sdkconfig = ((IHuanlePlatform)_interface).GetSDKConfig("get_login_bill", "");
+
+#if UNITY_EDITOR
+ Dictionary<string, string> testinfo = new Dictionary<string, string>();
+ testinfo["token"] = "6859034BCE654365632252";
+ testinfo["openid"] = "BAFE459486548AC698568956DEF";
+ sdkconfig = MiniJSON.Json.Serialize(testinfo);
+#endif
+ object obj = MiniJSON.Json.Deserialize(sdkconfig);
+ Dictionary<string, object> info = obj as Dictionary<string, object>;
+
+ if (info != null)
+ {
+ if (info.ContainsKey("token"))
+ mToken = info["token"] as string ;
+
+ if (info.ContainsKey("openid"))
+ mOpenid = info["openid"] as string;
+ }
+
+ Debug.Log("The openid: " + mOpenid);
+ Debug.Log("The token: " + mToken);
+#endif
+ }
+#if UNITY_IOS || UNITY_ANDROID || UNITY_EDITOR
+
+ //1. First of all, we need a reference to hold an instance of UniWebView
+ private UniWebView _webView;
+
+ private string _errorMessage;
+ private GameObject _cube;
+ private Vector3 _moveVector;
+ private bool _is_bgopen = true;
+
+ void Start()
+ {
+
+ }
+
+ public void OpenWebView()
+ {
+ Debug.Log("Will do open web view");
+
+ _gap = GetGap();
+
+ System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
+ mOpenTime = (ulong)(DateTime.Now - startTime).TotalMilliseconds;
+
+ _webView = GetComponent<UniWebView>();
+ if (_webView == null)
+ {
+ _webView = gameObject.AddComponent<UniWebView>();
+ _webView.OnReceivedMessage += OnReceivedMessage;
+ _webView.OnLoadComplete += OnLoadComplete;
+ _webView.OnWebViewShouldClose += OnWebViewShouldClose;
+ _webView.OnEvalJavaScriptFinished += OnEvalJavaScriptFinished;
+
+ _webView.InsetsForScreenOreitation += InsetsForScreenOreitation;
+ }
+
+ string url = string.Format("{0}?appid={1}&openid={2}&access_token={3}&partition={4}&roleid={5}&entertime={6}&nickname={7}",
+ mWebViewUrl, mAppId, mOpenid, mToken, mServerid, mRoleid, mOpenTime, WWW.EscapeURL(mNickName));
+
+ Debug.Log("url: " + url);
+
+ _webView.url = url; // WWW.EscapeURL(url);
+
+ Debug.Log("Final url: " + _webView.url);
+
+ Debug.Log("Width: " + Screen.width.ToString());
+ Debug.Log("Height: " + Screen.height.ToString());
+ //Debug.Log("Webview height: " + _webView.GetWebViewHeight().ToString());
+
+ _webView.Load();
+ }
+
+ public void CloseWebView(UniWebView webView)
+ {
+ if (webView == null)
+ webView = _webView;
+
+ if (webView != null)
+ {
+ webView.CleanCache();
+ webView.CleanCookie();
+ webView.Hide();
+ Destroy(webView);
+ webView.OnReceivedMessage -= OnReceivedMessage;
+ webView.OnLoadComplete -= OnLoadComplete;
+ webView.OnWebViewShouldClose -= OnWebViewShouldClose;
+ webView.OnEvalJavaScriptFinished -= OnEvalJavaScriptFinished;
+ webView.InsetsForScreenOreitation -= InsetsForScreenOreitation;
+ }
+
+ _webView = null;
+
+ _is_bgopen = true;
+
+ if (m_uiUtility == null)
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+ m_uiUtility.OnSetBg(true);
+ m_uiUtility.OnWebViewClose();
+ }
+#if UNITY_EDITOR
+ void Update() {
+
+ if (Input.GetKeyUp(KeyCode.F10))
+ {
+ string str = "uniwebview://webview?funcname=dnsetshareinfo&args=%7B%22title%22%3A%22%E5%88%86%E4%BA%AB%E6%B5%8B%E8%AF%95%E6%A0%87%E9%A2%98%22%2C%22desc%22%3A%22%E5%88%86%E4%BA%AB%E6%B5%8B%E8%AF%95%E6%8F%8F%E8%BF%B0%E6%8F%8F%E8%BF%B0%E6%8F%8F%E8%BF%B0%E3%80%82%E3%80%82%E3%80%82%E3%80%82%22%2C%22url%22%3A%22%2F%2Fiu.qq.com%2Fdn%2Fdist%2Fhtml%2Ftest.htm%22%2C%22imgurl%22%3A%22%2F%2Fgame.gtimg.cn%2Fimages%2Fiu%2Fdn%2Fb1.png%22%2C%22type%22%3A%22weixin%22%7D";
+ if (_webView == null) _webView = gameObject.AddComponent<UniWebView>();
+ UniWebViewMessage message = new UniWebViewMessage(str);
+ OnReceivedMessage(_webView, message);
+ }
+ }
+#endif
+ //5. When the webView complete loading the url sucessfully, you can show it.
+ // You can also set the autoShowWhenLoadComplete of UniWebView to show it automatically when it loads finished.
+ void OnLoadComplete(UniWebView webView, bool success, string errorMessage) {
+ if (success) {
+ webView.Show();
+ } else {
+ Debug.Log("Something wrong in webview loading: " + errorMessage);
+ _errorMessage = errorMessage;
+ }
+ }
+
+ //6. The webview can talk to Unity by a url with scheme of "uniwebview". See the webpage for more
+ // Every time a url with this scheme clicked, OnReceivedMessage of webview event get raised.
+ void OnReceivedMessage(UniWebView webView, UniWebViewMessage message)
+ {
+ Debug.Log("OnReceivedMessage");
+ Debug.Log(message.rawMessage);
+ //7. You can get the information out from the url path and query in the UniWebViewMessage
+ //For example, a url of "uniwebview://move?direction=up&distance=1" in the web page will
+ //be parsed to a UniWebViewMessage object with:
+ // message.scheme => "uniwebview"
+ // message.path => "move"
+ // message.args["direction"] => "up"
+ // message.args["distance"] => "1"
+ // "uniwebview" scheme is sending message to Unity by default.
+ // If you want to use your customized url schemes and make them sending message to UniWebView,
+ // use webView.AddUrlScheme("your_scheme") and webView.RemoveUrlScheme("your_scheme")
+ if (string.Equals(message.path, "webview"))
+ {
+ Vector3 direction = Vector3.zero;
+
+
+ if (message.args.ContainsKey("funcname"))
+ {
+ if (string.Equals(message.args["funcname"], "dnqueryuserinfo"))
+ {
+ if (message.args.ContainsKey("callback"))
+ {
+
+ Debug.Log("Will callback");
+ string callbackname = message.args["callback"];
+
+ Dictionary<string, object> jsonData = new Dictionary<string, object>();
+ jsonData["appid"] = mAppId;
+ jsonData["openid"] = mOpenid;
+ jsonData["access_token"] = mToken;
+ jsonData["partition"] = mServerid;
+ jsonData["roleid"] = mRoleid;
+ jsonData["entertime"] = mOpenTime;
+ jsonData["nickname"] = mNickName;
+ string paramStr = MiniJSON.Json.Serialize(jsonData);
+
+ //paramStr = "100539858";
+
+ string jsscript = string.Format("{0}({1})", callbackname, paramStr);
+
+ Debug.Log(jsscript);
+
+ webView.EvaluatingJavaScript(jsscript);
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnclosewebview"))
+ {
+ CloseWebView(webView);
+
+ }
+ else if (string.Equals(message.args["funcname"], "dniswifi"))
+ {
+ if (message.args.ContainsKey("callback"))
+ {
+
+ Debug.Log("Will dniswifi callback");
+ string callbackname = message.args["callback"];
+ bool iswifi = (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork);
+ int res = iswifi ? 1 : 0;
+
+ string jsscript = string.Format("{0}({1})", callbackname, res);
+
+ Debug.Log(jsscript);
+
+ webView.EvaluatingJavaScript(jsscript);
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnisbgopen"))
+ {
+ if (message.args.ContainsKey("callback"))
+ {
+
+ Debug.Log("Will dnisbgopen callback");
+ string callbackname = message.args["callback"];
+ int res = _is_bgopen ? 1 : 0;
+
+ string jsscript = string.Format("{0}({1})", callbackname, res);
+
+ Debug.Log(jsscript);
+
+ webView.EvaluatingJavaScript(jsscript);
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnopenbg"))
+ {
+ _is_bgopen = true;
+ m_uiUtility.OnSetBg(true);
+ }
+ else if (string.Equals(message.args["funcname"], "dnclosebg"))
+ {
+ _is_bgopen = false;
+ m_uiUtility.OnSetBg(false);
+ }
+ else if (string.Equals(message.args["funcname"], "dnchangemenu"))
+ {
+ if (message.args.ContainsKey("menutype"))
+ {
+ // 0: main menu 1; detail
+ int menutype = int.Parse(message.args["menutype"]);
+ m_uiUtility.OnSetWebViewMenu(menutype);
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnbackgame"))
+ {
+ if (message.args.ContainsKey("backtype"))
+ {
+ int backtype = int.Parse(message.args["backtype"]);
+ m_uiUtility.OnSetWebViewMenu(backtype);
+ }
+
+ if (message.args.ContainsKey("callback"))
+ {
+ Debug.Log("Will dnbackgame callback");
+ string callbackname = message.args["callback"];
+ string jsscript = string.Format("{0}()", callbackname);
+ Debug.Log(jsscript);
+
+ webView.EvaluatingJavaScript(jsscript);
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnrefreshredpoint"))
+ {
+ if (message.args.ContainsKey("args"))
+ {
+ string redpointinfo = WWW.UnEscapeURL(message.args["args"]);
+ Debug.Log("dnrefreshredpoint" + redpointinfo);
+ m_uiUtility.OnWebViewRefershRefPoint(redpointinfo);
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnsetheaderinfo"))
+ {
+ if (message.args.ContainsKey("args"))
+ {
+ string headerinfo = WWW.UnEscapeURL(message.args["args"]);
+ Debug.Log("dnsetheaderinfo" + headerinfo);
+ m_uiUtility.OnWebViewSetheaderInfo(headerinfo);
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnshownav"))
+ {
+ if (message.args.ContainsKey("type"))
+ {
+ int show = int.Parse(message.args["type"]);
+
+ if (show == 1)
+ _gap = GetGap();
+ else
+ _gap = 0;
+ _webView.ForceResize();
+
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dncloseloading"))
+ {
+ if (message.args.ContainsKey("show"))
+ {
+ int show = int.Parse(message.args["show"]);
+ Debug.Log("dncloseloading: " + message.args["show"]);
+
+ m_uiUtility.OnWebViewCloseLoading(show);
+
+ if (show == 1)
+ _webView.Hide();
+ else
+ _webView.Show();
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnshowreconnect"))
+ {
+ if (message.args.ContainsKey("show"))
+ {
+ int show = int.Parse(message.args["show"]);
+ Debug.Log("dnshowreconnect: " + message.args["show"]);
+
+ m_uiUtility.OnWebViewShowReconnect(show);
+
+ if (show == 1)
+ _webView.Hide();
+ else
+ _webView.Show();
+ }
+ }
+ else if (string.Equals(message.args["funcname"], "dnsetlivetab"))
+ {
+ m_uiUtility.OnWebViewLiveTab();
+ }
+ else if (string.Equals(message.args["funcname"], "dnbackhistory"))
+ {
+ _webView.GoBack();
+ }
+ else if (string.Equals(message.args["funcname"], "dnsetshareinfo"))
+ {
+ string info = WWW.UnEscapeURL(message.args["args"]);
+ //Debug.Log("dnsetshareinfo" + info);
+ Dictionary<string, object> dic = MiniJSON.Json.Deserialize(info) as Dictionary<string, object>;
+ XPlatform platf = gameObject.GetComponent<XPlatform>();
+ object title, imgUrl, desc, url, type;
+ dic.TryGetValue("title", out title);
+ dic.TryGetValue("imgurl", out imgUrl);
+ dic.TryGetValue("desc", out desc);
+ dic.TryGetValue("url", out url);
+ dic.TryGetValue("type", out type);
+ //Debug.Log("title: " + title + " url: " + url + " desc: " + desc + " img: " + imgUrl + " type: " + type);
+ if (type.Equals("qq") || type.Equals("qzone"))
+ {
+ Dictionary<string, string> jsondata = new Dictionary<string, string>();
+ jsondata["scene"] = type.Equals("qq") ? "Session" : "QZone";
+ if (url != null) jsondata["targetUrl"] = "https:"+url.ToString();
+ if (imgUrl != null) jsondata["imageUrl"] = imgUrl.ToString();
+ if (title != null) jsondata["title"] = title.ToString();
+ if (desc != null) jsondata["description"] = desc.ToString();
+ jsondata["summary"] = "";
+ string json = MiniJSON.Json.Serialize(jsondata);
+ platf.SendGameExData("share_send_to_struct_qq", json);
+ }
+ else if (type.Equals("weixin") || type.Equals("timeline"))
+ {
+ if (!gameObject.activeSelf) return;
+ StartCoroutine(DownloadPic(imgUrl.ToString(), (filepath) =>
+ {
+ //Debug.Log("cb: "+filepath);
+ if (!string.IsNullOrEmpty(filepath))
+ {
+ Dictionary<string, string> jsondata = new Dictionary<string, string>();
+ jsondata["scene"] = type.Equals("weixin") ? "Session" : "Timeline";
+ if (title != null) jsondata["title"] = title.ToString();
+ if (desc != null) jsondata["desc"] = desc.ToString();
+ if (url != null) jsondata["url"] = url.ToString();
+ jsondata["mediaTagName"] = "MSG_INVITE";
+ jsondata["filePath"] = filepath;
+ jsondata["messageExt"] = "ShareUrlWithWeixin";
+ string json = MiniJSON.Json.Serialize(jsondata);
+ platf.SendGameExData("share_send_to_with_url_wx", json);
+ }
+ }));
+ }
+ else
+ {
+ Debug.LogError("err type: " + type);
+ }
+ }
+ }
+ }
+ // else if (string.Equals(message.path, "close")) {
+ // //8. When you done your work with the webview,
+ // //you can hide it, destory it and do some clean work.
+ // webView.Hide();
+ // Destroy(webView);
+ // webView.OnReceivedMessage -= OnReceivedMessage;
+ // webView.OnLoadComplete -= OnLoadComplete;
+ // webView.OnWebViewShouldClose -= OnWebViewShouldClose;
+ // webView.OnEvalJavaScriptFinished -= OnEvalJavaScriptFinished;
+ // webView.InsetsForScreenOreitation -= InsetsForScreenOreitation;
+ // _webView = null;
+ //}
+ }
+
+
+ IEnumerator DownloadPic(string path, Action<string> cb)
+ {
+ int hash = Mathf.Abs( path.GetHashCode());
+ string dir = Application.temporaryCachePath + "/ImageCache/";
+ try
+ {
+ if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
+ }
+ catch { }
+ string pa = dir + hash;
+ if (File.Exists(pa))
+ {
+ cb(pa);
+ }
+ else
+ {
+ string url = path;
+ //print(url+" pa: "+pa);
+ WWW w = new WWW(url);
+ while (!w.isDone)
+ yield return w;
+ if (!string.IsNullOrEmpty(w.error))
+ {
+ Debug.LogError("error:"+w.error);
+ cb(string.Empty);
+ }
+ else
+ {
+ try
+ {
+ Texture2D image = w.texture;
+ byte[] pngData = image.EncodeToJPG();
+ File.WriteAllBytes(pa, pngData);
+ cb(pa);
+ }
+ catch(Exception e) { cb(string.Empty); Debug.LogError("wraite error"+e.StackTrace); }
+ }
+ w.Dispose();
+ w = null;
+ }
+ }
+
+ //9. By using EvaluatingJavaScript method, you can talk to webview from Unity.
+ //It can evel a javascript or run a js method in the web page.
+ //(In the demo, it will be called when the cube hits the sphere)
+ public void ShowAlertInWebview(float time, bool first) {
+ _moveVector = Vector3.zero;
+ if (first) {
+ //Eval the js and wait for the OnEvalJavaScriptFinished event to be raised.
+ //The sample(float time) is written in the js in webpage, in which we pop
+ //up an alert and return a demo string.
+ //When the js excute finished, OnEvalJavaScriptFinished will be raised.
+ _webView.EvaluatingJavaScript("sample(" + time +")");
+ }
+ }
+
+ //In this demo, we set the text to the return value from js.
+ void OnEvalJavaScriptFinished(UniWebView webView, string result) {
+ Debug.Log("js result: " + result);
+ }
+
+ //10. If the user close the webview by tap back button (Android) or toolbar Done button (iOS),
+ // we should set your reference to null to release it.
+ // Then we can return true here to tell the webview to dismiss.
+ bool OnWebViewShouldClose(UniWebView webView) {
+ if (webView == _webView) {
+ _webView = null;
+ return true;
+ }
+ return false;
+ }
+
+ public void EvalJsScript(string jsscript)
+ {
+ Debug.Log(jsscript);
+
+ if (jsscript.Contains("DNBackClick"))
+ {
+ if (_webView != null)
+ {
+ try
+ {
+ _webView.EvaluatingJavaScript(jsscript);
+ }
+ catch
+ {
+ CloseWebView(_webView);
+ }
+ }
+ }
+ else
+ {
+ if (_webView != null)
+ _webView.EvaluatingJavaScript(jsscript);
+ }
+
+ }
+
+ public void OnShowWebView(bool show)
+ {
+ if (_webView != null)
+ {
+ if (show)
+ _webView.Show();
+ else
+ _webView.Hide();
+ }
+ }
+
+ private int GetGap()
+ {
+#if UNITY_IOS
+ if (Screen.width == 1920)
+ return 35 * Screen.width / 1920 + (Screen.height - (Screen.width * 1080 / 1920))/4;
+ else
+ return (int)(35*1.3 * Screen.width / 1920) + (Screen.height - (Screen.width * 1080 / 1920))/4;
+#else
+ return 90 * Screen.width / 1920 + (Screen.height - (Screen.width * 1080 / 1920))/2;
+#endif
+ }
+
+ // This method will be called when the screen orientation changed. Here we returned UniWebViewEdgeInsets(5,5,bottomInset,5)
+ // for both situation. Although they seem to be the same, screenHeight was changed, leading a difference between the result.
+ // eg. on iPhone 5, bottomInset is 284 (568 * 0.5) in portrait mode while it is 160 (320 * 0.5) in landscape.
+ UniWebViewEdgeInsets InsetsForScreenOreitation(UniWebView webView, UniWebViewOrientation orientation) {
+ //int bottomInset = (int)(UniWebViewHelper.screenHeight * 0.5f);
+ //int bottomInset = (int)(UniWebViewHelper.screenHeight);
+ //int rightInset = (int)(UniWebViewHelper.screenWidth);
+
+ Debug.Log("Gap: " + _gap.ToString());
+
+ return new UniWebViewEdgeInsets(_gap, 0, 0, 0);
+ }
+#endif //End of #if UNITY_IOS || UNITY_ANDROID
+
+
+#endif
+}
diff --git a/Client/Assets/Scripts/UniWebView/UniWeb.cs.meta b/Client/Assets/Scripts/UniWebView/UniWeb.cs.meta new file mode 100644 index 00000000..d1dfccef --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/UniWeb.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2
+guid: ebd9bd53848baa043b6786b123a58ddb
+timeCreated: 1497252612
+licenseType: Pro
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
|