英文版本,pc分享功能,移动端fb分享,修改细节

This commit is contained in:
Caiyanpeng committed 2022-02-22 18:11:26 +08:00
1 parent 2c7d02ec9a
commit 768f8261da
13 files changed
+322 -216

No files matched your search

@@ -6,25 +6,84 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
#if UNITY_STANDALONE_WIN
using ZenFulcrum.EmbeddedBrowser;
#endif
public class ActivityController : PFUIPanel
{
Transform browser;
#if UNITY_STANDALONE_WIN
Browser webView;
#else
UniWebView webView;
#endif
protected override void Awake()
{
this.url = null;
browser = transform.Find("Browser");
#if UNITY_STANDALONE_WIN
webView = browser.GetComponent<Browser>();
webView.onLoad -= RegisterFunc;
webView.onLoad += RegisterFunc;
#if UNITY_EDITOR
webView.ShowDevTools(true);
#endif
#else
webView = browser.GetComponent<UniWebView>();
#endif
//webView.Show();
}
#if UNITY_STANDALONE_WIN
private void RegisterFunc(JSONNode obj)
{
RunJavaScript($"navigator.pfLang = '{App.GetLocalLanguage()}';");
webView.RegisterFunction("Close", args =>
{
Debug.Log("执行返回");
CloseFunc();
});
webView.RegisterFunction("StartRide", args =>
{
if (args.Count == 2)
{
StartRide((int)args[0], args[1]);
}
});
webView.RegisterFunction("OpenUrl", args =>
{
if (args.Count == 1)
{
OpenUrl(args[0]);
}
});
webView.RegisterFunction("Share", args =>
{
if (args.Count == 2)
{
Share((int)args[0], (int)args[1]);
}
});
}
#endif
public override void Show()
{
base.Show();
//Debug.Log(20);
//Invoke("StartPageFunc",0.5f);
}
#if UNITY_STANDALONE_WIN
private void StartPageFunc(Action action = null)
{
if (action == null)
{
webView.LoadURL(url, true);
}
else
{
action.Invoke();
}
}
#else
private void StartPageFunc(Action action = null)
{
Debug.Log("开始");
@@ -51,23 +110,21 @@ public class ActivityController : PFUIPanel
switch (message.Path)
{
case "Close": CloseFunc(); break;
case "StartRide": StartRide(message.Args); break;
case "Share": Share(message.Args); break;
case "OpenUrl": OpenUrl(message.Args); break;
case "StartRide": StartRide(int.Parse(message.Args["id"]),message.Args.ContainsKey("routeResult")?message.Args["routeResult"]:null); break;
case "Share": Share(int.Parse(message.Args["type"]),int.Parse(message.Args["id"])); break;
case "OpenUrl": OpenUrl(message.Args["url"]); break;
default:break;
}
}
#endif
private void OpenUrl(Dictionary<string, string> args)
private void OpenUrl(string url)
{
Application.OpenURL(System.Net.WebUtility.UrlDecode(args["url"]));
Application.OpenURL(System.Net.WebUtility.UrlDecode(url));
}
private void Share(Dictionary<string, string> args)
private void Share(int type,int id)
{
int type = int.Parse(args["type"]);
int id = int.Parse(args["id"]);
string url = $"http://192.168.0.101:3081/Activity/LightUpChina/Share?userId={App.CurrentUser.Id}";
if (type < 2)
{
@@ -76,21 +133,26 @@ public class ActivityController : PFUIPanel
App.weChatController.ShareWebpageToWX(type, url, "点亮中国活动", "by " + App.CurrentUser.Nickname, null);
}
}
else
else if (type == 2)
{
UnityEngine.GUIUtility.systemCopyBuffer = url;
RunJavaScript("window.postMessage(\"webview;复制成功\")");
}
else
{
Facebook.Unity.FB.ShareLink(contentURL: new Uri(url),
contentTitle: "点亮中国活动",
contentDescription: "By " + App.CurrentUser.Nickname,
photoURL: new Uri(App.CurrentUser.WxHeadImg));
}
}
private void StartRide(Dictionary<string, string> args)
private void StartRide(int id,string routeResult)
{
var id = int.Parse(args["id"]);
App.RouteIdParam = id;
if (args.ContainsKey("routeResult"))
if (routeResult!=null)
{
Debug.Log(args.ContainsKey("routeResult"));
App.routeResult = JsonConvert.DeserializeObject<RouteResult>(args["routeResult"]);
App.routeResult = JsonConvert.DeserializeObject<RouteResult>(routeResult);
}
SceneManager.LoadScene("Ride");
}
@@ -103,7 +165,11 @@ public class ActivityController : PFUIPanel
private void RunJavaScript(string js)
{
#if UNITY_STANDALONE_WIN
webView.EvalJS(js);
#else
browser.GetComponent<UniWebView>().EvaluateJavaScript(js);
#endif
}
// Update is called once per frame
void Update()
@@ -127,5 +193,6 @@ public class ActivityController : PFUIPanel
RunJavaScript("window.postMessage(\"webview;Refresh\")");
});
}
}
}