using Newtonsoft.Json.Linq;
using UnityEngine;
namespace LLM.Editor.Helper
{
///
/// Provides extension methods for converting JToken objects to Unity-specific types.
///
public static class JsonExtensions
{
public static Vector3 ToVector3(this JToken token)
{
if (token is not JObject obj) return Vector3.zero;
var x = obj["x"]?.Value() ?? 0f;
var y = obj["y"]?.Value() ?? 0f;
var z = obj["z"]?.Value() ?? 0f;
return new Vector3(x, y, z);
}
public static Quaternion ToQuaternion(this JToken token)
{
if (token is not JObject obj) return Quaternion.identity;
var x = obj["x"]?.Value() ?? 0f;
var y = obj["y"]?.Value() ?? 0f;
var z = obj["z"]?.Value() ?? 0f;
var w = obj["w"]?.Value() ?? 1f;
return new Quaternion(x, y, z, w);
}
}
}