Exemplo n.º 1
0
    // Parses the .wproj to find out where soundbanks are generated for the given path
    public static string GetWwiseSoundBankDestinationFolder(string Platform, string WwiseProjectPath)
    {
        try
        {
            if (WwiseProjectPath.Length == 0)
            {
                return("");
            }

            XmlDocument doc = new XmlDocument();
            doc.Load(WwiseProjectPath);
            XPathNavigator Navigator = doc.CreateNavigator();

            // Navigate the wproj file (XML format) to where generated soundbank paths are stored
            string          PathExpression = string.Format("//Property[@Name='SoundBankPaths']/ValueList/Value[@Platform='{0}']", Platform);
            XPathExpression expression     = XPathExpression.Compile(PathExpression);
            XPathNavigator  node           = Navigator.SelectSingleNode(expression);
            string          Path           = "";
            if (node != null)
            {
                Path = node.Value;
                                #if !(UNITY_EDITOR_WIN || UNITY_XBOX360 || UNITY_XBOXONE || UNITY_METRO)
                AkBankPathUtil.ConvertToPosixPath(ref Path);
                                #endif // #if !(UNITY_EDITOR_WIN || UNITY_XBOX360 || UNITY_XBOXONE || UNITY_METRO)
            }

            return(Path);
        }
        catch (Exception)
        {
            // Error happened, return empty string
            return("");
        }
    }
Exemplo n.º 2
0
    public static string GetFullBasePath()
    {
        string basePath = AkInitializer.GetBasePath();

        AkBankPathUtil.LazyAppendTrailingSeparator(ref basePath);
        AkBankPathUtil.LazyConvertPathConvention(ref basePath);
        return(basePath);
    }
Exemplo n.º 3
0
    public static string GetPlatformBasePath()
    {
        string result = string.Empty;

        result = Path.Combine(AkBankPathUtil.GetFullBasePath(), AkBankPathUtil.GetPlatformSubDirectory());
        AkBankPathUtil.LazyAppendTrailingSeparator(ref result);
        AkBankPathUtil.LazyConvertPathConvention(ref result);
        return(result);
    }
Exemplo n.º 4
0
 public static void LazyConvertPathConvention(ref string path)
 {
     if (AkBankPathUtil.isToUsePosixPathSeparator)
     {
         AkBankPathUtil.ConvertToPosixPath(ref path);
     }
     else if (Path.DirectorySeparatorChar == '/')
     {
         AkBankPathUtil.ConvertToPosixPath(ref path);
     }
     else
     {
         AkBankPathUtil.ConvertToWindowsPath(ref path);
     }
 }
Exemplo n.º 5
0
    // 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 = AkBankPathUtil.GetDefaultPath();
            }

            s_Instance = Settings;
        }
        catch (Exception)
        {
        }

        return(Settings);
    }
Exemplo n.º 6
0
    private AkWwiseXMLWatcher()
    {
        XmlWatcher      = new FileSystemWatcher();
        SoundBankFolder = AkBankPathUtil.GetPlatformBasePath();

        try
        {
            XmlWatcher.Path         = SoundBankFolder;
            XmlWatcher.NotifyFilter = NotifyFilters.LastWrite;

            // Event handlers that are watching for specific event
            XmlWatcher.Created += new FileSystemEventHandler(RaisePopulateFlag);
            XmlWatcher.Changed += new FileSystemEventHandler(RaisePopulateFlag);

            XmlWatcher.Filter = "*.xml";
            XmlWatcher.IncludeSubdirectories = true;
        }
        catch (Exception)
        {
            // Deliberately left empty
        }
    }
Exemplo n.º 7
0
    public static void Populate()
    {
        if (EditorApplication.isPlaying)
        {
            return;
        }

        // Try getting the SoundbanksInfo.xml file for Windows or Mac first, then try to find any other available platform.
        string FullSoundbankPath = AkBankPathUtil.GetPlatformBasePath();
        string filename          = Path.Combine(FullSoundbankPath, "SoundbanksInfo.xml");

        if (!File.Exists(filename))
        {
            FullSoundbankPath = Path.Combine(Application.streamingAssetsPath, WwiseSetupWizard.Settings.SoundbankPath);
            string[] foundFiles = Directory.GetFiles(FullSoundbankPath, "SoundbanksInfo.xml", SearchOption.AllDirectories);
            if (foundFiles.Length > 0)
            {
                // We just want any file, doesn't matter which one.
                filename = foundFiles[0];
            }
        }

        if (File.Exists(filename))
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(filename);

            XmlNodeList soundBanks = doc.GetElementsByTagName("SoundBanks");
            for (int i = 0; i < soundBanks.Count; i++)
            {
                XmlNodeList soundBank = soundBanks[i].SelectNodes("SoundBank");
                for (int j = 0; j < soundBank.Count; j++)
                {
                    SerialiseSoundBank(soundBank[j]);
                }
            }
        }
    }
Exemplo n.º 8
0
    public void LoadLocalizedBank(string in_bankFilename)
    {
        string in_bankPath = "file://" + Path.Combine(Path.Combine(AkBankPathUtil.GetPlatformBasePath(), AkInitializer.GetCurrentLanguage()), in_bankFilename);

        this.DoLoadBank(in_bankPath);
    }
Exemplo n.º 9
0
    public void LoadNonLocalizedBank(string in_bankFilename)
    {
        string in_bankPath = "file://" + Path.Combine(AkBankPathUtil.GetPlatformBasePath(), in_bankFilename);

        this.DoLoadBank(in_bankPath);
    }
Exemplo n.º 10
0
    void Awake()
    {
        if (ms_Instance != null)
        {
            //Don't init twice
            //Check if there are 2 objects with this script.  If yes, remove this component.
            if (ms_Instance != this)
            {
                UnityEngine.Object.DestroyImmediate(this.gameObject);
            }
            return;
        }

        Debug.Log("WwiseUnity: Initialize sound engine ...");

        //Use default properties for most SoundEngine subsystem.
        //The game programmer should modify these when needed.  See the Wwise SDK documentation for the initialization.
        //These settings may very well change for each target platform.
        AkMemSettings memSettings = new AkMemSettings();

        memSettings.uMaxNumPools = 20;

        AkDeviceSettings deviceSettings = new AkDeviceSettings();

        AkSoundEngine.GetDefaultDeviceSettings(deviceSettings);

        AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings();

        streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024;

        AkInitSettings initSettings = new AkInitSettings();

        AkSoundEngine.GetDefaultInitSettings(initSettings);
        initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024;

        AkPlatformInitSettings platformSettings = new AkPlatformInitSettings();

        AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings);
        platformSettings.uLEngineDefaultPoolSize           = (uint)lowerPoolSize * 1024;
        platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold;

        AkMusicSettings musicSettings = new AkMusicSettings();

        AkSoundEngine.GetDefaultMusicSettings(musicSettings);

        AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings);

        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            return; //AkSoundEngine.Init should have logged more details.
        }

        ms_Instance = this;

        AkBankPathUtil.UsePlatformSpecificPath();
        string platformBasePath = AkBankPathUtil.GetPlatformBasePath();

// Note: Android low-level IO uses relative path to "assets" folder of the apk as SoundBank folder.
// Unity uses full paths for general path checks. We thus don't use DirectoryInfo.Exists to test
// our SoundBank folder for Android.
#if !UNITY_ANDROID && !UNITY_METRO && !UNITY_PSP2
        if (!AkBankPathUtil.Exists(platformBasePath))
        {
            string errorMsg = string.Format("WwiseUnity: Failed to find soundbank folder: {0}. Abort.", platformBasePath);
            Debug.LogError(errorMsg);
            ms_Instance = null;
            return;
        }
#endif // #if !UNITY_ANDROID

        AkSoundEngine.SetBasePath(platformBasePath);
        AkSoundEngine.SetCurrentLanguage(language);

        result = AkCallbackManager.Init();
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            ms_Instance = null;
            return;
        }

        AkBankManager.Reset();

        Debug.Log("WwiseUnity: Sound engine initialized.");

        //The sound engine should not be destroyed once it is initialized.
        DontDestroyOnLoad(this);

#if UNITY_EDITOR
        //Redirect Wwise error messages into Unity console.
        AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole);
#endif

        //Load the init bank right away.  Errors will be logged automatically.
        uint BankID;
#if UNITY_ANDROID && !UNITY_METRO && AK_LOAD_BANK_IN_MEMORY
        result = AkInMemBankLoader.LoadNonLocalizedBank("Init.bnk");
#else
        result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);
#endif // #if UNITY_ANDROID && !UNITY_METRO && AK_ANDROID_BANK_IN_OBB
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString());
        }
    }
Exemplo n.º 11
0
    private void Awake()
    {
        if (ms_Instance != null)
        {
            if (ms_Instance != this)
            {
                UnityEngine.Object.DestroyImmediate(base.gameObject);
            }
        }
        else
        {
            Debug.Log("WwiseUnity: Initialize sound engine ...");
            AkMemSettings settings = new AkMemSettings {
                uMaxNumPools = 40
            };
            AkDeviceSettings settings2 = new AkDeviceSettings();
            AkSoundEngine.GetDefaultDeviceSettings(settings2);
            AkStreamMgrSettings settings3 = new AkStreamMgrSettings {
                uMemorySize = (uint)(this.streamingPoolSize * 0x400)
            };
            AkInitSettings settings4 = new AkInitSettings();
            AkSoundEngine.GetDefaultInitSettings(settings4);
            settings4.uDefaultPoolSize = (uint)(this.defaultPoolSize * 0x400);
            AkPlatformInitSettings settings5 = new AkPlatformInitSettings();
            AkSoundEngine.GetDefaultPlatformInitSettings(settings5);
            settings5.uLEngineDefaultPoolSize           = (uint)(this.lowerPoolSize * 0x400);
            settings5.fLEngineDefaultPoolRatioThreshold = this.memoryCutoffThreshold;
            AkMusicSettings settings6 = new AkMusicSettings();
            AkSoundEngine.GetDefaultMusicSettings(settings6);
            if (AkSoundEngine.Init(settings, settings3, settings2, settings4, settings5, settings6) != AKRESULT.AK_Success)
            {
                Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            }
            else
            {
                ms_Instance = this;
                AkBankPathUtil.UsePlatformSpecificPath();
                string platformBasePath = AkBankPathUtil.GetPlatformBasePath();
                if (!s_loadBankFromMemory)
                {
                }
                AkSoundEngine.SetBasePath(platformBasePath);
                AkSoundEngine.SetCurrentLanguage(this.language);
                if (AkCallbackManager.Init() != AKRESULT.AK_Success)
                {
                    Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
                    AkSoundEngine.Term();
                    ms_Instance = null;
                }
                else
                {
                    AKRESULT akresult;
                    uint     num;
                    Debug.Log("WwiseUnity: Sound engine initialized.");
                    UnityEngine.Object.DontDestroyOnLoad(this);
                    if (s_loadBankFromMemory)
                    {
                        string        soundBankPathInResources = GetSoundBankPathInResources("Init.bytes");
                        CBinaryObject content = Singleton <CResourceManager> .GetInstance().GetResource(soundBankPathInResources, typeof(TextAsset), enResourceType.Sound, false, false).m_content as CBinaryObject;

                        GCHandle handle = GCHandle.Alloc(content.m_data, GCHandleType.Pinned);
                        IntPtr   ptr    = handle.AddrOfPinnedObject();
                        if (ptr != IntPtr.Zero)
                        {
                            akresult = AkSoundEngine.LoadBank(ptr, (uint)content.m_data.Length, -1, out num);
                            handle.Free();
                        }
                        else
                        {
                            akresult = AKRESULT.AK_Fail;
                        }
                        Singleton <CResourceManager> .GetInstance().RemoveCachedResource(soundBankPathInResources);
                    }
                    else
                    {
                        akresult = AkSoundEngine.LoadBank("Init.bnk", -1, out num);
                    }
                    if (akresult != AKRESULT.AK_Success)
                    {
                        Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + akresult.ToString());
                    }
                }
            }
        }
    }
Exemplo n.º 12
0
    /// Load a language-specific bank from WWW object
    public AKRESULT LoadLocalizedBank(string in_bankFilename)
    {
        string bankPath = Path.Combine(Path.Combine(AkBankPathUtil.GetPlatformBasePath(), AkInitializer.GetCurrentLanguage()), in_bankFilename);

        return(DoLoadBank(bankPath));
    }
Exemplo n.º 13
0
    /// Load a sound bank from WWW object
    public AKRESULT LoadNonLocalizedBank(string in_bankFilename)
    {
        string bankPath = Path.Combine(AkBankPathUtil.GetPlatformBasePath(), in_bankFilename);

        return(DoLoadBank(bankPath));
    }
    private void Awake()
    {
        if (AkInitializer.ms_Instance != null)
        {
            if (AkInitializer.ms_Instance != this)
            {
                Object.DestroyImmediate(base.gameObject);
            }
            return;
        }
        Debug.Log("WwiseUnity: Initialize sound engine ...");
        AkMemSettings akMemSettings = new AkMemSettings();

        akMemSettings.uMaxNumPools = 40u;
        AkDeviceSettings akDeviceSettings = new AkDeviceSettings();

        AkSoundEngine.GetDefaultDeviceSettings(akDeviceSettings);
        AkStreamMgrSettings akStreamMgrSettings = new AkStreamMgrSettings();

        akStreamMgrSettings.uMemorySize = (uint)(this.streamingPoolSize * 1024);
        AkInitSettings akInitSettings = new AkInitSettings();

        AkSoundEngine.GetDefaultInitSettings(akInitSettings);
        akInitSettings.uDefaultPoolSize = (uint)(this.defaultPoolSize * 1024);
        AkPlatformInitSettings akPlatformInitSettings = new AkPlatformInitSettings();

        AkSoundEngine.GetDefaultPlatformInitSettings(akPlatformInitSettings);
        akPlatformInitSettings.uLEngineDefaultPoolSize           = (uint)(this.lowerPoolSize * 1024);
        akPlatformInitSettings.fLEngineDefaultPoolRatioThreshold = this.memoryCutoffThreshold;
        AkMusicSettings akMusicSettings = new AkMusicSettings();

        AkSoundEngine.GetDefaultMusicSettings(akMusicSettings);
        AKRESULT aKRESULT = AkSoundEngine.Init(akMemSettings, akStreamMgrSettings, akDeviceSettings, akInitSettings, akPlatformInitSettings, akMusicSettings);

        if (aKRESULT != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            return;
        }
        AkInitializer.ms_Instance = this;
        AkBankPathUtil.UsePlatformSpecificPath();
        string platformBasePath = AkBankPathUtil.GetPlatformBasePath();

        if (!AkInitializer.s_loadBankFromMemory)
        {
        }
        AkSoundEngine.SetBasePath(platformBasePath);
        AkSoundEngine.SetCurrentLanguage(this.language);
        aKRESULT = AkCallbackManager.Init();
        if (aKRESULT != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            AkInitializer.ms_Instance = null;
            return;
        }
        Debug.Log("WwiseUnity: Sound engine initialized.");
        Object.DontDestroyOnLoad(this);
        if (AkInitializer.s_loadBankFromMemory)
        {
            string        soundBankPathInResources = AkInitializer.GetSoundBankPathInResources("Init.bytes");
            CBinaryObject cBinaryObject            = Singleton <CResourceManager> .GetInstance().GetResource(soundBankPathInResources, typeof(TextAsset), enResourceType.Sound, false, false).m_content as CBinaryObject;

            GCHandle gCHandle = GCHandle.Alloc(cBinaryObject.m_data, 3);
            IntPtr   intPtr   = gCHandle.AddrOfPinnedObject();
            if (intPtr != IntPtr.Zero)
            {
                uint num;
                aKRESULT = AkSoundEngine.LoadBank(intPtr, (uint)cBinaryObject.m_data.Length, -1, out num);
                gCHandle.Free();
            }
            else
            {
                aKRESULT = AKRESULT.AK_Fail;
            }
            Singleton <CResourceManager> .GetInstance().RemoveCachedResource(soundBankPathInResources);
        }
        else
        {
            uint num2;
            aKRESULT = AkSoundEngine.LoadBank("Init.bnk", -1, out num2);
        }
        if (aKRESULT != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + aKRESULT.ToString());
        }
    }