版本

menu_open

C# (WampSharp) - WAMP 发布器/订阅器

初始化工程

Note.gif
Note: 这一示例需要安装 Visual Studio 2017 并带有 NuGet 软件包管理器扩展。

想安装依赖,请在 Visual Studio 2017 中打开示例工程 <Wwise 安装路径>/SDK/samples/WwiseAuthoringAPI/cs/WaapiCS/WaapiCS.sln。通过在解决方案上单击右键并选择 Restore NuGet Packages 来安装依赖。

想选取启动对象,在 Solution Explorer 中右键单击 WaapiCS 工程并点击 Properties。选择 Application 选项卡,并在有 Startup object 标签的部分下,选择 WaapiCS.PubSubWwise

工程代码

找到示例文件 <Wwise 安装路径>/SDK/samples/WwiseAuthoringAPI/cs/WaapiCS/PubSubWwise.cs 的位置。

该文件包含以下代码,让您能连接到 Wwise Authoring API。

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using SystemEx;

using WampSharp.V2;
using WampSharp.V2.Client;
using WampSharp.V2.PubSub;
using WampSharp.Core.Serialization;
using WampSharp.V2.Core.Contracts;


namespace WaapiCS
{
    internal class SubscribeContext
    {
        // Used to dispose of the subscription, effectively sending an unsubscribe message
        public IAsyncDisposable unsubscribeDisposable = null;
    }

    internal class PubSubWwise
    {
        const string serverAddress = "ws://127.0.0.1:8080/waapi";
        const string selectionChangedTopic = "ak.wwise.core.object.childAdded";

        public static void Main(string[] args)
        {
            DefaultWampChannelFactory factory = new DefaultWampChannelFactory();
            IWampChannel channel = factory.CreateJsonChannel(serverAddress, "realm1");
            channel.Open().Wait();

            IWampTopicProxy topicProxy = channel.RealmProxy.TopicContainer.GetTopicByUri(selectionChangedTopic);
            MySubscribeOptions options = new MySubscribeOptions();

            // Set your options here
            options.@return = new string[] { "id" };

            SubscribeContext context = new SubscribeContext();
            topicProxy.Subscribe(new MySubscriber(context), options)
                .ContinueWith(t => context.unsubscribeDisposable = t.Result)
                .Wait();

            Console.WriteLine("Add a child to an entity in the Wwise Authoring application.");
            Console.ReadLine();
        }
    }

    internal class MySubscribeOptions : SubscribeOptions
    {
        // Add data members with name corresponding to the option fields (see reference documentation)
        //          vvvvvvvvvvvvvvv
        [DataMember(Name = "return")]
        public IEnumerable<string> @return { get; set; }

        // If a data member is not set, it will not be sent to WAAPI
        [DataMember(Name = "platform")]
        public string platform { get; set; }
    }

    internal class MySubscriber : IWampRawTopicClientSubscriber
    {
        private SubscribeContext mContext;

        public MySubscriber(SubscribeContext context)
        {
            mContext = context ?? throw new ArgumentNullException("Context cannot be null");
        }

        public void Event<TMessage>(IWampFormatter<TMessage> formatter, long publicationId, EventDetails details, TMessage[] arguments, IDictionary<string, TMessage> argumentsKeywords)
        {
            // TMessage is used to represent a serialized message type
            // We know by contract that the child element is another dictionary
            IDictionary<string, TMessage> childDict = formatter.Deserialize<IDictionary<string, TMessage>>(argumentsKeywords["child"]);
            // Again, we know by contract that a field containing a string is expected for the key "id"
            string id = formatter.Deserialize<string>(childDict["id"]);

            Console.WriteLine("A child was added, ID={0}", id);
            Console.WriteLine("Press any key to continue...");

            // Dispose to unsubscribe
            mContext.unsubscribeDisposable.DisposeAsync().Wait();
        }

        // Other method overloads are never used: WAAPI always sends keyword arguments
        public void Event<TMessage>(IWampFormatter<TMessage> formatter, long publicationId, EventDetails details) { }
        public void Event<TMessage>(IWampFormatter<TMessage> formatter, long publicationId, EventDetails details, TMessage[] arguments) { }
    }

}

运行工程

Wwise 在运行并且工程已打开时,执行解决方案,并观察输出:

在 Wwise Authoring 应用中为某实体添加一个子级。

在 Project Explorer 里的 Audio 选项卡中,在 Actor-Mixer Hierarchy 下选择 Default Work Unit 并添加一个容器。在输出中,您应该能看到:

A child was added, ID={EAFD1799-41AA-4A98-B0CA-BDB8CDA0D878}
Press any key to continue...
Note.gif
Note: 从 Wwise 中获取的信息,比如对象 ID,会因 Wwise Authoring Application 中打开的工程而异。

此页面对您是否有帮助?

需要技术支持?

仍有疑问?或者问题?需要更多信息?欢迎联系我们,我们可以提供帮助!

查看我们的“技术支持”页面

介绍一下自己的项目。我们会竭力为您提供帮助。

来注册自己的项目,我们帮您快速入门,不带任何附加条件!

开始 Wwise 之旅