版本

menu_open
Wwise SDK 2018.1.11
C# (WampSharp)- WAMP

初始化工程

Note: 该示例需要带有对 C# 支持的 Visual Studio 2017 和 NuGet 软件包管理器扩展。

从 WampSharp 1.2.5.36-beta 开始,如果您在 Wwise Authoring 应用的同一台电脑上运行示例,那么您需要将 ws://127.0.0.1:8080 添加为允许的来源(origin)。若要做到这一点,请进入 Project > User Preferences... 并在 Wwise Authoring API 中的 Allowed origins 文本框中添加地址。请注意数值用逗号分隔。

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

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

工程代码

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

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

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using WampSharp.Core.Serialization;
using WampSharp.V2;
using WampSharp.V2.Client;
using WampSharp.V2.Core.Contracts;
using WampSharp.V2.Rpc;
namespace WaapiCS
{
class CallWwise
{
const string serverAddress = "ws://127.0.0.1:8080/waapi";
public static void Main(string[] args)
{
// Wwise allows by default ws://127.0.0.1 and ws://localhost.
// However, if you specify anything else in the server address, you will need to add
// it as an allowed origin in Wwise User Preferences.
// To do so, go to Project > User Preferences... and in the Wwise Authoring API section
// at the bottom of the window, add the address in the Allowed origins text box.
// Note that values are comma-separated.
DefaultWampChannelFactory factory = new DefaultWampChannelFactory();
IWampChannel channel = factory.CreateJsonChannel(serverAddress, "realm1");
channel.Open().Wait();
IWampRealmProxy realmProxy = channel.RealmProxy;
CallGetInfo(realmProxy);
CallGetSelectedObjects(realmProxy);
Console.ReadLine();
}
public static void CallGetInfo(IWampRealmProxy realmProxy)
{
Console.WriteLine("Calling 'ak.wwise.core.getInfo'");
// Arguments are passed using keywordArguments with primitive values which are serialized as Json
IDictionary<string, object> keywordArguments = new Dictionary<string, object>();
realmProxy.RpcCatalog.Invoke(
new AssertCallback(),
new CallOptions(),
"ak.wwise.core.getInfo",
new object[] { }, // Volontarily empty, we use only keywordArguments
keywordArguments);
}
public static void CallGetSelectedObjects(IWampRealmProxy realmProxy)
{
Console.WriteLine("Calling 'ak.wwise.ui.getSelectedObjects'");
// Optional arguments are passed using a subclass of CallOptions providing data members as specified by the Wwise Authoring API
MyCallOptions options = new MyCallOptions();
options.@return = new string[] { "id", "name", "parent" };
realmProxy.RpcCatalog.Invoke(
new GetSelectedObjectsCallback(),
options,
"ak.wwise.ui.getSelectedObjects",
new object[] { }, // Volontarily empty, we use only keywordArguments
new Dictionary<string, object>()); // Volontarily empty, no keywordArguments are necessary for this API call
}
}
public class AssertCallback : IWampRawRpcOperationClientCallback
{
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details, TMessage[] arguments, IDictionary<string, TMessage> argumentsKeywords)
{
string name = argumentsKeywords["displayName"].ToString();
string copyright = formatter.Deserialize<JToken>(argumentsKeywords["version"])["displayName"].ToString();
Console.WriteLine("ak.wwise.core.getInfo: Hello {0} {1}", name, copyright);
}
// Other method overloads are never used: WAAPI always sends keyword arguments
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error, TMessage[] arguments, TMessage argumentsKeywords) {}
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error) {}
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error, TMessage[] arguments) {}
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details) {}
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details, TMessage[] arguments) {}
}
public class GetSelectedObjectsCallback : IWampRawRpcOperationClientCallback
{
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details, TMessage[] arguments, IDictionary<string, TMessage> argumentsKeywords)
{
string prefix = "ak.wwise.ui.getSelectedObjects: ";
Console.WriteLine(prefix + "Got selected object data!");
IEnumerable<JToken> objects = formatter.Deserialize<IEnumerable<JToken>>(argumentsKeywords["objects"]);
int selectedObjectsNum = objects.Count<JToken>();
Console.WriteLine(prefix + "Got {0} object(s)!", selectedObjectsNum);
if (selectedObjectsNum >= 1)
{
JToken firstObject = objects.First<JToken>();
Console.WriteLine(prefix + "The first selected object is '{0}' ({1})",
firstObject["name"].ToString(),
firstObject["id"].ToString());
JToken parent = firstObject["parent"];
if (parent == null)
{
Console.WriteLine(prefix + "It has no parent.");
}
else
{
Console.WriteLine(prefix + "Its parent is '{0}' ({1})",
parent["name"].ToString(),
parent["id"].ToString());
}
}
else
{
Console.WriteLine(prefix + "Select something and try again!");
}
}
// Other method overloads are never used: WAAPI always sends keyword arguments
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error, TMessage[] arguments, TMessage argumentsKeywords) { }
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error) { }
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error, TMessage[] arguments) { }
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details) { }
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details, TMessage[] arguments) { }
}
public class MyCallOptions : CallOptions
{
// 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; }
}
}

运行工程

构建解决方案(Ctrl+B)并使用 Visual Studio 运行示例(F5)。

该示例调用两种方法:一种从 Wwise Authoring Application 中获取一般信息,另一种获取在 Application 中选中的对象。

观察输出控制台显示的消息。您应该会看到类似这样的信息:

Calling 'ak.wwise.core.getInfo'
Calling 'ak.wwise.ui.getSelectedObjects'
ak.wwise.core.getInfo: Hello Wwise v2017.1.0
ak.wwise.ui.getSelectedObjects: Got selected object data!
ak.wwise.ui.getSelectedObjects: Got 1 object(s)!
ak.wwise.ui.getSelectedObjects: The first selected object is 'New Sequence Container' ({03E8DC21-EB2F-4607-BFCC-25BCE69DFB27})
ak.wwise.ui.getSelectedObjects: Its parent is 'ParentA' ({FBB64B3C-711C-46E6-9BBC-B49511F08244})
Note: 从 Wwise 中获取的信息,比如对象 ID,会因 Wwise Authoring Application 中打开的工程而异。如果不存在已选项,会显示以下信息:ak.wwise.ui.getSelectedObjects: Select something and try again!

此页面对您是否有帮助?

需要技术支持?

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

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

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

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

开始 Wwise 之旅