public static void DescribeBankBuses(FMOD.Studio.Bank bank) { FMOD.Studio.Bus[] buses = { }; bank.getBusList(out buses); foreach (FMOD.Studio.Bus bus in buses) { Guid busid = new Guid(); bus.getID(out busid); string busPathString = ""; bus.getPath(out busPathString); Log.Info(" Bus: {0} - path: {1}", busid.ToString(), busPathString); } }
public static void DescribeBankEvents(FMOD.Studio.Bank bank) { FMOD.Studio.EventDescription[] descs = { }; bank.getEventList(out descs); foreach (FMOD.Studio.EventDescription desc in descs) { Guid eventid = new Guid(); desc.getID(out eventid); string eventPathString = ""; desc.getPath(out eventPathString); Log.Info(" Event: {0} - path: {1}", eventid.ToString(), eventPathString); } }
public void LoadBankSamples(FMOD.Studio.Bank bank) { Console.WriteLine("Loading sample data"); Utilities.checkResult(bank.loadSampleData()); _system.update(); FMOD.Studio.LOADING_STATE lState; do { Utilities.checkResult(bank.getSampleLoadingState(out lState)); Console.WriteLine(lState.ToString()); Task.Delay(200).Wait(); }while (lState != FMOD.Studio.LOADING_STATE.LOADED); }
public static void PreviewStop() { if (previewEventInstance != null) { previewEventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); previewEventInstance.release(); previewEventInstance = null; previewEventDesc = null; if (previewBank != null) { previewBank.unload(); } masterBank.unload(); masterBank = null; previewBank = null; previewState = PreviewState.Stopped; } }
private void UnloadAllBankSampleData() { int bankCount; Instance.studioSystem.getBankCount(out bankCount); if (bankCount > 0) { FMOD.Studio.Bank[] bankArray = new FMOD.Studio.Bank[bankCount]; Instance.studioSystem.getBankList(out bankArray); for (int i = 0; i < bankCount; i++) { int eventCount; bankArray[i].getEventCount(out eventCount); if (eventCount > 0) { FMOD.Studio.EventDescription[] eventArray = new FMOD.Studio.EventDescription[eventCount]; bankArray[i].getEventList(out eventArray); for (int j = 0; j < eventCount; j++) { int instanceCount; eventArray[j].getInstanceCount(out instanceCount); if (instanceCount > 0) { FMOD.Studio.EventInstance[] instanceArray = new FMOD.Studio.EventInstance[instanceCount]; eventArray[j].getInstanceList(out instanceArray); for (int k = 0; k < instanceCount; k++) { instanceArray[k].stop(FMOD.Studio.STOP_MODE.IMMEDIATE); instanceArray[k].release(); } } } } } for (int i = 0; i < bankCount; i++) { bankArray[i].unloadSampleData(); } } }
public static void PreviewEvent(EditorEventRef eventRef) { bool load = true; if (previewEventDesc != null) { Guid guid; previewEventDesc.getID(out guid); if (guid == eventRef.Guid) { load = false; } else { PreviewStop(); } } if (load) { CheckResult(System.loadBankFile(EventManager.MasterBank.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out masterBank)); if (eventRef.Banks[0] != EventManager.MasterBank) { CheckResult(System.loadBankFile(eventRef.Banks[0].Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out previewBank)); } else { previewBank = null; } CheckResult(System.getEventByID(eventRef.Guid, out previewEventDesc)); CheckResult(previewEventDesc.createInstance(out previewEventInstance)); } CheckResult(previewEventInstance.start()); previewState = PreviewState.Playing; }
public static void PreviewStop() { if (previewEventInstance != null) { previewEventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); previewEventInstance.release(); previewEventInstance = null; previewEventDesc = null; if (previewBank != null) { previewBank.unload(); } masterBank.unload(); masterBank = null; previewBank = null; previewState = PreviewState.Stopped; } }
public static void PreviewEvent(EditorEventRef eventRef) { bool load = true; if (previewEventDesc != null) { Guid guid; previewEventDesc.getID(out guid); if (guid == eventRef.Guid) { load = false; } else { PreviewStop(); } } if (load) { CheckResult(System.loadBankFile(EventManager.MasterBank.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out masterBank)); if (eventRef.Banks[0] != EventManager.MasterBank) { CheckResult(System.loadBankFile(eventRef.Banks[0].Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out previewBank)); } else { previewBank = null; } CheckResult(System.getEventByID(eventRef.Guid, out previewEventDesc)); CheckResult(previewEventDesc.createInstance(out previewEventInstance)); } CheckResult(previewEventInstance.start()); previewState = PreviewState.Playing; }
static void UpdateCache() { if (EditorUtils.GetBankDirectory() == null) { if (eventCache.StringsBankWriteTime != DateTime.MinValue) { eventCache.StringsBankWriteTime = DateTime.MinValue; eventCache.EditorBanks.Clear(); eventCache.EditorEvents.Clear(); OnCacheChange(); } return; } string defaultBankFolder = null; if (!Settings.Instance.HasPlatforms) { defaultBankFolder = EditorUtils.GetBankDirectory(); } else { defaultBankFolder = Path.Combine(EditorUtils.GetBankDirectory(), Settings.Instance.GetBankPlatform(FMODPlatform.PlayInEditor)); } string[] bankPlatforms = EditorUtils.GetBankPlatforms(); string[] bankFolders = new string[bankPlatforms.Length]; for (int i = 0; i < bankPlatforms.Length; i++) { bankFolders[i] = Path.Combine(EditorUtils.GetBankDirectory(), bankPlatforms[i]); } string[] stringBanks = new string[0]; try { stringBanks = Directory.GetFiles(defaultBankFolder, "*." + StringBankExtension); } catch { } if (stringBanks.Length == 0) { if (eventCache.StringsBankWriteTime != DateTime.MinValue) { eventCache.StringsBankWriteTime = DateTime.MinValue; eventCache.EditorBanks.Clear(); eventCache.EditorEvents.Clear(); OnCacheChange(); UnityEngine.Debug.LogWarningFormat("FMOD Studio: Directory {0} doesn't contain any banks. Build from the tool or check the path in the settings", defaultBankFolder); } return; } // If we have multiple .strings.bank files find the most recent Array.Sort(stringBanks, (a, b) => File.GetLastWriteTime(b).CompareTo(File.GetLastWriteTime(a))); string stringBankPath = stringBanks[0]; // Use the string bank timestamp as a marker for the most recent build of any bank because it gets exported every time if (File.GetLastWriteTime(stringBankPath) <= eventCache.StringsBankWriteTime) { return; } eventCache.StringsBankWriteTime = File.GetLastWriteTime(stringBankPath); string masterBankFileName = Path.GetFileName(stringBankPath).Replace(StringBankExtension, BankExtension); FMOD.Studio.Bank stringBank = null; EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (stringBank == null) { if (eventCache.StringsBankWriteTime != DateTime.MinValue) { eventCache.StringsBankWriteTime = DateTime.MinValue; eventCache.EditorBanks.Clear(); eventCache.EditorEvents.Clear(); OnCacheChange(); } return; } // Iterate every string in the strings bank and look for any that identify banks int stringCount; stringBank.getStringCount(out stringCount); List <string> bankFileNames = new List <string>(); for (int stringIndex = 0; stringIndex < stringCount; stringIndex++) { string currentString; Guid currentGuid; stringBank.getStringInfo(stringIndex, out currentGuid, out currentString); const string BankPrefix = "bank:/"; int BankPrefixLength = BankPrefix.Length; if (currentString.StartsWith(BankPrefix)) { string bankFileName = currentString.Substring(BankPrefixLength) + "." + BankExtension; if (!bankFileName.Contains(StringBankExtension)) // filter out the strings bank { bankFileNames.Add(bankFileName); } } } eventCache.EditorBanks.ForEach((x) => x.Exists = false); foreach (string bankFileName in bankFileNames) { string bankPath = Path.Combine(defaultBankFolder, bankFileName); EditorBankRef bankRef = eventCache.EditorBanks.Find((x) => bankPath == x.Path); // New bank we've never seen before if (bankRef == null) { bankRef = ScriptableObject.CreateInstance <EditorBankRef>(); AssetDatabase.AddObjectToAsset(bankRef, CacheAssetFullName); bankRef.Path = bankPath; bankRef.LastModified = DateTime.MinValue; bankRef.FileSizes = new List <EditorBankRef.NameValuePair>(); eventCache.EditorBanks.Add(bankRef); } bankRef.Exists = true; // Timestamp check - if it doesn't match update events from that bank if (bankRef.LastModified != File.GetLastWriteTime(bankPath)) { bankRef.LastModified = File.GetLastWriteTime(bankPath); UpdateCacheBank(bankRef); } // Update file sizes bankRef.FileSizes.Clear(); for (int i = 0; i < bankPlatforms.Length; i++) { string platformBankPath = Path.Combine(bankFolders[i], bankFileName); var fileInfo = new FileInfo(platformBankPath); if (fileInfo.Exists) { bankRef.FileSizes.Add(new EditorBankRef.NameValuePair(bankPlatforms[i], fileInfo.Length)); } } if (bankFileName == masterBankFileName) { eventCache.MasterBankRef = bankRef; } } // Unload the strings bank stringBank.unload(); // Remove any stale entries from bank and event lists eventCache.EditorBanks.FindAll((x) => !x.Exists).ForEach(RemoveCacheBank); eventCache.EditorBanks.RemoveAll((x) => !x.Exists); eventCache.EditorEvents.RemoveAll((x) => x.Banks.Count == 0); OnCacheChange(); }
public Bank(FMOD.Studio.Bank bank, FMOD.Studio.Bank stringsBank) { this.bank = bank; this.stringsBank = stringsBank; }
static public void UpdateCache() { // Deserialize the cache from the unity resources if (eventCache == null) { eventCache = AssetDatabase.LoadAssetAtPath(CacheAssetFullName, typeof(EventCache)) as EventCache; if (eventCache == null || eventCache.cacheVersion != EventCache.CurrentCacheVersion) { UnityEngine.Debug.Log("FMOD Studio: Cannot find serialized event cache or cache in old format, creating new instance"); eventCache = ScriptableObject.CreateInstance <EventCache>(); eventCache.cacheVersion = EventCache.CurrentCacheVersion; AssetDatabase.CreateAsset(eventCache, CacheAssetFullName); } } if (EditorUtils.GetBankDirectory() == null) { ClearCache(); return; } string defaultBankFolder = null; if (!Settings.Instance.HasPlatforms) { defaultBankFolder = EditorUtils.GetBankDirectory(); } else { FMODPlatform platform = RuntimeUtils.GetEditorFMODPlatform(); if (platform == FMODPlatform.None) { platform = FMODPlatform.PlayInEditor; } defaultBankFolder = Path.Combine(EditorUtils.GetBankDirectory(), Settings.Instance.GetBankPlatform(platform)); } string[] bankPlatforms = EditorUtils.GetBankPlatforms(); string[] bankFolders = new string[bankPlatforms.Length]; for (int i = 0; i < bankPlatforms.Length; i++) { bankFolders[i] = Path.Combine(EditorUtils.GetBankDirectory(), bankPlatforms[i]); } List <String> stringBanks = new List <string>(0); try { var files = Directory.GetFiles(defaultBankFolder, "*." + StringBankExtension); stringBanks = new List <string>(files); } catch { } // Strip out OSX resource-fork files that appear on FAT32 stringBanks.RemoveAll((x) => Path.GetFileName(x).StartsWith("._")); if (stringBanks.Count == 0) { bool wasValid = eventCache.StringsBankWriteTime != DateTime.MinValue; ClearCache(); if (wasValid) { UnityEngine.Debug.LogError(String.Format("FMOD Studio: Directory {0} doesn't contain any banks. Build from the tool or check the path in the settings", defaultBankFolder)); } return; } // If we have multiple .strings.bank files find the most recent stringBanks.Sort((a, b) => File.GetLastWriteTime(b).CompareTo(File.GetLastWriteTime(a))); string stringBankPath = stringBanks[0]; // Use the string bank timestamp as a marker for the most recent build of any bank because it gets exported every time if (File.GetLastWriteTime(stringBankPath) == eventCache.StringsBankWriteTime) { countdownTimer = CountdownTimerReset; return; } if (EditorUtils.IsFileOpenByStudio(stringBankPath)) { countdownTimer = CountdownTimerReset; return; } FMOD.Studio.Bank stringBank = null; EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (stringBank == null) { countdownTimer = CountdownTimerReset; return; } // Iterate every string in the strings bank and look for any that identify banks int stringCount; stringBank.getStringCount(out stringCount); List <string> bankFileNames = new List <string>(); for (int stringIndex = 0; stringIndex < stringCount; stringIndex++) { string currentString; Guid currentGuid; stringBank.getStringInfo(stringIndex, out currentGuid, out currentString); const string BankPrefix = "bank:/"; int BankPrefixLength = BankPrefix.Length; if (currentString.StartsWith(BankPrefix)) { string bankFileName = currentString.Substring(BankPrefixLength) + "." + BankExtension; if (!bankFileName.Contains(StringBankExtension)) // filter out the strings bank { bankFileNames.Add(bankFileName); } } } // Unload the strings bank stringBank.unload(); // Check if any of the files are still being written by studio foreach (string bankFileName in bankFileNames) { string bankPath = Path.Combine(defaultBankFolder, bankFileName); if (!File.Exists(bankPath)) { // TODO: this is meant to catch the case where we're in the middle of a build and a bank is being built // for the first time. But it also stops someone trying to import an incomplete set of banks without any error message. countdownTimer = CountdownTimerReset; return; } EditorBankRef bankRef = eventCache.EditorBanks.Find((x) => bankPath == x.Path); if (bankRef == null) { if (EditorUtils.IsFileOpenByStudio(bankPath)) { countdownTimer = CountdownTimerReset; return; } continue; } if (bankRef.LastModified != File.GetLastWriteTime(bankPath)) { if (EditorUtils.IsFileOpenByStudio(bankPath)) { countdownTimer = CountdownTimerReset; return; } } } // Count down the timer in case we catch studio in-between updating two files. if (countdownTimer-- > 0) { return; } // All files are finished being modified by studio so update the cache // Stop editor preview so no stale data being held EditorUtils.PreviewStop(); // Reload the strings bank EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (stringBank == null) { ClearCache(); return; } FileInfo stringBankFileInfo = new FileInfo(stringBankPath); eventCache.StringsBankWriteTime = stringBankFileInfo.LastWriteTime; string masterBankFileName = Path.GetFileName(stringBankPath).Replace(StringBankExtension, BankExtension); AssetDatabase.StartAssetEditing(); if (eventCache.StringsBankRef == null) { eventCache.StringsBankRef = ScriptableObject.CreateInstance <EditorBankRef>(); eventCache.StringsBankRef.FileSizes = new List <EditorBankRef.NameValuePair>(); eventCache.EditorBanks.Add(eventCache.StringsBankRef); AssetDatabase.AddObjectToAsset(eventCache.StringsBankRef, eventCache); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(eventCache.StringsBankRef)); } eventCache.StringsBankRef.Path = stringBankPath; eventCache.StringsBankRef.LastModified = eventCache.StringsBankWriteTime; eventCache.StringsBankRef.FileSizes.Clear(); if (Settings.Instance.HasPlatforms) { for (int i = 0; i < bankPlatforms.Length; i++) { eventCache.StringsBankRef.FileSizes.Add(new EditorBankRef.NameValuePair(bankPlatforms[i], stringBankFileInfo.Length)); } } else { eventCache.StringsBankRef.FileSizes.Add(new EditorBankRef.NameValuePair("", stringBankFileInfo.Length)); } eventCache.EditorBanks.ForEach((x) => x.Exists = false); eventCache.StringsBankRef.Exists = true; string[] folderContents = Directory.GetFiles(defaultBankFolder); foreach (string bankFileName in bankFileNames) { // Get the true file path, can't trust the character case we got from the string bank string bankPath = ArrayUtility.Find(folderContents, x => (string.Equals(bankFileName, Path.GetFileName(x), StringComparison.CurrentCultureIgnoreCase))); FileInfo bankFileInfo = new FileInfo(bankPath); EditorBankRef bankRef = eventCache.EditorBanks.Find((x) => bankFileInfo.FullName == x.Path); // New bank we've never seen before if (bankRef == null) { bankRef = ScriptableObject.CreateInstance <EditorBankRef>(); AssetDatabase.AddObjectToAsset(bankRef, eventCache); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(bankRef)); bankRef.Path = bankFileInfo.FullName; bankRef.LastModified = DateTime.MinValue; bankRef.FileSizes = new List <EditorBankRef.NameValuePair>(); eventCache.EditorBanks.Add(bankRef); } bankRef.Exists = true; // Timestamp check - if it doesn't match update events from that bank if (bankRef.LastModified != bankFileInfo.LastWriteTime) { bankRef.LastModified = bankFileInfo.LastWriteTime; UpdateCacheBank(bankRef); } // Update file sizes bankRef.FileSizes.Clear(); if (Settings.Instance.HasPlatforms) { for (int i = 0; i < bankPlatforms.Length; i++) { string platformBankPath = Path.Combine(bankFolders[i], bankFileName); var fileInfo = new FileInfo(platformBankPath); if (fileInfo.Exists) { bankRef.FileSizes.Add(new EditorBankRef.NameValuePair(bankPlatforms[i], fileInfo.Length)); } } } else { string platformBankPath = Path.Combine(EditorUtils.GetBankDirectory(), bankFileName); var fileInfo = new FileInfo(platformBankPath); if (fileInfo.Exists) { bankRef.FileSizes.Add(new EditorBankRef.NameValuePair("", fileInfo.Length)); } } if (bankFileInfo.Name == masterBankFileName) { eventCache.MasterBankRef = bankRef; } } // Unload the strings bank stringBank.unload(); // Remove any stale entries from bank and event lists eventCache.EditorBanks.FindAll((x) => !x.Exists).ForEach(RemoveCacheBank); eventCache.EditorBanks.RemoveAll((x) => !x.Exists); eventCache.EditorEvents.RemoveAll((x) => x.Banks.Count == 0); OnCacheChange(); AssetDatabase.StopAssetEditing(); }