public static GetBankPlatforms ( ) : string[] | ||
return | string[] |
void DisplayPIEBuildDirectory(string label, List <PlatformStringSetting> settings, FMODPlatform platform) { string buildTargetSetting = Settings.GetSetting(settings, RuntimeUtils.GetEditorFMODPlatform(), "Desktop"); string[] buildDirectories = new string[EditorUtils.GetBankPlatforms().Length + 1]; Array.Copy(EditorUtils.GetBankPlatforms(), 0, buildDirectories, 1, EditorUtils.GetBankPlatforms().Length); buildDirectories[0] = String.Format("Current Unity Platform ({0})", buildTargetSetting); bool useCurrentUnity = !Settings.HasSetting(settings, platform); string current = Settings.GetSetting(settings, platform, "Desktop"); int index = Array.IndexOf(buildDirectories, current); if (useCurrentUnity || index < 0) { index = 0; } int next = EditorGUILayout.Popup(label, index, buildDirectories); if (next != 0) { Settings.SetSetting(settings, platform, buildDirectories[next]); } else { Settings.RemoveSetting(settings, platform); } }
void DisplayChildBuildDirectories(string label, List <PlatformStringSetting> settings, FMODPlatform platform) { string[] buildDirectories = EditorUtils.GetBankPlatforms(); bool overriden = Settings.HasSetting(settings, platform); string current = Settings.GetSetting(settings, platform, "Desktop"); string inherit = Settings.GetSetting(settings, Settings.GetParent(platform), "Desktop"); int index = Array.IndexOf(buildDirectories, current); if (index < 0) { index = 0; } string[] valuesChild = new string[buildDirectories.Length + 1]; Array.Copy(buildDirectories, 0, valuesChild, 1, buildDirectories.Length); valuesChild[0] = string.Format("Inherit ({0})", inherit); int next = EditorGUILayout.Popup(label, overriden ? index + 1 : 0, valuesChild); if (next == 0) { Settings.RemoveSetting(settings, platform); Settings.RemoveSetting(((Settings)target).SpeakerModeSettings, platform); } else { Settings.SetSetting(settings, platform, buildDirectories[next - 1]); } }
void DisplayParentBuildDirectory(string label, List <PlatformStringSetting> settings, FMODPlatform platform) { string[] buildDirectories = EditorUtils.GetBankPlatforms(); string current = Settings.GetSetting(settings, platform, "Desktop"); int index = Array.IndexOf(buildDirectories, current); if (index < 0) { index = 0; } int next = EditorGUILayout.Popup(label, index, buildDirectories); Settings.SetSetting(settings, platform, buildDirectories[next]); }
void DisplayBuildDirectory(string label, Platform platform) { string[] buildDirectories = EditorUtils.GetBankPlatforms(); string currentValue = platform.BuildDirectory; int currentIndex = Math.Max(Array.IndexOf(buildDirectories, currentValue), 0); if (platform.Parent != null || platform is PlatformPlayInEditor) { string[] values = new string[buildDirectories.Length + 1]; Array.Copy(buildDirectories, 0, values, 1, buildDirectories.Length); if (platform is PlatformPlayInEditor) { Settings settings = target as Settings; values[0] = string.Format("Current Unity Platform ({0})", settings.CurrentEditorPlatform.BuildDirectory); } else { values[0] = string.Format("Inherit ({0})", platform.Parent.BuildDirectory); } bool overriden = Platform.PropertyAccessors.BuildDirectory.HasValue(platform); int next = EditorGUILayout.Popup(label, overriden ? currentIndex + 1 : 0, values); if (next == 0) { Platform.PropertyAccessors.BuildDirectory.Clear(platform); Platform.PropertyAccessors.SpeakerMode.Clear(platform); } else { Platform.PropertyAccessors.BuildDirectory.Set(platform, buildDirectories[next - 1]); } } else { int next = EditorGUILayout.Popup(label, currentIndex, buildDirectories); Platform.PropertyAccessors.BuildDirectory.Set(platform, buildDirectories[next]); } }
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; Directory.CreateDirectory(Path.GetDirectoryName(CacheAssetFullName)); AssetDatabase.CreateAsset(eventCache, CacheAssetFullName); } } var settings = Settings.Instance; if (string.IsNullOrEmpty(settings.SourceBankPath)) { ClearCache(); return; } string defaultBankFolder = null; if (!settings.HasPlatforms) { defaultBankFolder = settings.SourceBankPath; } else { Platform platform = settings.CurrentEditorPlatform; if (platform == settings.DefaultPlatform) { platform = settings.PlayInEditorPlatform; } defaultBankFolder = RuntimeUtils.GetCommonPlatformPath(Path.Combine(settings.SourceBankPath, platform.BuildDirectory)); } string[] bankPlatforms = EditorUtils.GetBankPlatforms(); string[] bankFolders = new string[bankPlatforms.Length]; for (int i = 0; i < bankPlatforms.Length; i++) { bankFolders[i] = RuntimeUtils.GetCommonPlatformPath(Path.Combine(settings.SourceBankPath, bankPlatforms[i])); } List <string> stringBanks = new List <string>(0); try { var files = Directory.GetFiles(defaultBankFolder, "*." + StringBankExtension, SearchOption.AllDirectories); 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 the banks in Studio 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))); // Use the most recent string bank timestamp as a marker for the most recent build of any bank because it gets exported every time DateTime lastWriteTime = File.GetLastWriteTime(stringBanks[0]); if (lastWriteTime == eventCache.StringsBankWriteTime) { countdownTimer = CountdownTimerReset; return; } if (EditorUtils.IsFileOpenByStudio(stringBanks[0])) { countdownTimer = CountdownTimerReset; return; } // Most recent strings bank is newer than last cache update time, recache. // Get a list of all banks List <string> bankFileNames = new List <string>(); List <string> reducedStringBanksList = new List <string>(); HashSet <Guid> stringBankGuids = new HashSet <Guid>(); foreach (string stringBankPath in stringBanks) { FMOD.Studio.Bank stringBank; EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (!stringBank.isValid()) { countdownTimer = CountdownTimerReset; return; } else { // Unload the strings bank stringBank.unload(); } Guid stringBankGuid; EditorUtils.CheckResult(stringBank.getID(out stringBankGuid)); if (!stringBankGuids.Add(stringBankGuid)) { // If we encounter multiple string banks with the same GUID then only use the first. This handles the scenario where // a Studio project is cloned and extended for DLC with a new master bank name. continue; } reducedStringBanksList.Add(stringBankPath); } bankFileNames = new List <string>(Directory.GetFiles(defaultBankFolder, "*.bank", SearchOption.AllDirectories)); bankFileNames.RemoveAll(x => x.Contains(".strings")); stringBanks = reducedStringBanksList; if (!UnityEditorInternal.InternalEditorUtility.inBatchMode) { // Check if any of the files are still being written by studio foreach (string bankFileName in bankFileNames) { EditorBankRef bankRef = eventCache.EditorBanks.Find((x) => RuntimeUtils.GetCommonPlatformPath(bankFileName) == x.Path); if (bankRef == null) { if (EditorUtils.IsFileOpenByStudio(bankFileName)) { countdownTimer = CountdownTimerReset; return; } continue; } if (bankRef.LastModified != File.GetLastWriteTime(bankFileName)) { if (EditorUtils.IsFileOpenByStudio(bankFileName)) { countdownTimer = CountdownTimerReset; return; } } } // Count down the timer in case we catch studio in-between updating two files. if (countdownTimer-- > 0) { return; } } eventCache.StringsBankWriteTime = lastWriteTime; // 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 banks List <FMOD.Studio.Bank> loadedStringsBanks = new List <FMOD.Studio.Bank>(); try { AssetDatabase.StartAssetEditing(); eventCache.EditorBanks.ForEach((x) => x.Exists = false); HashSet <string> masterBankFileNames = new HashSet <string>(); foreach (string stringBankPath in stringBanks) { FMOD.Studio.Bank stringBank; EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (!stringBank.isValid()) { ClearCache(); return; } loadedStringsBanks.Add(stringBank); FileInfo stringBankFileInfo = new FileInfo(stringBankPath); string masterBankFileName = Path.GetFileName(stringBankPath).Replace(StringBankExtension, BankExtension); masterBankFileNames.Add(masterBankFileName); EditorBankRef stringsBankRef = eventCache.StringsBanks.Find(x => RuntimeUtils.GetCommonPlatformPath(stringBankPath) == x.Path); if (stringsBankRef == null) { stringsBankRef = ScriptableObject.CreateInstance <EditorBankRef>(); stringsBankRef.FileSizes = new List <EditorBankRef.NameValuePair>(); AssetDatabase.AddObjectToAsset(stringsBankRef, eventCache); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(stringsBankRef)); eventCache.EditorBanks.Add(stringsBankRef); eventCache.StringsBanks.Add(stringsBankRef); } stringsBankRef.SetPath(stringBankPath, defaultBankFolder); stringsBankRef.LastModified = stringBankFileInfo.LastWriteTime; stringsBankRef.Exists = true; stringsBankRef.FileSizes.Clear(); if (Settings.Instance.HasPlatforms) { for (int i = 0; i < bankPlatforms.Length; i++) { stringsBankRef.FileSizes.Add(new EditorBankRef.NameValuePair(bankPlatforms[i], stringBankFileInfo.Length)); } } else { stringsBankRef.FileSizes.Add(new EditorBankRef.NameValuePair("", stringBankFileInfo.Length)); } } eventCache.EditorParameters.ForEach((x) => x.Exists = false); foreach (string bankFileName in bankFileNames) { EditorBankRef bankRef = eventCache.EditorBanks.Find((x) => RuntimeUtils.GetCommonPlatformPath(bankFileName) == 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.SetPath(bankFileName, defaultBankFolder); bankRef.LastModified = DateTime.MinValue; bankRef.FileSizes = new List <EditorBankRef.NameValuePair>(); eventCache.EditorBanks.Add(bankRef); } bankRef.Exists = true; FileInfo bankFileInfo = new FileInfo(bankFileName); // 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 = RuntimeUtils.GetCommonPlatformPath(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 = RuntimeUtils.GetCommonPlatformPath(Path.Combine(Settings.Instance.SourceBankPath, bankFileName)); var fileInfo = new FileInfo(platformBankPath); if (fileInfo.Exists) { bankRef.FileSizes.Add(new EditorBankRef.NameValuePair("", fileInfo.Length)); } } if (masterBankFileNames.Contains(bankFileInfo.Name)) { if (!eventCache.MasterBanks.Exists(x => RuntimeUtils.GetCommonPlatformPath(bankFileName) == x.Path)) { eventCache.MasterBanks.Add(bankRef); } } } // Remove any stale entries from bank, event and parameter lists eventCache.EditorBanks.FindAll((x) => !x.Exists).ForEach(RemoveCacheBank); eventCache.EditorBanks.RemoveAll((x) => !x.Exists); eventCache.EditorEvents.RemoveAll((x) => x.Banks.Count == 0); eventCache.EditorParameters.RemoveAll((x) => !x.Exists); eventCache.MasterBanks.RemoveAll((x) => !x.Exists); eventCache.StringsBanks.RemoveAll((x) => !x.Exists); } finally { // Unload the strings banks loadedStringsBanks.ForEach(x => x.unload()); AssetDatabase.StopAssetEditing(); Debug.Log("[FMOD] Cache Updated."); } }
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(); }
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))); // Use the most recent string bank timestamp as a marker for the most recent build of any bank because it gets exported every time DateTime lastWriteTime = File.GetLastWriteTime(stringBanks[0]); if (lastWriteTime == eventCache.StringsBankWriteTime) { countdownTimer = CountdownTimerReset; return; } if (EditorUtils.IsFileOpenByStudio(stringBanks[0])) { countdownTimer = CountdownTimerReset; return; } // Most recent strings bank is newer than last cache update time, recache. // Get a list of all banks HashSet <string> bankFileNames = new HashSet <string>(); List <string> reducedStringBanksList = new List <string>(); HashSet <Guid> stringBankGuids = new HashSet <Guid>(); foreach (string stringBankPath in stringBanks) { FMOD.Studio.Bank stringBank; EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (!stringBank.isValid()) { countdownTimer = CountdownTimerReset; return; } try { Guid stringBankGuid; EditorUtils.CheckResult(stringBank.getID(out stringBankGuid)); if (!stringBankGuids.Add(stringBankGuid)) { // If we encounter multiple string banks with the same GUID then only use the first. This handles the scenario where // a Studio project is cloned and extended for DLC with a new master bank name. continue; } reducedStringBanksList.Add(stringBankPath); // Iterate every string in the strings bank and look for any that identify banks int stringCount; stringBank.getStringCount(out stringCount); 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); } } } } finally { // Unload the strings bank stringBank.unload(); } } stringBanks = reducedStringBanksList; // 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; } eventCache.StringsBankWriteTime = lastWriteTime; // 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 banks List <FMOD.Studio.Bank> loadedBanks = new List <FMOD.Studio.Bank>(); try { AssetDatabase.StartAssetEditing(); eventCache.EditorBanks.ForEach((x) => x.Exists = false); HashSet <string> masterBankFileNames = new HashSet <string>(); foreach (string stringBankPath in stringBanks) { FMOD.Studio.Bank stringBank; EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (!stringBank.isValid()) { ClearCache(); return; } loadedBanks.Add(stringBank); FileInfo stringBankFileInfo = new FileInfo(stringBankPath); string masterBankFileName = Path.GetFileName(stringBankPath).Replace(StringBankExtension, BankExtension); masterBankFileNames.Add(masterBankFileName); EditorBankRef stringsBankRef = eventCache.StringsBanks.Find(x => stringBankPath == x.Path); if (stringsBankRef == null) { stringsBankRef = ScriptableObject.CreateInstance <EditorBankRef>(); stringsBankRef.FileSizes = new List <EditorBankRef.NameValuePair>(); eventCache.EditorBanks.Add(stringsBankRef); AssetDatabase.AddObjectToAsset(stringsBankRef, eventCache); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(stringsBankRef)); eventCache.StringsBanks.Add(stringsBankRef); } stringsBankRef.Path = stringBankPath; stringsBankRef.LastModified = stringBankFileInfo.LastWriteTime; stringsBankRef.Exists = true; stringsBankRef.FileSizes.Clear(); if (Settings.Instance.HasPlatforms) { for (int i = 0; i < bankPlatforms.Length; i++) { stringsBankRef.FileSizes.Add(new EditorBankRef.NameValuePair(bankPlatforms[i], stringBankFileInfo.Length)); } } else { stringsBankRef.FileSizes.Add(new EditorBankRef.NameValuePair("", stringBankFileInfo.Length)); } } 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 (masterBankFileNames.Contains(bankFileInfo.Name)) { if (!eventCache.MasterBanks.Exists(x => bankFileInfo.FullName == x.Path)) { eventCache.MasterBanks.Add(bankRef); } } } // 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(); } finally { // Unload the strings banks loadedBanks.ForEach(x => x.unload()); AssetDatabase.StopAssetEditing(); } }
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 { 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]); } List <String> stringBanks = new List <string>(0); try { var files = Directory.GetFiles(defaultBankFolder, "*." + StringBankExtension); stringBanks = new List <string>(files); } catch { UnityEngine.Debug.LogWarning(String.Format("FMOD Studio: Directory {0} doesn't exist. Build from the tool or check the path in the settings", defaultBankFolder)); } // Strip out OSX resource-fork files that appear on FAT32 stringBanks.RemoveAll((x) => Path.GetFileName(x).StartsWith("._")); if (stringBanks.Count == 0) { ClearCache(); if (eventCache.StringsBankWriteTime != DateTime.MinValue) { UnityEngine.Debug.LogWarning(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 = 1; return; } if (EditorUtils.IsFileOpenByStudio(stringBankPath)) { countdownTimer = 1; return; } FMOD.Studio.Bank stringBank = null; EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (stringBank == null) { countdownTimer = 1; 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)) { countdownTimer = 1; return; } EditorBankRef bankRef = eventCache.EditorBanks.Find((x) => bankPath == x.Path); if (bankRef == null) { if (EditorUtils.IsFileOpenByStudio(bankPath)) { countdownTimer = 1; return; } continue; } if (bankRef.LastModified != File.GetLastWriteTime(bankPath)) { if (EditorUtils.IsFileOpenByStudio(bankPath)) { countdownTimer = 1; return; } } } // Do one extra loop through the in-use check in case we catch studio exactly in-between updating two files. if (countdownTimer-- > 0) { return; } // All files are finished being modified by studio so update the cache // Reload the strings bank EditorUtils.CheckResult(EditorUtils.System.loadBankFile(stringBankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringBank)); if (stringBank == null) { ClearCache(); return; } eventCache.StringsBankWriteTime = File.GetLastWriteTime(stringBankPath); string masterBankFileName = Path.GetFileName(stringBankPath).Replace(StringBankExtension, BankExtension); 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, eventCache); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(bankRef)); 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 override void OnInspectorGUI() { Settings settings = target as Settings; EditorUtility.SetDirty(settings); hasBankSourceChanged = false; GUIStyle style = new GUIStyle(GUI.skin.label); style.richText = true; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("<b>Source</b>", GUI.skin.textField, style); int selection = settings.HasSourceProject ? 0 : 1; selection = GUILayout.SelectionGrid(selection, new GUIContent[2] { new GUIContent("Project"), new GUIContent("Bank Folder") }, 2, GUILayout.ExpandWidth(false)); settings.HasSourceProject = selection == 0; EditorGUILayout.EndHorizontal(); if (selection == 0) { EditorGUILayout.BeginHorizontal(); string oldPath = settings.SourceProjectPath; EditorGUILayout.PrefixLabel("Studio Project Path", GUI.skin.textField, style); settings.SourceProjectPath = EditorGUILayout.TextField(GUIContent.none, settings.SourceProjectPath); if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false))) { GUI.FocusControl(null); string path = EditorUtility.OpenFilePanel("Locate Studio Project", oldPath, "fspro"); if (!String.IsNullOrEmpty(path)) { settings.SourceProjectPath = path; this.Repaint(); } } EditorGUILayout.EndHorizontal(); // Cache in settings for runtime access in play-in-editor mode settings.SourceBankPath = EditorUtils.GetBankDirectory(); settings.HasPlatforms = true; // First time project path is set or changes, copy to streaming assets if (settings.SourceProjectPath != oldPath) { hasBankSourceChanged = true; } } else { EditorGUILayout.BeginHorizontal(); string oldPath = settings.SourceBankPath; EditorGUILayout.PrefixLabel("Banks Folder Path", GUI.skin.textField, style); settings.SourceBankPath = EditorGUILayout.TextField(GUIContent.none, settings.SourceBankPath); if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false))) { GUI.FocusControl(null); var path = EditorUtility.OpenFolderPanel("Locate Studio Banks", oldPath, null); if (!String.IsNullOrEmpty(path)) { settings.SourceBankPath = path; } } EditorGUILayout.EndHorizontal(); settings.HasPlatforms = EditorUtils.GetBankPlatforms().Length > 0; // First time project path is set or changes, copy to streaming assets if (settings.SourceBankPath != oldPath) { hasBankSourceChanged = true; } } if ((settings.HasSourceProject && !File.Exists(settings.SourceProjectPath)) || !Directory.Exists(settings.SourceBankPath)) { return; } // ----- PIE ---------------------------------------------- EditorGUILayout.Separator(); EditorGUILayout.LabelField("<b>Play In Editor Settings</b>", style); EditorGUI.indentLevel++; DisplayParentBool("Live Update", settings.LiveUpdateSettings, FMODPlatform.PlayInEditor); if (settings.IsLiveUpdateEnabled(FMODPlatform.PlayInEditor)) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); #if UNITY_5_0 || UNITY_5_1 GUILayout.Label("Unity 5.0 or 5.1 detected: Live update will listen on port <b>9265</b>", style); #else GUILayout.Label("Live update will listen on port <b>9264</b>", style); #endif EditorGUILayout.EndHorizontal(); } DisplayParentSpeakerMode("Speaker Mode", settings.SpeakerModeSettings, FMODPlatform.PlayInEditor); if (settings.HasPlatforms) { DisplayParentBuildDirectory("Bank Platform", settings.BankDirectorySettings, FMODPlatform.PlayInEditor); } EditorGUI.indentLevel--; // ----- Default ---------------------------------------------- EditorGUILayout.Separator(); EditorGUILayout.LabelField("<b>Default Settings</b>", style); EditorGUI.indentLevel++; DisplayParentBool("Live Update", settings.LiveUpdateSettings, FMODPlatform.Default); if (settings.IsLiveUpdateEnabled(FMODPlatform.Default)) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); #if UNITY_5_0 || UNITY_5_1 GUILayout.Label("Unity 5.0 or 5.1 detected: Live update will listen on port <b>9265</b>", style); #else GUILayout.Label("Live update will listen on port <b>9264</b>", style); #endif EditorGUILayout.EndHorizontal(); } DisplayParentSpeakerMode("Speaker Mode", settings.SpeakerModeSettings, FMODPlatform.Default); DisplayParentFreq("Sample Rate", settings.SampleRateSettings, FMODPlatform.Default); if (settings.HasPlatforms) { bool prevChanged = GUI.changed; DisplayParentBuildDirectory("Bank Platform", settings.BankDirectorySettings, FMODPlatform.Default); hasBankSourceChanged |= !prevChanged && GUI.changed; } DisplayParentInt("Virtual Channel Count", settings.VirtualChannelSettings, FMODPlatform.Default, 0, 2048); DisplayParentInt("Real Channel Count", settings.RealChannelSettings, FMODPlatform.Default, 0, 2048); EditorGUI.indentLevel--; // ----- Plugins ---------------------------------------------- EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("<b>Plugins</b>", GUI.skin.button, style); if (GUILayout.Button("Add Plugin", GUILayout.ExpandWidth(false))) { settings.Plugins.Add(""); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel++; for (int count = 0; count < settings.Plugins.Count; count++) { EditorGUILayout.BeginHorizontal(); settings.Plugins[count] = EditorGUILayout.TextField("Plugin " + (count + 1).ToString() + ":", settings.Plugins[count]); if (GUILayout.Button("Delete Plugin", GUILayout.ExpandWidth(false))) { settings.Plugins.RemoveAt(count); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; // ----- Windows ---------------------------------------------- DisplayPlatform(FMODPlatform.Desktop, null); DisplayPlatform(FMODPlatform.Mobile, new FMODPlatform[] { FMODPlatform.MobileHigh, FMODPlatform.MobileLow, FMODPlatform.PSVita }); DisplayPlatform(FMODPlatform.Console, new FMODPlatform[] { FMODPlatform.XboxOne, FMODPlatform.PS4, FMODPlatform.WiiU }); if (hasBankSourceChanged) { EditorUtils.CopyToStreamingAssets(); } }