public static MonsterTestList GetInstance() { if (!XMLSerializable.bSafeToLoad) { TypeUtils.RegisterAllTypes(); } if (MonsterTestList.ManagerInst == null) { LoadMonsterTestList(); } return(MonsterTestList.ManagerInst); }
public static void RegisterEditorTypes() { TypeUtils.RegisterAllTypes(); List <Type> InspectableTypes = IgorRuntimeUtils.GetTypesInheritFrom <InspectableObject>(); foreach (Type CurrentInspectableType in InspectableTypes) { MethodInfo RegisterFunction = CurrentInspectableType.GetMethod("RegisterEditorType", BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly); if (RegisterFunction != null) { RegisterFunction.Invoke(null, new object[] {}); } } }
public static void SerializeFromXML <SerializeType>(string Filename, ref SerializeType ToSerialize, bool bSaving, XmlSerializer Serializer = null) where SerializeType : XMLSerializable { if (bSaving) { XmlSerializer SpecificSerializer = Serializer; if (SpecificSerializer == null) { try { SpecificSerializer = new XmlSerializer(typeof(SerializeType)); } catch (Exception Ex) { if (Ex != null) { Debug.LogError("Error creating an XML serializer for type " + typeof(SerializeType).ToString() + "!! Exception message is\n" + Ex.Message + "\nAnd inner exception is\n" + Ex.InnerException.Message); } } } GuaranteePathExists(Filename); TextWriter SpecificWriter = new StreamWriter(Filename); try { SpecificSerializer.Serialize(SpecificWriter, ToSerialize); } catch (Exception Ex) { if (Ex != null) { Debug.LogError("Error serializing an XML file!! Exception message is\n" + Ex.Message + "\nAnd inner exception is\n" + Ex.InnerException.Message); } } ToSerialize.PostSerialize(); SpecificWriter.Close(); } else { if (!bSafeToLoad) { TypeUtils.RegisterAllTypes(); // ToSerialize = null; // return; } #if !UNITY_EDITOR if (Filename.StartsWith("Assets/Resources/")) { XmlSerializer SpecificSerializer = Serializer; if (SpecificSerializer == null) { SpecificSerializer = new XmlSerializer(typeof(SerializeType)); } string ResourcePath = Filename.Substring("Assets/Resources/".Length); ResourcePath = ResourcePath.Substring(0, ResourcePath.Length - 4); TextAsset XMLAsset = (TextAsset)Resources.Load(ResourcePath, typeof(TextAsset)); if (XMLAsset != null) { string RawXML = XMLAsset.text; TextReader SpecificReader = new StringReader(RawXML); ToSerialize = (SerializeType)SpecificSerializer.Deserialize(SpecificReader); ToSerialize.PostSerialize(); SpecificReader.Close(); } else { Debug.LogError("Failed to load XML from resource file with name " + ResourcePath); } } else { if (!Filename.Contains("GameSaves")) { Debug.LogError("Trying to serialize in an XML file that isn't in the resources folder. Filename is " + Filename); } #else { #endif if (File.Exists(Filename)) { XmlSerializer SpecificSerializer = Serializer; if (SpecificSerializer == null) { try { SpecificSerializer = new XmlSerializer(typeof(SerializeType)); } catch (Exception Ex) { if (Ex != null) { Debug.LogError("Error creating an XML deserializer for type " + typeof(SerializeType).ToString() + "!! Exception message is\n" + Ex.Message + "\nAnd inner exception is\n" + Ex.InnerException.Message); } } } TextReader SpecificReader = new StreamReader(Filename); try { ToSerialize = (SerializeType)SpecificSerializer.Deserialize(SpecificReader); } catch (Exception Ex) { if (Ex != null) { Debug.LogError("Error deserializing an XML file!! Exception message is\n" + Ex.Message + "\nAnd inner exception is\n" + Ex.InnerException != null ? Ex.InnerException.Message : ""); } } ToSerialize.PostSerialize(); SpecificReader.Close(); } } } }