Files
XRLib/Assets/Scripts/Simulator/UpdateValueStack.cs
2026-02-25 16:30:12 +09:00

56 lines
1.3 KiB
C#

using Cysharp.Threading.Tasks;
using Newtonsoft.Json;
using Simulator.Config;
using Simulator.Data;
using System;
using System.Collections.Generic;
using UnityEngine;
using UVC.Network;
namespace Simulator.Data
{
[Serializable]
public class Patches
{
public List<Patch> patches=new List<Patch>();
}
[Serializable]
public class Patch
{
public string path;
public object value;
}
public class UpdateValueStack : MonoBehaviour
{
static Dictionary<string,object> patches=new Dictionary<string,object>();
public static void AddPatch(string path, object value)
{
if (patches.ContainsKey(path))
{
patches[path] = value;
}
else
{
patches.Add(path, value);
}
}
public static async UniTask Save()
{
Patches change = new Patches();
foreach (var patch in patches)
{
Patch pa = new Patch();
pa.path = patch.Key;
pa.value = patch.Value;
change.patches.Add(pa);
}
var data=JsonConvert.SerializeObject(change);
Debug.Log(data);
var request = await HttpRequester.Request_<Totaljson>($"{Constants.HTTP_DOMAIN}/simulation/logics/{SimulationConfig.logicId}/data", data, methodString:"patch", null,true);
Debug.Log(request.code);
patches.Clear();
}
}
}