public static void SerializeToFile(SoundToolKitMaterial material) { if (SoundToolKitManager.Instance != null && material != null) { // Create json file with serialized material var customJsonDirectory = Path.Combine(Path.Combine(Application.streamingAssetsPath, SOUNDTOOLKIT_JSON_MATERIALS_PATH), "Custom"); Directory.CreateDirectory(customJsonDirectory); var name = "Custom " + material.name; var serializedData = SoundToolKit.Extensions.Scene.MaterialsSerializer.Serialize(SoundToolKitManager.Instance.StkAudioEngine, material.GetStkMaterial()); customJsonDirectory = Path.Combine(customJsonDirectory, name); customJsonDirectory = Path.ChangeExtension(customJsonDirectory, ".json"); File.WriteAllText(customJsonDirectory, serializedData); // Create SoundToolKitMaterial Asset from a newly serialized material var directoryRelativeToRoot = Path.GetDirectoryName(customJsonDirectory.Substring( customJsonDirectory.IndexOf(MATERIAL_DIRECTORY) + MATERIAL_DIRECTORY.Length)); var materialDirectory = Path.Combine(SOUNDTOOLKIT_MATERIALS_PATH, directoryRelativeToRoot); var relativeJsonPath = customJsonDirectory.Substring( customJsonDirectory.IndexOf(SOUNDTOOLKIT_JSON_MATERIALS_PATH)); Directory.CreateDirectory(materialDirectory); CreateAcousticMaterial(materialDirectory, relativeJsonPath); SoundToolKitDebug.Log(name + " SoundToolKitMaterial successfully created. " + "Corresponding Material config file available in StreamingAssets/SoundToolKit/Materials/Custom"); } }
public void Remove(SoundToolKitMaterial acousticMaterial) { SoundToolKitDebug.Assert(acousticMaterial != null, "Material is null"); if (AcousticMaterials.Contains(acousticMaterial)) { m_acousticMaterials.Remove(acousticMaterial); } else { SoundToolKitDebug.LogWarning("Material wasn't registered."); } }
public void Add(SoundToolKitMaterial acousticMaterial) { SoundToolKitDebug.Assert(acousticMaterial != null, "Material is null"); if (!AcousticMaterials.Contains(acousticMaterial)) { m_acousticMaterials.Add(acousticMaterial); } else { SoundToolKitDebug.LogWarning("Material already registered."); } }