Forum rules - please read before posting.
Tech questions during the weekend? Drop in on the community Discord channel!

AC & WWise - Any integration to easily trigger events in action lists?

AC Ver: 1.70.4
Unity Ver: 2019.2.4f1

Hello,

Before I go delving into custom actions, is there any existing integration for using WWise events inside action lists?

Thanks!

Comments

  • edited February 19

    So I've written a custom action that seems to do the job for now. It's not very elegant, could be a lot better, but it will play a WWise event assuming you type the correct names.

    Ideally this would offer a drop down selection of all the available WWise events and then you just select the one to use, but I've no idea how to do that!

    /*
     *
     *  Adventure Creator
     *  by Chris Burton, 2013-2019
     *  
     *  "ActionPlayWWiseEvent.cs"
     * 
     *  Takes a WWise event as a string and then attempts a PostEvent() with it.
     *  by Pete Brisbourne 2020
     * 
     */
    
    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionPlayWWiseEvent : Action
        {
            // Declare variables here
            public string WwiseEvent;
            public GameObject gameobject;
    
            public ActionPlayWWiseEvent()
            {
                this.isDisplayed = true;
                category = ActionCategory.Custom;
                title = "Play WWise Event";
                description = "Plays an event from WWise";
            }
    
            override public float Run ()
            {
                /* 
                 * This function is called when the action is performed.
                 * 
                 * The float to return is the time that the game
                 * should wait before moving on to the next action.
                 * Return 0f to make the action instantenous.
                 * 
                 * For actions that take longer than one frame,
                 * you can return "defaultPauseTime" to make the game
                 * re-run this function a short time later. You can
                 * use the isRunning boolean to check if the action is
                 * being run for the first time, eg: 
                 */
    
                AkSoundEngine.PostEvent(WwiseEvent, gameobject);
    
                return 0f; //Action only happens on one frame
            }
    
    
            override public void Skip ()
            {
                /*
                 * This function is called when the Action is skipped, as a
                 * result of the player invoking the "EndCutscene" input.
                 * 
                 * It should perform the instructions of the Action instantly -
                 * regardless of whether or not the Action itself has been run
                 * normally yet.  If this method is left blank, then skipping
                 * the Action will have no effect.  If this method is removed,
                 * or if the Run() method call is left below, then skipping the
                 * Action will cause it to run itself as normal.
                 */
    
                 Run ();
            }
    
    
            #if UNITY_EDITOR
    
            override public void ShowGUI ()
            {
                // Action-specific Inspector GUI code here
                WwiseEvent = EditorGUILayout.TextField("Wwise Event:", WwiseEvent);
                gameobject = (GameObject)EditorGUILayout.ObjectField("Game Object:", gameobject, typeof(GameObject), true);
    
                AfterRunningOption ();
            }
    
            public override string SetLabel ()
            {
                // (Optional) Return a string used to describe the specific action's job.
    
                return string.Empty;
            }
            #endif  
        }
    }
    
  • There's a lot of fat you can trim here, since you have no need for Skip or SetLabel functions. Here's something a little easier to manage:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionPlayWWiseEvent : Action
        {
    
            public string WwiseEvent;
            public GameObject gameobject;
    
            public ActionPlayWWiseEvent()
            {
                this.isDisplayed = true;
                category = ActionCategory.Custom;
                title = "Play WWise Event";
                description = "Plays an event from WWise";
            }
    
            override public float Run ()
            {
                AkSoundEngine.PostEvent(WwiseEvent, gameobject);
    
                return 0f; //Action only happens on one frame
            }
    
            #if UNITY_EDITOR
    
            override public void ShowGUI ()
            {
                // Action-specific Inspector GUI code here
                WwiseEvent = EditorGUILayout.TextField("Wwise Event:", WwiseEvent);
                gameobject = (GameObject)EditorGUILayout.ObjectField("Game Object:", gameobject, typeof(GameObject), true);
    
                AfterRunningOption ();
            }
    
            #endif
        }
    }
    

    Ideally this would offer a drop down selection of all the available WWise events and then you just select the one to use, but I've no idea how to do that!

    I'm not familiar with WWise myself, but if you know in advance what the events are you can just create a string array:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionPlayWWiseEvent : Action
        {
    
            public int eventIndex;
            public GameObject gameobject;
    
            private string[] WwiseEvents = new string[] {"One", "Two", "Three"};
    
            public ActionPlayWWiseEvent()
            {
                this.isDisplayed = true;
                category = ActionCategory.Custom;
                title = "Play WWise Event";
                description = "Plays an event from WWise";
            }
    
            override public float Run ()
            {
                string WwiseEvent = WwiseEvents[eventIndex];
                AkSoundEngine.PostEvent(WwiseEvent, gameobject);
    
                return 0f; //Action only happens on one frame
            }
    
            #if UNITY_EDITOR
    
            override public void ShowGUI ()
            {
                eventIndex = EditorGUILayout.Popup ("Select event:", eventIndex, WwiseEvents);
                gameobject = (GameObject)EditorGUILayout.ObjectField("Game Object:", gameobject, typeof(GameObject), true);
    
                AfterRunningOption ();
            }
    
            #endif
        }
    }
    
  • edited February 20

    Ah thanks @ChrisIceBox, that is definitely a nice clean up. I remember it was only a few months ago I was terrified at the prospect of trying to write custom actions for AC, but it's one of the most powerful ways to extend it. I love it.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!