Leçon 5

Table des matières

Setting Game Parameters using Wwise-Types

When it comes to continuously keeping control of gradually changing effect properties, virtual voice settings, or volume levels, you'd most likely use a Game Parameter. Game Parameters allow you to control how a sound interpolates and changes over time. Take the sun in the Wwise Adventure Game. The sunlight source is controlled by a TimeOfDay property and just like the sun sets while the Allegro Kingdom goes dark, the ambience should also change slowly to night time.

This gradual change in ambience is set up using a Blend Container. Here the value of the Time_of_Day Game Parameter controls whether it's the Day or Night ambience playing. In the following steps, you will learn how to drive the Time_of_Day Game Parameter by WAG's TimeOfDay property. You will ensure that it is working with the use of the Game Object Profiler.

  1. In the Unity menu, go to Audiokinetic > Certifications > 301 > Lesson 5 and select Setting Game Parameters with Wwise-Types.

  2. In the Hierarchy, search for Sun and select the Sun game object.

  3. In the Inspector, create a new script called SetTimeOfDayRTPC

    [Note]

    If you do not know how to create a script, please refer to Lesson 4's Creating a Wwise-Type Event property.

  4. To open the script in a code editor, double-click the SetTimeOfDayRTPC script.

    The first step in making the Wwise-Type RTPC class property is to define the class (Ak.Wwise.RTPC) and access modifier (public).

  5. Inside the SetTimeOfDayRTPC class, type public AK.Wwise.RTPC.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
        
    public class SetTimeOfDayRTPC : MonoBehaviour {
        public AK.Wwise.RTPC
        // Use this for initialization
        void Start () {
        
        }
        
        // Update is called once per frame.
        void Update () {
                
        }
    }

  6. Name the variable TimeOfDayRTPC and end off with a semicolon (;).

    public class SetTimeOfDayRTPC : MonoBehaviour {
        public AK.Wwise.RTPC TimeOfDayRTPC;

    You will now see an assignable Wwise-Type RTPC property drawer in the Inspector, but you are currently not doing anything with it, so let's call the Wwise-Type from a function. As the sunlight is continuously changing, you should also constantly update the Time_of_Day Game Parameter to make the ambiences change gradually. Conveniently, the Update() function updates every frame at runtime, and here you can update the RTPC as well.

  7. Inside the Update() function, type TimeOfDayRTPC.set

    // Update is called once per frame.
    void Update () {
        TimeOfDayRTPC.set
    }

    Once you start typing after the period (.), Visual Studio will look for available functions resembling what you wrote. You will see two options: SetGlobalValue and SetValue. If no menu appears, try to delete all down to TimeOfDayRTPC and add a period (.).

    If you were to use the SetValue() function, you would only set the RTPC for the current game object. As the region ambiences are located on many different game objects, you should instead use the SetGlobalValue, affecting all game objects in the game using the same Game Parameter.

  8. Continued on TimeOfDayRTPC, click the SetGlobalValue option or type SetGlobalValue()

    // Update is called once per frame.
    void Update () {
        TimeOfDayRTPC.SetGlobalValue()
    }

    You also need to send a value to the RTPC Game Parameter. In the Wwise Adventure Game, the time of day is updated in the DayNightCycle script. This script will continuously send this value to the GameManager, which keeps track of various global game variables during gameplay. As such, to set the TimeOfDayRTPC, you can simply retrieve the value from the GameManager and use the .SetGlobalValue() function to send the value to Wwise.

  9. Inside the SetGlobalValue parentheses, type GameManager.TimeOfDay and after the parentheses add a semicolon (;).

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
        
    public class SetTimeOfDayRTPC : MonoBehaviour {
        public AK.Wwise.RTPC TimeOfDayRTPC;
        // Use this for initialization.
        void Start () {
          
        }
        
        // Update is called once per frame.
        void Update () {
            TimeOfDayRTPC.SetGlobalValue(GameManager.TimeOfDay);
        }
    }

    You have now completed all script steps, and you can now save the script.

  10. Press CTRL+S on Windows or CMD+S on Mac to Save the script.

    Lastly, you should assign the Time_of_Day Game Parameter to the Wwise-Type RTPC variable, so the script will know which Game Parameter to set.

  11. In Unity, select the TimeOfDayRTPC property drawer, expand Ambient and double-click Time_Of_Day.

    To test if the Game Parameter is being updated, we'll use the Game Object Profiler. By selecting the Time_Of_Day Game Parameter, you can monitor the value over time.

  12. In Wwise, go to Layouts and select Game Object Profiler.

    The Game Object Profiler allows you to monitor a registered game object. A game object is registered whenever you post any Event from either a component or from a script. However, as we're setting the value function with a global scope, the RTPC value applies for all game objects assigned to the same RTPC, so you don't need to specify a game object in the Game Object Profiler to see the Game Parameter curve.

    [Tip]

    Learn more about the differences of Global and Game Object scope in the Understanding Global and Game Object Scope section below.

  13. In the Game Object Explorer, select the Watches tab.

  14. Using the selector (>>), select Global Game Object.

    Next, the Game Parameter you want to monitor should be selected in the Game Sync Monitor.

  15. In the Game Sync Monitor, click Add.

  16. Expand the Ambient Work Unit, select the Time_of_Day Game Parameter and click OK.

    You can now connect to the game and play it, and the Game Parameter will be captured in the Game Sync Monitor.

  17. Click Remote…

  18. In the Remote Connections view, highlight the Wwise Adventure Game (Editor) and click Connect.

  19. In Unity, click Play.

  20. Switch to Wwise and look at the Game Sync Monitor.

    Over time, you will see a slight increase in the Time_of_Day Game Parameter, as it will be updating the RTPC for every frame, by referring to the TimeOfDay value in the GameManager script. To see a more radical change, you can also try to change the Time of Day slider in the in-game WAG menu, which will update the TimeOfDay variable in the GameManager. Remember to exit Play mode before taking on a new exercise.

  21. Press ESC to open the WAG menu and click Play again to exit Play mode.