在为我的游戏添加云端存储数据的功能,查看了教程编写了代码,制作了按钮用以上传数据,但是unity一直在报错,在网页端也没有更新显示
这是我的脚本:
using LC.Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using LeanCloud;
using LeanCloud.Storage;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LeanCloudSetup : MonoBehaviour
{
public static Player player;
public static string playerObjectId;
public HealthController healthController;
public EX ex;//引用等级
public zhaoyun_move zhaoyunMove;
public AttackController attackController;
public Button uploadDataButton;
private void Awake()
{
LCApplication.Initialize("appID", "appKey", "MasterKey");
player = new Player();
playerObjectId = "0001"; // 你需要替换这个值为你的玩家数据ID
uploadDataButton.onClick.AddListener(() =>
{
UpdateAllPlayerData();
Debug.Log("上传数据");
});
SceneManager.sceneUnloaded += OnSceneUnloaded;
}
public async void UpdateAllPlayerData()
{
player.Hp = healthController.currentHealth;
player.Ex = ex.level;
player.Sp = zhaoyunMove.moveSpeed;
player.Attack = attackController.attackDamage;
LCObject lc = LCObject.CreateWithoutData("GameData", playerObjectId);
lc["Hp"] = player.Hp;
lc["Ex"] = player.Ex;
lc["Sp"] = player.Sp;
lc["Attack"] = player.Attack;
//lc["Hero"] = player.Hero;
try
{
await lc.Save();
Debug.Log("数据上传成功");
}
catch (LCException e)
{
Debug.LogError($"数据上传失败: {e}");
}
}
private void OnSceneUnloaded(Scene scene)
{
player.Hp = healthController.currentHealth;
player.Ex = ex.level;
player.Sp = zhaoyunMove.moveSpeed;
player.Attack = attackController.attackDamage;
UpdateAllPlayerData();
}
}
[System.Serializable]
public class Player
{
//public string Id;
public int Hp;
public int Ex;
public float Sp;
public int Attack;
//public string Hero;
}
这是我的报错提示:
UriFormatException: Invalid URI: The format of the URI could not be determined.
System.Uri.CreateThis (System.String uri, System.Boolean dontEscape, System.UriKind uriKind) (at :0)
System.Uri..ctor (System.String uriString) (at :0)
LeanCloud.Common.LCHttpClient+d__191[T].MoveNext () (at /home/runner/work/csharp-sdk/csharp-sdk/Common/Common/Http/LCHttpClient.cs:118)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter
1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
LeanCloud.Storage.LCObject+d__42.MoveNext () (at /home/runner/work/csharp-sdk/csharp-sdk/Storage/Storage/Public/LCObject.cs:392)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
LeanCloudSetup+d__8.MoveNext () (at Assets/CloudData/Scripts/LeanCloudSetup.cs:60)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <446b65dcd6d04c88a7c163e46d5bf39b>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()