79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Runtime.InteropServices;
|
||
using System.Text;
|
||
using System.Web;
|
||
using UnityEngine;
|
||
using ZXKFramework;
|
||
|
||
public class WebTools : MonoBehaviour
|
||
{
|
||
[DllImport("__Internal")]
|
||
private static extern string StringReturnURLFunction();
|
||
|
||
//public string TestUrl = "https://www.zhihuishu.com/virtual_portals_h5/virtualExperiment.html#/indexPage?courseId=2000086607";
|
||
|
||
void Start()
|
||
{
|
||
|
||
#if UNITY_EDITOR
|
||
#elif UNITY_WEBGL
|
||
try
|
||
{
|
||
string loUrl = HttpUtility.UrlDecode(StringReturnURLFunction(), Encoding.UTF8);
|
||
Debug.Log("loUrl : " + loUrl);
|
||
if (!string.IsNullOrEmpty(loUrl))
|
||
{
|
||
YiLiao.Main.BaoGaoController.Instance.urlData.uuid = GetIdFromUrl(loUrl, "uuid");
|
||
YiLiao.Main.BaoGaoController.Instance.urlData.examId = GetIdFromUrl(loUrl, "examId");
|
||
YiLiao.Main.BaoGaoController.Instance.urlData.questionId = GetIdFromUrl(loUrl, "questionId");
|
||
YiLiao.Main.BaoGaoController.Instance.urlData.experimentId = GetIdFromUrl(loUrl, "experimentId");
|
||
YiLiao.Main.BaoGaoController.Instance.urlData.courseId = GetIdFromUrl(loUrl, "courseId");
|
||
Debug.Log($" URL解析数据: " + UnityTools.GetJson(YiLiao.Main.BaoGaoController.Instance.urlData));
|
||
}
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
Debug.LogError("解析Url出错:" + e);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
//if (Input.GetKeyDown(KeyCode.L))
|
||
//{
|
||
// YiLiao.BiSiFa.GameManager.Instance.uiManager.ShowUI<YiLiao.BiSiFa.KaoHePanel>();
|
||
//}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 解析URL中的参数
|
||
/// </summary>
|
||
public string GetIdFromUrl(string url, string theData)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(url)) return null;
|
||
var paramStr = url.Split('?')[1];
|
||
var paramList = paramStr.Split('&');
|
||
if (paramList == null || paramList.Count() <= 0) return null;
|
||
for (int i = 0; i < paramList.Count(); i++)
|
||
{
|
||
if (paramList[i].Split('=')[0] == theData)
|
||
{
|
||
return paramList[i].Split("=")[1];
|
||
}
|
||
}
|
||
return "";
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
Debug.Log("url解析错误 " + theData + e);
|
||
return "";
|
||
}
|
||
}
|
||
}
|