修改web平台对接逻辑
This commit is contained in:
parent
c7d31c23f2
commit
2ae75e1664
@ -1,5 +1,6 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 72fe0ae24cde45946914fa10b54896b0
|
guid: d0622dae4bc2b2a4d937ad88a765e87a
|
||||||
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
7
Assets/Resources/LYTWebGL/RSA.txt.meta
Normal file
7
Assets/Resources/LYTWebGL/RSA.txt.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fa05fa85bd33f6c4ca626c1e0317d53d
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -121,7 +121,7 @@ namespace QFramework.Example
|
|||||||
sum += float.Parse(item.Value.sum);
|
sum += float.Parse(item.Value.sum);
|
||||||
score += item.Value.value;
|
score += item.Value.value;
|
||||||
stepNames.Add(item.Value.step + item.Value.name);
|
stepNames.Add(item.Value.step + item.Value.name);
|
||||||
maxScore.Add(int.Parse(item.Value.sum));
|
maxScore.Add((int)float.Parse(item.Value.sum));
|
||||||
scores.Add((int)item.Value.value);
|
scores.Add((int)item.Value.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,21 +11,22 @@ using UnityEngine;
|
|||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
|
public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
|
||||||
{
|
{
|
||||||
private LYTWebGLHelper() { }
|
private LYTWebGLHelper() { }
|
||||||
public class LabData
|
public class LabData
|
||||||
{
|
{
|
||||||
public string GUID;
|
public string GUID;
|
||||||
public string ExpID;
|
public string ExpID;
|
||||||
public string HOST;
|
public string HOST = string.Empty;
|
||||||
public string PARA1;
|
public string PARA1;
|
||||||
public string PARA;
|
public string PARA;
|
||||||
public string PARA2;
|
public string PARA2;
|
||||||
}
|
}
|
||||||
|
#if UNITY_WEBGL
|
||||||
[DllImport("__Internal")]
|
[DllImport("__Internal")]
|
||||||
private static extern string GetURLParameter(string name);
|
private static extern string GetURLParameter(string name);
|
||||||
|
#endif
|
||||||
string token = string.Empty;
|
string token = string.Empty;
|
||||||
|
|
||||||
LabData labData = new LabData();
|
LabData labData = new LabData();
|
||||||
@ -35,10 +36,18 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
|
|||||||
|
|
||||||
public string uploadUrl;
|
public string uploadUrl;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
}
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
|
#if UNITY_WEBGL&&!UNITY_EDITOR
|
||||||
token = GetURLParameter("token").Replace("%2B", "+");
|
token = GetURLParameter("token").Replace("%2B", "+");
|
||||||
RSA = Resources.Load<TextAsset>("RSA");
|
#endif
|
||||||
|
RSA = Resources.Load<TextAsset>("LYTWebGL/RSA");
|
||||||
|
if (string.IsNullOrEmpty(token) == false)
|
||||||
|
{
|
||||||
string urlData = Decrypt(token);
|
string urlData = Decrypt(token);
|
||||||
var datas = urlData.Split("&");
|
var datas = urlData.Split("&");
|
||||||
labData.GUID = datas[0];
|
labData.GUID = datas[0];
|
||||||
@ -47,7 +56,7 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
|
|||||||
labData.PARA1 = datas[3];
|
labData.PARA1 = datas[3];
|
||||||
labData.PARA = datas[4];
|
labData.PARA = datas[4];
|
||||||
labData.PARA2 = datas[5];
|
labData.PARA2 = datas[5];
|
||||||
|
}
|
||||||
uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/");
|
uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -87,7 +96,9 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
|
|||||||
{
|
{
|
||||||
var data = new UploadData();
|
var data = new UploadData();
|
||||||
data.GUID = labData.GUID;
|
data.GUID = labData.GUID;
|
||||||
data.ExpID = int.Parse(labData.ExpID);
|
int expId = 0;
|
||||||
|
int.TryParse(labData.ExpID, out expId);
|
||||||
|
data.ExpID = expId;
|
||||||
data.score = totalScore;
|
data.score = totalScore;
|
||||||
data.flag = true;
|
data.flag = true;
|
||||||
|
|
||||||
@ -101,7 +112,7 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
|
|||||||
}
|
}
|
||||||
data.ExpStepVTwoList = list.ToArray();
|
data.ExpStepVTwoList = list.ToArray();
|
||||||
|
|
||||||
SendScore(JsonConvert.SerializeObject(data));
|
StartCoroutine(SendScore(JsonConvert.SerializeObject(data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator SendScore(string json, UnityAction<string> action = null)
|
IEnumerator SendScore(string json, UnityAction<string> action = null)
|
||||||
@ -122,6 +133,7 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
|
|||||||
if (request.result == UnityWebRequest.Result.ConnectionError ||
|
if (request.result == UnityWebRequest.Result.ConnectionError ||
|
||||||
request.result == UnityWebRequest.Result.ProtocolError)
|
request.result == UnityWebRequest.Result.ProtocolError)
|
||||||
{
|
{
|
||||||
|
Debug.LogError($"Upload failed: {request.uri}");
|
||||||
Debug.LogError($"Upload failed: {request.error}");
|
Debug.LogError($"Upload failed: {request.error}");
|
||||||
Debug.LogError($"Response Code: {request.responseCode}");
|
Debug.LogError($"Response Code: {request.responseCode}");
|
||||||
}
|
}
|
||||||
|
|||||||
23
Assets/WebPlatform/WebTest.cs
Normal file
23
Assets/WebPlatform/WebTest.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class WebTest : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
List<string> stepNames = new List<string>() { "µÚÒ»²½", "µÚ¶þ²½", "µÚÈý²½" };
|
||||||
|
List<int> maxScore = new List<int>() { 10, 20, 30 };
|
||||||
|
List<int> score = new List<int>() { 5, 10, 15 };
|
||||||
|
LYTWebGLHelper.Instance.UpLoadData(60, stepNames, maxScore, score);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/WebPlatform/WebTest.cs.meta
Normal file
11
Assets/WebPlatform/WebTest.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 08f51ad357b70604492d4c3e95ce1e27
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user