我很难在检查器中恢复我的变量 id

Ihave difficulties to recover my variable id in the inspector

你能帮我在 unity 的检查器中获取 id 的值吗? 我在 unity 控制台中有一个 json,我做了一个程序来访问这个 json 中的数据,然后在 unity inspector 中恢复它。对于“位置”它是有效的但对于“id”没有。试了很多方法都没用

这是我在启动函数和更新函数中的代码,我已经搜索过但没有找到如何为 id:

我正在使用 SimpleJSON。

if(mono != null)
{
     JSONNode id = Face["mono"]["id"].AsInt; 
     JSONNode position = Face["mono"]["position"];
     Vector3 pos = new Vector3(position["x"].AsFloat, position["y"].AsFloat, position["z"].AsFloat);
     int ident = new ident(id);
    
     x = pos.x;
     y = pos.y;
     z = pos.z;
     id= ident.id;
}

private void Update()
{
     Vector3 newPosition = new Vector3(x, y, z);
     gameObject.transform.localPosition = newPosition;
}

这是我的 json: { “命令”:“数据”, "frame_time": "2021-06-10T11:16:54.678596+00:00", "start_time": "2021-06-10T10:35:40.516632+00:00", “流”:[ { “名称”:“usb0.1245.2”, “对象”:[ { “名字”:“脸”, “单核细胞增多症”: { “编号”:“18”, “位置”: { “x”:“0.073997”, “y”:“-0.024979”, “z”:“0.677220” } }, “多”: [ { “编号”:“18”, “位置”: { “x”:“0.073997”, “y”:“-0.024979”, “z”:“0.677220” } } ] } ] } ], “播放”:{“列表”:“测试”, “项目”:“right_key” } }

如果您从 Face["mono"]["id"].AsInt; 获得 int,您可以在检查器中设置它,方法是设置 class 的 public[SerializeField] private 变量像这样:

public myInt = 0; //also [SerializeField] private myInt = 0;
if(mono != null)
{
     myInt = Face["mono"]["id"].AsInt; 
     JSONNode position = Face["mono"]["position"];
     Vector3 pos = new Vector3(position["x"].AsFloat, position["y"].AsFloat, position["z"].AsFloat);
     int ident = new ident(id);
    
     x = pos.x;
     y = pos.y;
     z = pos.z;
     id= ident.id;
}

private void Update()
{
     Vector3 newPosition = new Vector3(x, y, z);
     gameObject.transform.localPosition = newPosition;
}