UnityEngine.Object DeserializeUnityObjectInner() { // Ignore InstanceID field (compatibility only) var fieldName = EatField(); if (fieldName == "InstanceID") { EatField(); fieldName = EatField(); } if (fieldName != "Name") { throw new Exception("Expected 'Name' field"); } string name = EatField(); if (name == null) { return(null); } if (EatField() != "Type") { throw new Exception("Expected 'Type' field"); } string typename = EatField(); // Remove assembly information if (typename.IndexOf(',') != -1) { typename = typename.Substring(0, typename.IndexOf(',')); } // Note calling through assembly is more stable on e.g WebGL var type = WindowsStoreCompatibility.GetTypeInfo(typeof(AstarPath)).Assembly.GetType(typename); type = type ?? WindowsStoreCompatibility.GetTypeInfo(typeof(Transform)).Assembly.GetType(typename); if (Type.Equals(type, null)) { Debug.LogError("Could not find type '" + typename + "'. Cannot deserialize Unity reference"); return(null); } // Check if there is another field there EatWhitespace(); if ((char)reader.Peek() == '"') { if (EatField() != "GUID") { throw new Exception("Expected 'GUID' field"); } string guid = EatField(); foreach (var helper in UnityEngine.Object.FindObjectsOfType <UnityReferenceHelper>()) { if (helper.GetGUID() == guid) { if (Type.Equals(type, typeof(GameObject))) { return(helper.gameObject); } else { return(helper.GetComponent(type)); } } } } // Try to load from resources UnityEngine.Object[] objs = Resources.LoadAll(name, type); for (int i = 0; i < objs.Length; i++) { if (objs[i].name == name || objs.Length == 1) { return(objs[i]); } } return(null); }
private object Deserialize(Type tp, object populate = null) { Type typeInfo = WindowsStoreCompatibility.GetTypeInfo(tp); if (typeInfo.IsEnum) { return(Enum.Parse(tp, this.EatField())); } if (this.TryEat('n')) { this.Eat("ull"); this.TryEat(','); return(null); } if (object.Equals(tp, typeof(float))) { return(float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat)); } if (object.Equals(tp, typeof(int))) { return(int.Parse(this.EatField(), TinyJsonDeserializer.numberFormat)); } if (object.Equals(tp, typeof(uint))) { return(uint.Parse(this.EatField(), TinyJsonDeserializer.numberFormat)); } if (object.Equals(tp, typeof(bool))) { return(bool.Parse(this.EatField())); } if (object.Equals(tp, typeof(string))) { return(this.EatField()); } if (object.Equals(tp, typeof(Version))) { return(new Version(this.EatField())); } if (object.Equals(tp, typeof(Vector2))) { this.Eat("{"); Vector2 vector = default(Vector2); this.EatField(); vector.x = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat); this.EatField(); vector.y = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat); this.Eat("}"); return(vector); } if (object.Equals(tp, typeof(Vector3))) { this.Eat("{"); Vector3 vector2 = default(Vector3); this.EatField(); vector2.x = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat); this.EatField(); vector2.y = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat); this.EatField(); vector2.z = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat); this.Eat("}"); return(vector2); } if (object.Equals(tp, typeof(Pathfinding.Util.Guid))) { this.Eat("{"); this.EatField(); Pathfinding.Util.Guid guid = Pathfinding.Util.Guid.Parse(this.EatField()); this.Eat("}"); return(guid); } if (object.Equals(tp, typeof(LayerMask))) { this.Eat("{"); this.EatField(); LayerMask layerMask = int.Parse(this.EatField()); this.Eat("}"); return(layerMask); } if (object.Equals(tp, typeof(List <string>))) { IList list = new List <string>(); this.Eat("["); while (!this.TryEat(']')) { list.Add(this.Deserialize(typeof(string), null)); this.TryEat(','); } return(list); } if (typeInfo.IsArray) { List <object> list2 = new List <object>(); this.Eat("["); while (!this.TryEat(']')) { list2.Add(this.Deserialize(tp.GetElementType(), null)); this.TryEat(','); } Array array = Array.CreateInstance(tp.GetElementType(), list2.Count); list2.ToArray().CopyTo(array, 0); return(array); } if (object.Equals(tp, typeof(Mesh)) || object.Equals(tp, typeof(Texture2D)) || object.Equals(tp, typeof(Transform)) || object.Equals(tp, typeof(GameObject))) { return(this.DeserializeUnityObject()); } object obj = populate ?? Activator.CreateInstance(tp); this.Eat("{"); while (!this.TryEat('}')) { string name = this.EatField(); FieldInfo field = tp.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { this.SkipFieldData(); } else { field.SetValue(obj, this.Deserialize(field.FieldType, null)); } this.TryEat(','); } return(obj); }
/** Deserializes an object of type tp. * Will load all fields into the \a populate object if it is set (only works for classes). */ System.Object Deserialize(Type tp, System.Object populate = null) { var tpInfo = WindowsStoreCompatibility.GetTypeInfo(tp); if (tpInfo.IsEnum) { return(Enum.Parse(tp, EatField())); } else if (TryEat('n')) { Eat("ull"); TryEat(','); return(null); } else if (Type.Equals(tp, typeof(float))) { return(float.Parse(EatField(), numberFormat)); } else if (Type.Equals(tp, typeof(int))) { return(int.Parse(EatField(), numberFormat)); } else if (Type.Equals(tp, typeof(uint))) { return(uint.Parse(EatField(), numberFormat)); } else if (Type.Equals(tp, typeof(bool))) { return(bool.Parse(EatField())); } else if (Type.Equals(tp, typeof(string))) { return(EatField()); } else if (Type.Equals(tp, typeof(Version))) { return(new Version(EatField())); } else if (Type.Equals(tp, typeof(Vector2))) { Eat("{"); var result = new Vector2(); EatField(); result.x = float.Parse(EatField(), numberFormat); EatField(); result.y = float.Parse(EatField(), numberFormat); Eat("}"); return(result); } else if (Type.Equals(tp, typeof(Vector3))) { Eat("{"); var result = new Vector3(); EatField(); result.x = float.Parse(EatField(), numberFormat); EatField(); result.y = float.Parse(EatField(), numberFormat); EatField(); result.z = float.Parse(EatField(), numberFormat); Eat("}"); return(result); } else if (Type.Equals(tp, typeof(Pathfinding.Util.Guid))) { Eat("{"); EatField(); var result = Pathfinding.Util.Guid.Parse(EatField()); Eat("}"); return(result); } else if (Type.Equals(tp, typeof(LayerMask))) { Eat("{"); EatField(); var result = (LayerMask)int.Parse(EatField()); Eat("}"); return(result); } else if (Type.Equals(tp, typeof(List <string>))) { System.Collections.IList result = new List <string>(); Eat("["); while (!TryEat(']')) { result.Add(Deserialize(typeof(string))); TryEat(','); } return(result); } else if (tpInfo.IsArray) { List <System.Object> ls = new List <System.Object>(); Eat("["); while (!TryEat(']')) { ls.Add(Deserialize(tp.GetElementType())); TryEat(','); } var arr = Array.CreateInstance(tp.GetElementType(), ls.Count); ls.ToArray().CopyTo(arr, 0); return(arr); } else if (Type.Equals(tp, typeof(Mesh)) || Type.Equals(tp, typeof(Texture2D)) || Type.Equals(tp, typeof(Transform)) || Type.Equals(tp, typeof(GameObject))) { return(DeserializeUnityObject()); } else { var obj = populate ?? Activator.CreateInstance(tp); Eat("{"); while (!TryEat('}')) { var name = EatField(); var tmpType = tp; System.Reflection.FieldInfo field = null; while (field == null && tmpType != null) { field = tmpType.GetField(name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic); tmpType = tmpType.BaseType; } if (field == null) { SkipFieldData(); } else { field.SetValue(obj, Deserialize(field.FieldType)); } TryEat(','); } return(obj); } }
private UnityEngine.Object DeserializeUnityObjectInner() { string a = this.EatField(); if (a == "InstanceID") { this.EatField(); a = this.EatField(); } if (a != "Name") { throw new Exception("Expected 'Name' field"); } string text = this.EatField(); if (text == null) { return(null); } if (this.EatField() != "Type") { throw new Exception("Expected 'Type' field"); } string text2 = this.EatField(); if (text2.IndexOf(',') != -1) { text2 = text2.Substring(0, text2.IndexOf(',')); } Type type = WindowsStoreCompatibility.GetTypeInfo(typeof(AstarPath)).Assembly.GetType(text2); type = (type ?? WindowsStoreCompatibility.GetTypeInfo(typeof(Transform)).Assembly.GetType(text2)); if (object.Equals(type, null)) { Debug.LogError("Could not find type '" + text2 + "'. Cannot deserialize Unity reference"); return(null); } this.EatWhitespace(); if ((ushort)this.reader.Peek() == 34) { if (this.EatField() != "GUID") { throw new Exception("Expected 'GUID' field"); } string b = this.EatField(); UnityReferenceHelper[] array = UnityEngine.Object.FindObjectsOfType <UnityReferenceHelper>(); int i = 0; while (i < array.Length) { UnityReferenceHelper unityReferenceHelper = array[i]; if (unityReferenceHelper.GetGUID() == b) { if (object.Equals(type, typeof(GameObject))) { return(unityReferenceHelper.gameObject); } return(unityReferenceHelper.GetComponent(type)); } else { i++; } } } UnityEngine.Object[] array2 = Resources.LoadAll(text, type); for (int j = 0; j < array2.Length; j++) { if (array2[j].name == text || array2.Length == 1) { return(array2[j]); } } return(null); }
void Serialize(System.Object obj) { if (obj == null) { output.Append("null"); return; } var type = obj.GetType(); var typeInfo = WindowsStoreCompatibility.GetTypeInfo(type); if (serializers.ContainsKey(type)) { serializers[type] (obj); } else if (typeInfo.IsEnum) { output.Append('"' + obj.ToString() + '"'); } else if (obj is System.Collections.IList) { output.Append("["); var arr = obj as System.Collections.IList; for (int i = 0; i < arr.Count; i++) { if (i != 0) { output.Append(", "); } Serialize(arr[i]); } output.Append("]"); } else if (obj is UnityEngine.Object) { SerializeUnityObject(obj as UnityEngine.Object); } else { #if NETFX_CORE var optIn = typeInfo.CustomAttributes.Any(attr => attr.GetType() == typeof(JsonOptInAttribute)); #else var optIn = typeInfo.GetCustomAttributes(typeof(JsonOptInAttribute), true).Length > 0; #endif output.Append("{"); bool earlier = false; while (true) { #if NETFX_CORE var fields = typeInfo.DeclaredFields.Where(f => !f.IsStatic).ToArray(); #else var fields = type.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic); #endif foreach (var field in fields) { if (field.DeclaringType != type) { continue; } if ((!optIn && field.IsPublic) || #if NETFX_CORE field.CustomAttributes.Any(attr => attr.GetType() == typeof(JsonMemberAttribute)) #else field.GetCustomAttributes(typeof(JsonMemberAttribute), true).Length > 0 #endif ) { if (earlier) { output.Append(", "); } earlier = true; output.AppendFormat("\"{0}\": ", field.Name); Serialize(field.GetValue(obj)); } } #if NETFX_CORE typeInfo = typeInfo.BaseType; if (typeInfo == null) { break; } #else type = type.BaseType; if (type == null) { break; } #endif } output.Append("}"); } }
/** Returns the first graph which inherits from the type \a type. Returns null if no graph was found. */ public NavGraph FindGraphWhichInheritsFrom(System.Type type) { return(FindGraph(graph => WindowsStoreCompatibility.GetTypeInfo(type).IsAssignableFrom(WindowsStoreCompatibility.GetTypeInfo(graph.GetType())))); }
// Token: 0x06002815 RID: 10261 RVA: 0x001B6830 File Offset: 0x001B4A30 private void Serialize(object obj) { if (obj == null) { this.output.Append("null"); return; } Type type = obj.GetType(); Type typeInfo = WindowsStoreCompatibility.GetTypeInfo(type); if (this.serializers.ContainsKey(type)) { this.serializers[type](obj); return; } if (typeInfo.IsEnum) { this.output.Append("\"" + obj.ToString() + "\""); return; } if (obj is IList) { this.output.Append("["); IList list = obj as IList; for (int i = 0; i < list.Count; i++) { if (i != 0) { this.output.Append(", "); } this.Serialize(list[i]); } this.output.Append("]"); return; } if (obj is UnityEngine.Object) { this.SerializeUnityObject(obj as UnityEngine.Object); return; } bool flag = typeInfo.GetCustomAttributes(typeof(JsonOptInAttribute), true).Length != 0; this.output.Append("{"); bool flag2 = false; do { foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (!(fieldInfo.DeclaringType != type) && ((!flag && fieldInfo.IsPublic) || fieldInfo.GetCustomAttributes(typeof(JsonMemberAttribute), true).Length != 0)) { if (flag2) { this.output.Append(", "); } flag2 = true; this.output.AppendFormat("\"{0}\": ", fieldInfo.Name); this.Serialize(fieldInfo.GetValue(obj)); } } type = type.BaseType; }while (!(type == null)); this.output.Append("}"); }
// Token: 0x060021F7 RID: 8695 RVA: 0x00191008 File Offset: 0x0018F208 public NavGraph FindGraphWhichInheritsFrom(Type type) { return(this.FindGraph((NavGraph graph) => WindowsStoreCompatibility.GetTypeInfo(type).IsAssignableFrom(WindowsStoreCompatibility.GetTypeInfo(graph.GetType())))); }