Contenu connexe
Similaire à Building the Game Server both API and Realtime via c# (20)
Plus de Yoshifumi Kawai (20)
Building the Game Server both API and Realtime via c#
- 2. 河合 宜文 / Kawai Yoshifumi / @neuecc
Cysharp, Inc.
Cygames
C#大統一理論
C#
- 22. C# as a Schema
C#に固定することで
通信定義そのものをC#で表現する
- 26. public class TestService : ITestService
{
// パブリックメソッドがそのままgRPC定義
public async UnaryResult<int> Sum(int x, int y)
{
// async/awaitにも自然に対応
// マジカル技術によりasync Task<T>じゃなくてもawait可能
await Task.Yield();
return x + y;
}
}
// 普通のgRPCの接続を作る(MagicOnion用の特別なことはない)
var channel = new Channel("127.0.0.1:12345");
// 自然な書き味で、タイプセーフにRPC通信を実現
// C#のasync/await構文により、非同期通信も自然に見える
var client = MagicOnionClient.Create<ITestService>(channel);
var result = await client.Sum(100, 200);
クライアントもサーバーも自
然に繋がっているように見え
る(デバッガもサーバー/クラ
イアント共有でステップ実行
で繋がって動いていく)
- 44. ⚫ Mirror
⚫ Photon Engine
⚫ Monobit Engine
⚫ DIY - WebSocket + Server App
⚫ DIY - WebSocket + mBaaS
⚫ DIY - TCP(UDP) + Server App
⚫ Unity Headless
- 50. リアルタイム通信のための双方向の型付きRPC
public interface IGamingHub : IStreamingHub<IGamingHub, IGamingHub
{
Task<Player[]> JoinAsync(string roomName, string userName, Vec
Task LeaveAsync();
Task MoveAsync(Vector3 position, Quaternion rotation);
}
public interface IGamingHubReceiver
{
void OnJoin(Player player);
void OnLeave(Player player);
void OnMove(Player player);
}
- 52. il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Call, typeof(AsyncDuplexStreamingCall<byte[], byte[]>).GetProperty("RequestStream").GetMethod);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, serializerOptionsField);
il.Emit(OpCodes.Newobj, (typeof(MarshallingClientStreamWriter<>).MakeGenericType(def.RequestType).GetConstructors().Singl
il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Call, typeof(AsyncDuplexStreamingCall<byte[], byte[]>).GetProperty("ResponseStream").GetMethod);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, serializerOptionsField);
il.Emit(OpCodes.Newobj, (typeof(MarshallingAsyncStreamReader<>).MakeGenericType(def.ResponseType).GetConstructors().Singl
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, serializerOptionsField);
resultType2 = typeof(DuplexStreamingResult<,>).MakeGenericType(def.RequestType, def.ResponseType);
il.Emit(OpCodes.Newobj, resultType2.GetConstructors()[0]);
MethodType t;
string requestType;
string responseType;
ITypeSymbol unwrappedOriginalResponseType;
ExtractRequestResponseType(y, out t, out requestType, ou
var id = FNV1A32.GetHashCode(y.Name);
return new MethodDefinition
{
Name = y.Name,
MethodType = t,
RequestType = requestType,
ResponseType = responseType,
UnwrappedOriginalResposneTypeSymbol = unwrappedOrigi
OriginalResponseTypeSymbol = y.ReturnType,
IsIfDebug = y.GetAttributes().FindAttributeShortName
HubId = id,
Parameters = y.Parameters.Select(p =>
{