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 > Certification > 301 > Lesson 5 and select Setting Game Parameters with Wwise-Types.

  2. In the Hierarchy, expand the Wwise game object 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.

    Our goal is to create a script that will, every frame of the game, get the time of day in game and set the appropriate RTPC. In WAG, this RTPC already exists under the name Time_of_Day. To update that RTPC you can use a Wwise-Type, and the one to use for an RTPC is, you guessed it, 'AK.Wwise.RTPC'. Let's define the class and make it visible in the inspector using the 'public' access modifier.

  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 (;).

    publicclass SetTimeOfDayRTPC : MonoBehaviour {
    public AK.Wwise.RTPC TimeOfDayRTPC;
    
  7. Press CTRL+S on Windows or CMD+S on Mac to Save the script.

    You will now see an assignable Wwise-Type RTPC property drawer in the Inspector, but other than allowing you to select an RTPC, the property is not used for anything in your script. As the property needs to be updated constantly, along with time passing in-game, let's call the property from a function that will update for every frame of the game. This function is named Update() and it will run everything within the curly brackets.

  8. 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.

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

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

    Next, you 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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.

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

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

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

  16. In the Game Sync Monitor, click Add.

  17. 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.

  18. Click Remote…

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

  20. In Unity, click Play.

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

    You will now see a stready rising curve in the Game Sync Monitor. due to the script updating the RTPC with the TimeOfDay parameter value from the GameManager script. To see a more radical change, you can change the Time of Day slider in the in-game WAG menu, which will update the TimeOfDay variable in the GameManager. Let's exit Play mode before proceeding.

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


Cette page a-t-elle été utile ?