バージョン

menu_open
Wwise SDK 2018.1.11
C# (WampSharp) - WAMP Publisher/Subscriber

プロジェクトの初期化

Note: この例では、NuGetパッケージマネージャ・エクステンションがインストールされたVisual Studio 2017が必要です。

依存関係をインストールするには、Visual Studio 2017でサンプルプロジェクト<Wwise installation path>/SDK/samples/WwiseAuthoringAPI/cs/WaapiCS/WaapiCS.sln を開きます。ソリューションを右クリックし、 Restore NuGet Packagesを選択して、依存関係をインストールします。

スタートアップ オブジェクトを選択するには、ソリューション エクスプローラでWaapiCSプロジェクトを右クリックし、Properties をクリックします。アプリケーションタブを選択し、Startup object というセクションでWaapiCS.PubSubWwiseを選択します。

プロジェクトコード

サンプルファイル<Wwise installation path>/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を実行してプロジェクトを開いたら、ソリューションを実行し、出力を監視します:

Add a child to an entity in the Wwise Authoring application.

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: Wwiseから取得したオブジェクトIDなどの情報は、Wwise Authoringアプリケーションで開いたプロジェクトによって異なります。

このページはお役に立ちましたか?

サポートは必要ですか?

ご質問や問題、ご不明点はございますか?お気軽にお問い合わせください。

サポートページをご確認ください

あなたのプロジェクトについて教えてください。ご不明な点はありませんか。

プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。

Wwiseからはじめよう