From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/UniWebView/Script/UniWebViewMessage.cs | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs (limited to 'Client/Assets/Scripts/UniWebView/Script/UniWebViewMessage.cs') 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; + +/// +/// This structure represent a message from webview. +/// +/// +/// 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. +/// +public struct UniWebViewMessage { + /// + /// Gets the raw message. + /// + /// + /// The raw message received from UniWebView. It should be a url containing information + /// delivered from webview. + /// + public string rawMessage {get; private set;} + + /// + /// The url scheme of this UniWebViewMessage + /// + /// The scheme. + /// + /// 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. + /// + public string scheme {get; private set;} + + /// + /// The path of this UniWebViewMessage + /// + /// The path. + /// + /// A url "uniwebview://yourPath?param1=value1¶m2=value2", path = yourPath + /// + public string path {get; private set;} + + /// + /// The arguments of this UniWebViewMessage + /// + /// The arguments. + /// + /// A url "uniwebview://yourPath?param1=value1¶m2=value2", args[param1] = value1, args[param2] = value2 + /// + public Dictionary args{get; private set;} + + /// + /// Initializes a new instance of the struct. + /// + /// Raw message which will be parsed to a UniWebViewMessage. + 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(); + 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 -- cgit v1.1-26-g67d0