// Load the WwiseSettings structure from a serialized XML file public static WwiseSettings LoadSettings(bool ForceLoad = false) { if (s_Instance != null && !ForceLoad) { return(s_Instance); } WwiseSettings Settings = new WwiseSettings(); try { if (File.Exists(Path.Combine(Application.dataPath, WwiseSettingsFilename))) { XmlSerializer xmlSerializer = new XmlSerializer(Settings.GetType()); FileStream xmlFileStream = new FileStream(Application.dataPath + "/" + WwiseSettingsFilename, FileMode.Open, FileAccess.Read); Settings = (WwiseSettings)xmlSerializer.Deserialize(xmlFileStream); xmlFileStream.Close(); } else { string projectDir = Path.GetDirectoryName(Application.dataPath); string[] foundWwiseProjects = Directory.GetFiles(projectDir, "*.wproj", SearchOption.AllDirectories); if (foundWwiseProjects.Length == 0) { Settings.WwiseProjectPath = ""; } else { // MONO BUG: https://github.com/mono/mono/pull/471 // In the editor, Application.dataPath returns <Project Folder>/Assets. There is a bug in // mono for method Uri.GetRelativeUri where if the path ends in a folder, it will // ignore the last part of the path. Thus, we need to add fake depth to get the "real" // relative path. Settings.WwiseProjectPath = AkUtilities.MakeRelativePath(Application.dataPath + "/fake_depth", foundWwiseProjects[0]); } Settings.SoundbankPath = AkInitializer.c_DefaultBasePath; } s_Instance = Settings; } catch (Exception) { } return(Settings); }
// Load the WwiseSettings structure from a serialized XML file public static WwiseSettings LoadSettings(bool ForceLoad = false) { if (s_Instance != null && !ForceLoad) { return(s_Instance); } var Settings = new WwiseSettings(); try { if (System.IO.File.Exists(System.IO.Path.Combine(UnityEngine.Application.dataPath, WwiseSettingsFilename))) { var xmlSerializer = new System.Xml.Serialization.XmlSerializer(Settings.GetType()); var xmlFileStream = new System.IO.FileStream(UnityEngine.Application.dataPath + "/" + WwiseSettingsFilename, System.IO.FileMode.Open, System.IO.FileAccess.Read); Settings = (WwiseSettings)xmlSerializer.Deserialize(xmlFileStream); xmlFileStream.Close(); } else { var projectDir = System.IO.Path.GetDirectoryName(UnityEngine.Application.dataPath); var foundWwiseProjects = System.IO.Directory.GetFiles(projectDir, "*.wproj", System.IO.SearchOption.AllDirectories); if (foundWwiseProjects.Length == 0) { Settings.WwiseProjectPath = ""; } else { Settings.WwiseProjectPath = AkUtilities.MakeRelativePath(UnityEngine.Application.dataPath, foundWwiseProjects[0]); } Settings.SoundbankPath = AkSoundEngineController.s_DefaultBasePath; } s_Instance = Settings; } catch (System.Exception) { } return(Settings); }
// Load the WwiseSettings structure from a serialized XML file public static WwiseSettings LoadSettings(bool ForceLoad = false) { if (s_Instance != null && !ForceLoad) return s_Instance; WwiseSettings Settings = new WwiseSettings(); try { if (File.Exists(Path.Combine(Application.dataPath, WwiseSettingsFilename))) { XmlSerializer xmlSerializer = new XmlSerializer(Settings.GetType()); FileStream xmlFileStream = new FileStream(Application.dataPath + "/" + WwiseSettingsFilename, FileMode.Open, FileAccess.Read); Settings = (WwiseSettings)xmlSerializer.Deserialize(xmlFileStream); xmlFileStream.Close(); } else { string projectDir = Path.GetDirectoryName(Application.dataPath); string[] foundWwiseProjects = Directory.GetFiles(projectDir, "*.wproj", SearchOption.AllDirectories); if (foundWwiseProjects.Length == 0) { Settings.WwiseProjectPath = ""; } else { // MONO BUG: https://github.com/mono/mono/pull/471 // In the editor, Application.dataPath returns <Project Folder>/Assets. There is a bug in // mono for method Uri.GetRelativeUri where if the path ends in a folder, it will // ignore the last part of the path. Thus, we need to add fake depth to get the "real" // relative path. Settings.WwiseProjectPath = AkUtilities.MakeRelativePath(Application.dataPath + "/fake_depth", foundWwiseProjects[0]); } Settings.SoundbankPath = AkInitializer.c_DefaultBasePath; } s_Instance = Settings; } catch (Exception) { } return Settings; }
// Save the WwiseSettings structure to a serialized XML file public static void SaveSettings(WwiseSettings Settings) { try { var xmlDoc = new System.Xml.XmlDocument(); var xmlSerializer = new System.Xml.Serialization.XmlSerializer(Settings.GetType()); using (var xmlStream = new System.IO.MemoryStream()) { var streamWriter = new System.IO.StreamWriter(xmlStream, System.Text.Encoding.UTF8); xmlSerializer.Serialize(streamWriter, Settings); xmlStream.Position = 0; xmlDoc.Load(xmlStream); xmlDoc.Save(System.IO.Path.Combine(UnityEngine.Application.dataPath, WwiseSettingsFilename)); } } catch (System.Exception) { } }
// Save the WwiseSettings structure to a serialized XML file public static void SaveSettings(WwiseSettings Settings) { try { XmlDocument xmlDoc = new XmlDocument(); XmlSerializer xmlSerializer = new XmlSerializer(Settings.GetType()); using (MemoryStream xmlStream = new MemoryStream()) { xmlSerializer.Serialize(xmlStream, Settings); xmlStream.Position = 0; xmlDoc.Load(xmlStream); xmlDoc.Save(Path.Combine(Application.dataPath, WwiseSettingsFilename)); } } catch (Exception) { return; } }
// Save the WwiseSettings structure to a serialized XML file public static void SaveSettings(WwiseSettings Settings) { try { XmlDocument xmlDoc = new XmlDocument(); XmlSerializer xmlSerializer = new XmlSerializer(Settings.GetType()); using (MemoryStream xmlStream = new MemoryStream()) { StreamWriter streamWriter = new StreamWriter( xmlStream, System.Text.Encoding.UTF8 ); xmlSerializer.Serialize(streamWriter, Settings); xmlStream.Position = 0; xmlDoc.Load(xmlStream); xmlDoc.Save(Path.Combine(Application.dataPath, WwiseSettingsFilename)); } } catch (Exception) { return; } }