Esempio n. 1
0
    private void HandleXmlChange()
    {
        var logWarnings = AkBasePathGetter.LogWarnings;

        AkBasePathGetter.LogWarnings = false;
        generatedSoundbanksPath      = AkBasePathGetter.GetPlatformBasePath();

        if (XmlExceptionOccurred || generatedSoundbanksPath != XmlWatcher?.Path)
        {
            new Thread(CreateXmlWatcher).Start();
        }

        if (!xmlChanged)
        {
            return;
        }

        xmlChanged = false;

        var populate = PopulateXML;

        if (populate == null || !populate())
        {
            return;
        }

        var callback = XMLUpdated;

        if (callback != null)
        {
            callback();
        }
    }
    public static bool Populate()
    {
        if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode || UnityEditor.EditorApplication.isCompiling)
        {
            return(false);
        }

        try
        {
            // Try getting the SoundbanksInfo.xml file for Windows or Mac first, then try to find any other available platform.
            var FullSoundbankPath = AkBasePathGetter.GetPlatformBasePath();
            var filename          = System.IO.Path.Combine(FullSoundbankPath, "SoundbanksInfo.xml");
            if (!System.IO.File.Exists(filename))
            {
                FullSoundbankPath = System.IO.Path.Combine(UnityEngine.Application.streamingAssetsPath,
                                                           WwiseSetupWizard.Settings.SoundbankPath);

                if (!System.IO.Directory.Exists(FullSoundbankPath))
                {
                    return(false);
                }

                var foundFiles =
                    System.IO.Directory.GetFiles(FullSoundbankPath, "SoundbanksInfo.xml", System.IO.SearchOption.AllDirectories);

                if (foundFiles.Length == 0)
                {
                    return(false);
                }

                filename = foundFiles[0];
            }

            var time = System.IO.File.GetLastWriteTime(filename);
            if (time <= s_LastParsed)
            {
                return(false);
            }

            var doc = new System.Xml.XmlDocument();
            doc.Load(filename);

            var bChanged   = false;
            var soundBanks = doc.GetElementsByTagName("SoundBanks");
            for (var i = 0; i < soundBanks.Count; i++)
            {
                var soundBank = soundBanks[i].SelectNodes("SoundBank");
                for (var j = 0; j < soundBank.Count; j++)
                {
                    bChanged = SerialiseSoundBank(soundBank[j]) || bChanged;
                }
            }

            return(bChanged);
        }
        catch
        {
            return(false);
        }
    }
Esempio n. 3
0
	/// Load a language-specific bank from WWW object
	public void LoadLocalizedBank(string in_bankFilename)
	{
		var bankPath = "file://" + System.IO.Path.Combine(
			               System.IO.Path.Combine(AkBasePathGetter.GetPlatformBasePath(), AkSoundEngine.GetCurrentLanguage()),
			               in_bankFilename);
		DoLoadBank(bankPath);
	}
Esempio n. 4
0
    static void GenericBuild(string[] scenes, string targetDir, string appName, BuildTarget buildTarget, BuildOptions buildOptions)
    {
        string res = BuildPipeline.BuildPlayer(scenes, targetDir + "/" + appName + ".exe", buildTarget, buildOptions);

        if (res.Length > 0)
        {
            throw new Exception("BuildPlayer failure: " + res);
        }
        else
        {
            // Copy WWise soundbanks
            string wwiseProjFile              = Path.Combine(Application.dataPath, WwiseSetupWizard.Settings.WwiseProjectPath).Replace('/', '\\');
            string wwiseProjectFolder         = wwiseProjFile.Remove(wwiseProjFile.LastIndexOf(Path.DirectorySeparatorChar));
            string wwisePlatformString        = UnityToWwisePlatformString(EditorUserBuildSettings.activeBuildTarget.ToString());
            string sourceSoundBankFolder      = Path.Combine(wwiseProjectFolder, AkBasePathGetter.GetPlatformBasePath());
            string destinationSoundBankFolder = Path.Combine(targetDir + "/" + appName + "_Data/StreamingAssets",
                                                             Path.Combine(WwiseSetupWizard.Settings.SoundbankPath, wwisePlatformString)
                                                             );

            if (!AkUtilities.DirectoryCopy(sourceSoundBankFolder, destinationSoundBankFolder, true))
            {
                Debug.LogError("WwiseUnity: The soundbank folder for the " + wwisePlatformString + " platform doesn't exist. Make sure it was generated in your Wwise project");
                throw new Exception("BuildPlayer failure: " + res);
            }
            Directory.GetFiles(targetDir + "/" + appName + "_Data/StreamingAssets", "*.meta", SearchOption.AllDirectories).ForEach(file => File.Delete(file));
        }
    }
Esempio n. 5
0
    public static string GetDecodedBankFullPath()
    {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
        return(Path.Combine(Application.persistentDataPath, GetDecodedBankFolder()));
#else
        return(Path.Combine(AkBasePathGetter.GetPlatformBasePath(), GetDecodedBankFolder()));
#endif
    }
Esempio n. 6
0
    public static string GetDecodedBankFullPath()
    {
#if (UNITY_ANDROID || UNITY_IOS || UNITY_SWITCH) && !UNITY_EDITOR
        // This is for platforms that only have a specific file location for persistent data.
        return(Path.Combine(Application.persistentDataPath, GetDecodedBankFolder()));
#else
        return(Path.Combine(AkBasePathGetter.GetPlatformBasePath(), GetDecodedBankFolder()));
#endif
    }
Esempio n. 7
0
    public void StartWatchers()
    {
        generatedSoundbanksPath = AkBasePathGetter.GetPlatformBasePath();
        wwiseProjectPath        = AkBasePathGetter.GetWwiseProjectDirectory();

        new Thread(CreateXmlWatcher).Start();
        new Thread(CreateProjectWatcher).Start();

        WwiseProjectUpdated += AkUtilities.SoundBankDestinationsUpdated;
        UnityEditor.EditorApplication.update += OnEditorUpdate;
    }
Esempio n. 8
0
    public static string GetDecodedBankFullPath()
    {
#if UNITY_SWITCH && !UNITY_EDITOR
        // Calling Application.persistentDataPath crashes Switch
        return(null);
#elif (UNITY_ANDROID || PLATFORM_LUMIN || UNITY_IOS) && !UNITY_EDITOR
        // This is for platforms that only have a specific file location for persistent data.
        return(System.IO.Path.Combine(UnityEngine.Application.persistentDataPath, GetDecodedBankFolder()));
#else
        return(System.IO.Path.Combine(AkBasePathGetter.GetPlatformBasePath(), GetDecodedBankFolder()));
#endif
    }
    public static MinMaxEventDuration GetMinMaxDuration(AK.Wwise.Event akEvent)
    {
        var result            = new MinMaxEventDuration();
        var FullSoundbankPath = AkBasePathGetter.GetPlatformBasePath();
        var filename          = System.IO.Path.Combine(FullSoundbankPath, "SoundbanksInfo.xml");
        var MaxDuration       = 1000000.0f;

        if (System.IO.File.Exists(filename))
        {
            var doc = new System.Xml.XmlDocument();
            doc.Load(filename);

            var soundBanks = doc.GetElementsByTagName("SoundBanks");
            for (var i = 0; i < soundBanks.Count; i++)
            {
                var soundBank = soundBanks[i].SelectNodes("SoundBank");
                for (var j = 0; j < soundBank.Count; j++)
                {
                    var includedEvents = soundBank[j].SelectNodes("IncludedEvents");
                    for (var ie = 0; ie < includedEvents.Count; ie++)
                    {
                        var events = includedEvents[i].SelectNodes("Event");
                        for (var e = 0; e < events.Count; e++)
                        {
                            if (events[e].Attributes["Id"] != null && uint.Parse(events[e].Attributes["Id"].InnerText) == (uint)akEvent.ID)
                            {
                                if (events[e].Attributes["DurationType"] != null &&
                                    events[e].Attributes["DurationType"].InnerText == "Infinite")
                                {
                                    // Set both min and max to MaxDuration for infinite events
                                    result.MinDuration = MaxDuration;
                                    result.MaxDuration = MaxDuration;
                                }

                                if (events[e].Attributes["DurationMin"] != null)
                                {
                                    result.MinDuration = float.Parse(events[e].Attributes["DurationMin"].InnerText);
                                }
                                if (events[e].Attributes["DurationMax"] != null)
                                {
                                    result.MaxDuration = float.Parse(events[e].Attributes["DurationMax"].InnerText);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }

        return(result);
    }
Esempio n. 10
0
    public static bool Populate()
    {
        if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling)
        {
            return(false);
        }

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

        if (!File.Exists(filename))
        {
            FullSoundbankPath = Path.Combine(Application.streamingAssetsPath, WwiseSetupWizard.Settings.SoundbankPath);
#if UNITY_EDITOR_OSX
            FullSoundbankPath = FullSoundbankPath.Replace('\\', '/');
#endif
            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];
            }
        }

        bool bChanged = false;
        if (File.Exists(filename))
        {
            DateTime time = File.GetLastWriteTime(filename);
            if (time <= s_LastParsed)
            {
                return(false);
            }

            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++)
                {
                    bChanged = bChanged || SerialiseSoundBank(soundBank[j]);
                }
            }
        }
        return(bChanged);
    }
Esempio n. 11
0
    // Based on AkExampleAppBuilderBase.Build
    private static void MoveSoundBanks(string wwisePlatformString)
    {
        string wwiseProjFile      = Path.Combine(Application.dataPath, WwiseSetupWizard.Settings.WwiseProjectPath).Replace('/', Path.DirectorySeparatorChar);
        string wwiseProjectFolder = wwiseProjFile.Remove(wwiseProjFile.LastIndexOf(Path.DirectorySeparatorChar));

        string sourceSoundBankFolder      = Path.Combine(wwiseProjectFolder, AkBasePathGetter.GetPlatformBasePath());
        string destinationSoundBankFolder = Path.Combine(Application.dataPath + Path.DirectorySeparatorChar + "StreamingAssets",
                                                         Path.Combine(WwiseSetupWizard.Settings.SoundbankPath, wwisePlatformString));

        Debug.Log("Copying soundbanks from: " + sourceSoundBankFolder + "\nto: " + destinationSoundBankFolder);
        if (!AkUtilities.DirectoryCopy(sourceSoundBankFolder, destinationSoundBankFolder, true))
        {
            Debug.LogError("WwiseUnity: The soundbank folder for the " + wwisePlatformString + " platform doesn't exist. Make sure it was generated in your Wwise project");
        }
        UnityEditor.AssetDatabase.Refresh();
    }
Esempio n. 12
0
    private void OnEditorUpdate()
    {
        var logWarnings = AkBasePathGetter.LogWarnings;

        AkBasePathGetter.LogWarnings = false;
        var path = AkBasePathGetter.GetPlatformBasePath();

        AkBasePathGetter.LogWarnings = logWarnings;

        try
        {
            if (ExceptionOccurred || path != XmlWatcher.Path)
            {
                XmlWatcher.Path = path;
            }

            ExceptionOccurred = false;
        }
        catch
        {
            ExceptionOccurred = true;
        }

        if (!fireEvent)
        {
            return;
        }

        fireEvent = false;

        var populate = PopulateXML;

        if (populate == null || !populate())
        {
            return;
        }

        var callback = XMLUpdated;

        if (callback != null)
        {
            callback();
        }

        AkBankManager.ReloadAllBanks();
    }
Esempio n. 13
0
    private AkWwiseXMLWatcher()
    {
        XmlWatcher = new System.IO.FileSystemWatcher {
            Filter = "*.xml", IncludeSubdirectories = true,
        };

        try
        {
            // Event handlers that are watching for specific event
            XmlWatcher.Created += RaisePopulateFlag;
            XmlWatcher.Changed += RaisePopulateFlag;

            XmlWatcher.NotifyFilter        = System.IO.NotifyFilters.LastWrite;
            XmlWatcher.EnableRaisingEvents = true;
            XmlWatcher.Path = AkBasePathGetter.GetPlatformBasePath();
        }
        catch
        {
            ExceptionOccurred = true;
        }

        UnityEditor.EditorApplication.update += OnEditorUpdate;
    }
Esempio n. 14
0
    private void OnEditorUpdate()
    {
        var logWarnings = AkBasePathGetter.LogWarnings;

        AkBasePathGetter.LogWarnings = false;
        basePath = AkBasePathGetter.GetPlatformBasePath();
        AkBasePathGetter.LogWarnings = logWarnings;

        if (ExceptionOccurred || basePath != XmlWatcher?.Path)
        {
            new Thread(CreateWatcher).Start();
        }

        if (!fireEvent)
        {
            return;
        }

        fireEvent = false;

        var populate = PopulateXML;

        if (populate == null || !populate())
        {
            return;
        }

        var callback = XMLUpdated;

        if (callback != null)
        {
            callback();
        }

        AkBankManager.ReloadAllBanks();
    }
Esempio n. 15
0
    public void LoadNonLocalizedBank(string in_bankFilename)
    {
        string in_bankPath = "file://" + Path.Combine(AkBasePathGetter.GetPlatformBasePath(), in_bankFilename);

        this.DoLoadBank(in_bankPath);
    }
Esempio n. 16
0
    public static bool Populate()
    {
        if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode || UnityEditor.EditorApplication.isCompiling)
        {
            return(false);
        }

        try
        {
            // Try getting the SoundbanksInfo.xml file for Windows or Mac first, then try to find any other available platform.
            var logWarnings = AkBasePathGetter.LogWarnings;
            AkBasePathGetter.LogWarnings = false;
            var FullSoundbankPath = AkBasePathGetter.GetPlatformBasePath();
            AkBasePathGetter.LogWarnings = logWarnings;

            var filename = System.IO.Path.Combine(FullSoundbankPath, "SoundbanksInfo.xml");
            if (!System.IO.File.Exists(filename))
            {
                FullSoundbankPath = System.IO.Path.Combine(UnityEngine.Application.streamingAssetsPath, AkWwiseEditorSettings.Instance.SoundbankPath);

                if (!System.IO.Directory.Exists(FullSoundbankPath))
                {
                    UnityEngine.Debug.Log("WwiseUnity: Could not open SoundbanksInfo.xml, generated SoundBanks path does not exist: " + FullSoundbankPath);
                    return(false);
                }

                var foundFiles = System.IO.Directory.GetFiles(FullSoundbankPath, "SoundbanksInfo.xml", System.IO.SearchOption.AllDirectories);
                if (foundFiles.Length == 0)
                {
                    UnityEngine.Debug.Log("WwiseUnity: Could not find SoundbanksInfo.xml in directory: " + FullSoundbankPath);
                    return(false);
                }
                filename = foundFiles[0];
            }

            var time = System.IO.File.GetLastWriteTime(filename);
            if (time <= s_LastParsed)
            {
                UnityEngine.Debug.Log("WwiseUnity: Skipping parsing of SoundbanksInfo.xml because it has not changed.");
                return(false);
            }

            var doc = new System.Xml.XmlDocument();
            doc.Load(filename);

            var bChanged   = false;
            var soundBanks = doc.GetElementsByTagName("SoundBanks");
            for (var i = 0; i < soundBanks.Count; i++)
            {
                var soundBank = soundBanks[i].SelectNodes("SoundBank");
                for (var j = 0; j < soundBank.Count; j++)
                {
                    bChanged = SerialiseSoundBank(soundBank[j]) || bChanged;
                }
            }

            return(bChanged);
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.Log("WwiseUnity: Exception occured while parsing SoundbanksInfo.xml: " + e.ToString());
            return(false);
        }
    }
    public static bool Build()
    {
        //Choose app name and location
        string appPath = EditorUtility.SaveFilePanel("Build Unity-Wwise project",                                           //window title
                                                     Application.dataPath.Remove(Application.dataPath.LastIndexOf('/')),    //Default app location (unity project root directory)
                                                     "Unity_Wwise_app",                                                     //Default app name
                                                     getPlatFormExtension()                                                 //app extension (depends on target platform)
                                                     );
        //check if the build was cancelled
        bool isUserCancelledBuild = appPath == "";

        if (isUserCancelledBuild)
        {
            UnityEngine.Debug.Log("WwiseUnity: User cancelled the build.");
            return(false);
        }

        //get Wwise project file (.wproj) path
        string wwiseProjFile = Path.Combine(Application.dataPath, WwiseSetupWizard.Settings.WwiseProjectPath).Replace('/', '\\');

        //get Wwise project root folder path
        string wwiseProjectFolder = wwiseProjFile.Remove(wwiseProjFile.LastIndexOf(Path.DirectorySeparatorChar));

        //get Wwise platform string (the string isn't the same as unity for some platforms)
        string wwisePlatformString = UnityToWwisePlatformString(EditorUserBuildSettings.activeBuildTarget.ToString());

        //get soundbank location in the Wwise project for the current platform target
        string sourceSoundBankFolder = Path.Combine(wwiseProjectFolder, AkBasePathGetter.GetPlatformBasePath());

        //get soundbank destination in the Unity project for the current platform target
        string destinationSoundBankFolder = Path.Combine(Application.dataPath + "\\StreamingAssets",                                                            //Soundbank must be inside the StreamingAssets folder
                                                         Path.Combine(WwiseSetupWizard.Settings.SoundbankPath, wwisePlatformString)
                                                         );

        //Copy the soundbank from the Wwise project to the unity project (Inside the StreamingAssets folder as defined in Window->Wwise Settings)
        if (!AkUtilities.DirectoryCopy(sourceSoundBankFolder,           //source folder
                                       destinationSoundBankFolder,      //destination
                                       true                             //copy subfolders
                                       )
            )
        {
            UnityEngine.Debug.LogError("WwiseUnity: The soundbank folder for the " + wwisePlatformString + " platform doesn't exist. Make sure it was generated in your Wwise project");
            return(false);
        }

        //Get all the scenes to build as defined in File->Build Settings
        string[] scenes = new string[EditorBuildSettings.scenes.Length];
        for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
        {
            scenes[i] = EditorBuildSettings.scenes[i].path;
        }

        //Build the app
        BuildPipeline.BuildPlayer(scenes,                                               //scenes to build
                                  appPath,                                              //Location of the app to create
                                  EditorUserBuildSettings.activeBuildTarget,            //Platform for which to build the app
                                  BuildOptions.None
                                  );

        //Delete the soundbank from the unity project so they dont get copied in the game folder of fututre builds
        Directory.Delete(destinationSoundBankFolder, true);

        return(true);
    }
    /// Load a sound bank from WWW object
    public void LoadNonLocalizedBank(string in_bankFilename)
    {
        var bankPath = "file://" + System.IO.Path.Combine(AkBasePathGetter.GetPlatformBasePath(), in_bankFilename);

        DoLoadBank(bankPath);
    }
Esempio n. 19
0
 public void StartWatcher()
 {
     basePath = AkBasePathGetter.GetPlatformBasePath();
     new Thread(CreateWatcher).Start();
     UnityEditor.EditorApplication.update += OnEditorUpdate;
 }
 public static string GetValidBasePath()
 {
     return(AkBasePathGetter.GetPlatformBasePath());
 }
Esempio n. 21
0
    /// Load a language-specific bank from WWW object
    public void LoadLocalizedBank(string in_bankFilename)
    {
        string bankPath = "file://" + Path.Combine(Path.Combine(AkBasePathGetter.GetPlatformBasePath(), AkInitializer.GetCurrentLanguage()), in_bankFilename);

        DoLoadBank(bankPath);
    }