|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using UnityEngine; |
|
|
|
namespace UnityEngine.Graphing |
|
|
|
namespace UnityEditor.Graphing |
|
|
|
{ |
|
|
|
public static class SerializationHelper |
|
|
|
{ |
|
|
|
|
|
|
[SerializeField] |
|
|
|
public string fullName; |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
public string assemblyName; |
|
|
|
return !string.IsNullOrEmpty(fullName) && !string.IsNullOrEmpty(assemblyName); |
|
|
|
} |
|
|
|
|
|
|
|
public string SearchString() |
|
|
|
{ |
|
|
|
if (!IsValid()) |
|
|
|
return string.Empty; |
|
|
|
|
|
|
|
return string.Format("{0}, {1}", fullName, assemblyName); |
|
|
|
} |
|
|
|
|
|
|
|
public string SearchStringTestable() |
|
|
|
{ |
|
|
|
if (!IsValid()) |
|
|
|
return string.Empty; |
|
|
|
|
|
|
|
return string.Format("{0}, {1}-testable", fullName, assemblyName); |
|
|
|
return !string.IsNullOrEmpty(fullName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
return new TypeSerializationInfo |
|
|
|
{ |
|
|
|
fullName = type.FullName, |
|
|
|
assemblyName = type.Assembly.GetName().Name |
|
|
|
fullName = type.FullName |
|
|
|
private static Type GetTypeFromSerializedString(TypeSerializationInfo typeInfo) |
|
|
|
static Type GetTypeFromSerializedString(TypeSerializationInfo typeInfo) |
|
|
|
var res = Type.GetType(typeInfo.SearchString()); |
|
|
|
var assemblies = AppDomain.CurrentDomain.GetAssemblies(); |
|
|
|
foreach (var assembly in assemblies) |
|
|
|
{ |
|
|
|
var type = assembly.GetType(typeInfo.fullName); |
|
|
|
if (type != null) |
|
|
|
return type; |
|
|
|
} |
|
|
|
// if we are using a 'testable' dll.
|
|
|
|
if (res == null) |
|
|
|
res = Type.GetType(typeInfo.SearchStringTestable()); |
|
|
|
|
|
|
|
return res; |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static JSONSerializedElement Serialize<T>(T item) |
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private static TypeSerializationInfo DoTypeRemap(TypeSerializationInfo info, Dictionary<TypeSerializationInfo, TypeSerializationInfo> remapper) |
|
|
|
static TypeSerializationInfo DoTypeRemap(TypeSerializationInfo info, Dictionary<TypeSerializationInfo, TypeSerializationInfo> remapper) |
|
|
|
{ |
|
|
|
TypeSerializationInfo foundInfo; |
|
|
|
if (remapper.TryGetValue(info, out foundInfo)) |
|
|
|
|
|
|
throw new ArgumentException(string.Format("Can not deserialize {0}, it is invalid", item)); |
|
|
|
|
|
|
|
TypeSerializationInfo info = item.typeInfo; |
|
|
|
info.fullName = info.fullName.Replace("UnityEngine.MaterialGraph", "UnityEditor.ShaderGraph"); |
|
|
|
info.fullName = info.fullName.Replace("UnityEngine.Graphing", "UnityEditor.Graphing"); |
|
|
|
info.assemblyName = "Assembly-CSharp-Editor"; |
|
|
|
throw new ArgumentException(string.Format("Can not deserialize ({0}, {1}), type is invalid", info.assemblyName, info.fullName)); |
|
|
|
throw new ArgumentException(string.Format("Can not deserialize ({0}), type is invalid", info.fullName)); |
|
|
|
|
|
|
|
T instance; |
|
|
|
try |
|
|
|