Skip to content

Instantly share code, notes, and snippets.

@hananoki
Last active February 23, 2020 13:24
Show Gist options
  • Save hananoki/250cba64275495c27450bad37d64ed20 to your computer and use it in GitHub Desktop.
Save hananoki/250cba64275495c27450bad37d64ed20 to your computer and use it in GitHub Desktop.
UnityEditor.Jsonを扱えるようにしたもの
/// Copyright (c) 2020 hananoki
/// This code is released under NYSL Version 0.9982
/// See http://www.kmonos.net/nysl/NYSL.TXT
using System;
using System.Reflection;
public static class UnityEditorJson {
static Type s_UnityEditor_Json;
static Type UnityEditor_Json {
get {
if( s_UnityEditor_Json == null ) {
s_UnityEditor_Json = Assembly.Load( "UnityEditor.dll" ).GetType( "UnityEditor.Json" );
}
return s_UnityEditor_Json;
}
}
static MethodInfo s_UnityEditor_Json_Deserialize;
static MethodInfo UnityEditor_Json_Deserialize {
get {
if( s_UnityEditor_Json_Deserialize == null ) {
s_UnityEditor_Json_Deserialize = UnityEditor_Json.GetMethod( "Deserialize", flag );
}
return s_UnityEditor_Json_Deserialize;
}
}
static MethodInfo s_UnityEditor_Serialize;
static MethodInfo UnityEditor_Serialize {
get {
if( s_UnityEditor_Serialize == null ) {
s_UnityEditor_Serialize = UnityEditor_Json.GetMethod( "Serialize", flag );
}
return s_UnityEditor_Serialize;
}
}
const BindingFlags flag = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
public static object Deserialize( string json ) {
return UnityEditor_Json_Deserialize.Invoke( null, new object[] { json } );
}
public static string Serialize( object obj, bool pretty = false, string indentText = " " ) {
return (string) UnityEditor_Serialize.Invoke( null, new object[] { obj, pretty, indentText } );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment