想选取启动对象,在 Solution Explorer 中右键单击 WaapiCS 工程并点击 Properties。选择 Application 选项卡,并在有 Startup object 标签的部分下,选择 WaapiCS.PubSubWwise。
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
{
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();
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
{
[DataMember(Name = "return")]
public IEnumerable<string> @return { get; set; }
[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)
{
IDictionary<string, TMessage> childDict = formatter.Deserialize<IDictionary<string, TMessage>>(argumentsKeywords["child"]);
string id = formatter.Deserialize<string>(childDict["id"]);
Console.WriteLine("A child was added, ID={0}", id);
Console.WriteLine("Press any key to continue...");
mContext.unsubscribeDisposable.DisposeAsync().Wait();
}
public void Event<TMessage>(IWampFormatter<TMessage> formatter, long publicationId, EventDetails details) { }
public void Event<TMessage>(IWampFormatter<TMessage> formatter, long publicationId, EventDetails details, TMessage[] arguments) { }
}
}
在 Project Explorer 里的 Audio 选项卡中,在 Actor-Mixer Hierarchy 下选择 Default Work Unit 并添加一个容器。在输出中,您应该能看到: