Unity graph tool solution based on different implementation now focused on Unity.Experimental.Graphview
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
956 B

using System;
using Newtonsoft.Json;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace TNode.JsonSerialize{
public class UnityObjectConverter:JsonConverter<Object>{
public override void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer){
//Holding the object reference in a string
var go = value;
var guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(go));
writer.WriteValue(value.GetInstanceID().ToString());
}
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, bool hasExistingValue,
JsonSerializer serializer){
//Reading the object reference from the string
var guid = reader.Value.ToString();
var go = AssetDatabase.LoadAssetAtPath<Object>(AssetDatabase.GUIDToAssetPath(guid));
return go;
}
}
}