/// <summary> /// Save the specified asset's preset data to file at specified path. /// </summary> /// <param name="asset">The asset's preset data will be saved</param> /// <param name="filePath">The file to save to</param> public static void SaveAssetPresetToFile(HEU_HoudiniAsset asset, string filePath) { // This should return an object filled with preset data, and which we can serialize directly HEU_AssetPreset assetPreset = asset.GetAssetPreset(); if (assetPreset != null) { try { int len = PRESET_IDENTIFIER.Length; assetPreset._identifier = PRESET_IDENTIFIER; assetPreset._version = PRESET_VERSION; using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { IFormatter formatter = new BinaryFormatter(); HEU_Vector3SerializationSurrogate vector3S = new HEU_Vector3SerializationSurrogate(); HEU_Vector2SerializationSurrogate vector2S = new HEU_Vector2SerializationSurrogate(); SurrogateSelector surrogateSelector = new SurrogateSelector(); surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), vector3S); surrogateSelector.AddSurrogate(typeof(Vector2), new StreamingContext(StreamingContextStates.All), vector2S); formatter.SurrogateSelector = surrogateSelector; formatter.Serialize(fs, assetPreset); } } catch (System.Exception ex) { Debug.LogErrorFormat("Failed to save preset due to exception: " + ex.ToString()); } } else { Debug.LogErrorFormat("Failed to save preset due to unable to retrieve the preset buffer!"); } }