Beispiel #1
0
    /// <summary>
    /// Find the open transport in ItemTransports or create a new one.
    /// </summary>
    /// <param name="guid">GUID of the object.</param>
    /// <returns></returns>
    static async private Task <int> GetTransport(System.Guid guid)
    {
        TransportInfo transportInfo;

        if (!ItemTransports.TryGetValue(guid, out transportInfo))
        {
            transportInfo = await CreateTransport(guid);
        }
        return(transportInfo.TransportID);
    }
Beispiel #2
0
    /// <summary>
    /// Send a WAAPI call to create a transport in Wwise.
    /// Subscribe to the ak.wwise.core.transport.stateChanged topic of the new transport.
    /// Add the transport info to ItemTransports.
    /// </summary>
    /// <param name="guid">GUID of the Event</param>
    /// <returns></returns>
    static async private Task <TransportInfo> CreateTransport(System.Guid guid)
    {
        var args   = new ArgsObject(guid.ToString("B"));
        var result = await WaapiClient.Call(ak.wwise.core.transport.create, args, null, timeout : 1000);

        int  transportID    = UnityEngine.JsonUtility.FromJson <ReturnTransport>(result).transport;
        var  options        = new TransportOptions(transportID);
        uint subscriptionID = await WaapiClient.Subscribe(ak.wwise.core.transport.stateChanged, options, HandleTransportStateChanged);

        var transport = new TransportInfo(transportID, subscriptionID);

        ItemTransports.Add(guid, transport);
        return(transport);
    }
Beispiel #3
0
    /// <summary>
    /// Handle the messages published by a transport when its state is changed.
    /// If stopped, enqueue a command with DestroyTransport as its payload.
    /// </summary>
    /// <param name="message"></param>
    static private void HandleTransportStateChanged(string message)
    {
        TransportState transport = UnityEngine.JsonUtility.FromJson <TransportState>(message);

        System.Guid itemID      = new System.Guid(transport.@object);
        int         transportID = transport.transport;

        if (transport.state == WaapiKeywords.STOPPED)
        {
            waapiCommandQueue.Enqueue(new WaapiCommand(
                                          async() => await DestroyTransport(itemID)));
        }

        else if (transport.state == WaapiKeywords.PLAYING && !ItemTransports.ContainsKey(itemID))
        {
            ItemTransports.Add(itemID, new TransportInfo(transportID, 0));
        }
    }
Beispiel #4
0
    /// <summary>
    /// Unsubscribe from the transport topic and send a WAAPI command to destroy the transport in Wwise.
    /// </summary>
    /// <param name="in_itemID"> GUID of the Event.</param>
    /// <returns></returns>
    static async Task <string> DestroyTransport(System.Guid in_itemID)
    {
        if (!ItemTransports.ContainsKey(in_itemID))
        {
            return(null);
        }

        if (ItemTransports[in_itemID].SubscriptionID != 0)
        {
            await WaapiClient.Unsubscribe(ItemTransports[in_itemID].SubscriptionID);
        }

        var args   = new ArgsTransport(ItemTransports[in_itemID].TransportID);
        var result = await WaapiClient.Call(ak.wwise.core.transport.destroy, args, null);

        ItemTransports.Remove(in_itemID);
        return(result);
    }