Version: 2019.4
public static void FromJsonOverwrite (string json, object objectToOverwrite);

パラメーター

jsonオブジェクトの JSON 表現
objectToOverwrite上書きするオブジェクト

説明

JSON 表現から読み取ることでオブジェクトのデータを上書きします。

This is similar to JsonUtility.FromJsonOverwrite, but it supports any engine object. The fields available are the same as are accessible via the SerializedObject API, or as found in the YAML-serialized form of the object.

Note that using this method with a struct may not do what you expect because structs are passed to the method by value and not by reference. This means that instead of the method overwriting your original struct, a boxed copy of the struct is passed into the method and overwritten. You can avoid this by making your own boxed copy of the struct to pass into the method and then copying the values back again after the method returns. See example below.

Even when you do this, Unity’s built-in structs (such as Vector3 or Bounds) cannot be directly passed to the method, so you must enclose Unity’s built-in structs inside a wrapper class or struct.

using UnityEngine;
using UnityEditor;

[System.Serializable] struct MyStruct { public int value; }

public class StructExample : MonoBehaviour { void Start() { MyStruct myStruct = new MyStruct(); object boxedStruct = myStruct; var json = @"{ ""value"" : 42 }"; EditorJsonUtility.FromJsonOverwrite(json, boxedStruct); myStruct = (MyStruct)boxedStruct; Debug.Log("myStruct.value = " + myStruct.value); } }