버전

menu_open
Wwise SDK 2023.1.3
C# WaapiClient - WAMP

프로젝트 초기화하기

참고: This example requires Visual Studio 2015+ with C# support and the NuGet package manager extension.

To install dependencies, open the sample project <Wwise installation path>/SDK/samples/WwiseAuthoringAPI/cs/WaapiClientCsPC_vc160.sln in Visual Studio. 해당 솔루션을 우클릭하고 Restore NuGet Packages를 선택해 종속성을 설치합니다.

프로젝트 코드

Locate the sample file <Wwise installation path>/SDK/samples/WwiseAuthoringAPI/cs/WaapiClientSample/Program.cs.

이 파일에는 다음 코드가 포함돼있어 Wwise Authoring API에 연결할 수 있게 해줍니다.

/******************************************************************************
The content of this file includes portions of the AUDIOKINETIC Wwise Technology
released in source code form as part of the SDK installer package.
Commercial License Usage
Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
may use this file in accordance with the end user license agreement provided
with the software or, alternatively, in accordance with the terms contained in a
written agreement between you and Audiokinetic Inc.
Apache License Usage
Alternatively, this file may be used under the Apache License, Version 2.0 (the
"Apache License"); you may not use this file except in compliance with the
Apache License. You may obtain a copy of the Apache License at
http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed
under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
the specific language governing permissions and limitations under the License.
Copyright (c) 2024 Audiokinetic Inc.
*******************************************************************************/
using Newtonsoft.Json.Linq;
using System;
using System.Threading.Tasks;
namespace AK.Wwise.Waapi
{
class Program
{
static void Main(string[] args)
{
_Main().Wait();
}
static async Task _Main()
{
try
{
AK.Wwise.Waapi.JsonClient client = new AK.Wwise.Waapi.JsonClient();
// Try to connect to running instance of Wwise on localhost, default port
await client.Connect();
// Register for connection lost event
client.Disconnected += () =>
{
System.Console.WriteLine("We lost connection!");
};
// Simple RPC call
JObject info = await client.Call(ak.wwise.core.getInfo, null, null);
System.Console.WriteLine(info);
// Create an object for our tests, using C# anonymous types
var testObj = await client.Call(
ak.wwise.core.@object.create,
new
{
name = "WaapiObject",
parent = @"\Actor-Mixer Hierarchy\Default Work Unit",
type = "ActorMixer",
onNameConflict = "rename"
}, null);
System.Console.WriteLine(testObj["id"]);
// Subscribe to name changes
int nameSubscriptionId = await client.Subscribe(
ak.wwise.core.@object.nameChanged,
null,
(JObject publication) =>
{
System.Console.WriteLine($"Name changed: {publication}");
});
// Subscribe to property changes
int propertySubscriptionId = await client.Subscribe(
ak.wwise.core.@object.propertyChanged,
new JObject(
new JProperty("property", "Volume"),
new JProperty("object", testObj["id"])),
(JObject publication) =>
{
System.Console.WriteLine($"Property '{publication["property"]}' changed: {publication["new"]}");
});
// Set name using C# anonymous types
try
{
await client.Call(
ak.wwise.core.@object.setName,
new
{
@object = testObj["id"],
value = "NewName"
}, null);
// Undo the set name, using JObject constructor
await client.Call(
ak.wwise.ui.commands.execute,
new JObject(new JProperty("command", "Undo")), null);
}
catch (AK.Wwise.Waapi.Wamp.ErrorException e)
{
System.Console.Write(e.Message);
// Ignore the error, it is possible we have a name conflict
}
// Set property using anonymous type
await client.Call(
ak.wwise.core.@object.setProperty,
new
{
@property = "Volume",
@object = testObj["id"],
value = 6
}, null);
// Setting a property using dynamic types
{
dynamic args = new JObject();
args.property = "Volume";
args.@object = testObj["id"];
args.value = 9;
// Set property with JObject
await client.Call(ak.wwise.core.@object.setProperty, args, null);
}
// Setting a property using JObject constructor
await client.Call(ak.wwise.core.@object.setProperty,
new JObject(
new JProperty("property", "Volume"),
new JProperty("object", testObj["id"]),
new JProperty("value", 10)),
null);
{
// Query the volume, using JObject constructor
var query = new JObject(
new JProperty("from", new JObject(
new JProperty("id", new JArray(new string[] { testObj["id"].ToString() })))));
var options = new JObject(
new JProperty("return", new string[] { "name", "id", "@Volume" }));
JObject result = await client.Call(ak.wwise.core.@object.get, query, options);
System.Console.WriteLine(result["return"][0]["@Volume"]);
}
{
// Query the project using anonymous objects
var query = new
{
from = new
{
id = new string[] { testObj["id"].ToString() }
}
};
var options = new
{
@return = new string[] { "name", "id", "@Volume", "path" }
};
JObject jresult = await client.Call(ak.wwise.core.@object.get, query, options);
System.Console.WriteLine(jresult["return"][0]["@Volume"]);
}
// Clean up the created objects!
await client.Call(
ak.wwise.core.@object.delete,
new JObject(new JProperty("object", testObj["id"])), null);
await client.Unsubscribe(nameSubscriptionId);
await client.Unsubscribe(propertySubscriptionId);
await client.Close();
System.Console.WriteLine("done");
}
catch (Exception e)
{
System.Console.Error.WriteLine(e.Message);
}
}
}
}

프로젝트 실행하기

Build the solution (Ctrl+Shift+B) and run the sample using Visual Studio (F5).

출력 콘솔에 나타나는 메시지를 확인하세요.

Audiokinetic namespace

이 페이지가 도움이 되었나요?

지원이 필요하신가요?

질문이 있으신가요? 문제를 겪고 계신가요? 더 많은 정보가 필요하신가요? 저희에게 문의해주시면 도와드리겠습니다!

지원 페이지를 방문해 주세요

작업하는 프로젝트에 대해 알려주세요. 언제든지 도와드릴 준비가 되어 있습니다.

프로젝트를 등록하세요. 아무런 조건이나 의무 사항 없이 빠른 시작을 도와드리겠습니다.

Wwise를 시작해 보세요