A wrapper of Photon C# Client SDK for GDScript. Contain Photon Realtime Client and Photon Chat Client.
Because of the lack of time, I can't complete a perfect description in both script and document.
But the usage of this SDK is similar to Photon C# Client SDK, basically you can refer to the official document.
The most importance class are in addons\addons\PhotonGDScriptClientSDK\core
, the others data class and object represent class are in addons\addons\PhotonGDScriptClientSDK\wraps
You must use Godot 3.x mono.
- Install this addon like others addon.
- Build you project at least once to generate the
.csproj
file. - Include Photon C# SDK's
.dll
to you C# project. - Enable this addon.
If you don't know how to include C# SDK's .dll
, you can add follow text as a xml tiem under Project
item in .csproj
file:
for debug:
<ItemGroup>
<Reference Include="addons\PhotonGDScriptClientSDK\dependents\libs\Debug\netstandard2.0\Photon-NetStandard.dll" />
</ItemGroup>
for release:
<ItemGroup>
<Reference Include="addons\PhotonGDScriptClientSDK\dependents\libs\Release\netstandard2.0\Photon-NetStandard.dll" />
</ItemGroup>
- The key word
LoadingBalancing
in C# SDK is equal toRealtime
in GDScript SDK( the reson of usingLoadingBalancing
in C# SDK is to compatible the old implementation, but now is a new implementation for GDScript , so I replace it byRealtime
in GDScript SDK ). - You should access Photon's enum by
Photon.<EnumName>.<EnumItemName>
in GDScript SDK. Player
,Room
andRoomInfo
in C# SDK are renamed asPhotonPlayer
,PhotonRoom
andPhotonRoomInfo
.- You should access data class's default or prefeb static intance by
<DataClassName>.Prefeb.<Default/PrefebName>
. - The Callback Interfaces' methods and Client Events in C# SDK are implement in GDScript SDK as follow:
- Overridable methods( are called realtime, used in extends case);
- Signals(are used in all case, are called later than Overridable methods );
- Group's objects callback methods( are called defer as default, you can code
<RealtimeClient/ChatClient>.notify_when_idle = false
to set their are called realtime, but they are still called later than signal).
- The argument's type of callback
web_rpc_responsed
in GDScript is different to C# SDK, it isWebRpcResponse
( In C#, it isOperationResponse
). - You can't access the
PhotonPeer
( a underlying implementation forRealtimeClient
andChatClient
), you don't need to access it in common usage. If you has necessary to access it,please commit an issue to describe the necessity. - Because this SDK is a wrapper of C# SDK, in order to maximaize performance, I set the property
PhotonPeer.ReuseEventInstance
totrue
. You can control it byRealtimeClient.reuse_event_instance
andChatClient.reuse_event_instance
in GDScript version. - As the same reson as above, the instances which their class are named
ErroInfo
,OperationResponse
andWebRpcResponse
, which got fromRealtimeClient
andChatClient
, are always the same intance, event if got from defferent Client instancea. If you need to cache infos which in these intances, please extract infos every time you get them. - I‘m not expose the property
ChatClient.UseBackgroundWorkerForSending
for GDSctipt SDK. Instead, I implement a backgound thread system to send outgoing commands and dispatch incoming commands for bothRealtimeClient
andChatClient
:- use
bg_send
to control the ability of send outgoing commands; - use
bg_dispatch
to control the ability of dispatch incoming commands; - use
bg_send_interval_ms
to control the interval of send outgoing commands( in millisecond); - use
bg_dispatch_interval_ms
to control the interval of dispatch incoming commands( in millisecond); - use
bg_send_single
to control whether send all cached outgoing commands or send single cached outgoing commond per send cycle( default false, if you modiy it, please make sure you know what you're doing); - use
bg_dispatch_single
to control whether dispatch all cached incoming commands or dispatch single cached incoming commond per dispatch cycle( default false, if you modiy it, please make sure you know what you're doing). - all
RealtimeClient
andChatClient
instances are useing the same background thread to manipulate, even if you game have multiple Clients instance.
- use
- I expose the methods
send_outgoing_commands()
anddispatch_incoming_commands()
fromPhotonPeer
. Please to learn how to use them if you need to control the timing of send and dispatch commonds flexibly. Commonly, if you don't want to use background thread system, just callservice()
regularly to process netcode.
Again, because of the lack of time, I can't do many test for this SDK. I hope everybody can participate in the development of this SDK. If you encounter bug, please try to fix it or improve it, then submit a pull request. In addition,I will be grateful if you try to fix bugs or make document.
- Make doc.
- Waiting for Godot 4.0's GDExtension to build GDScrip 2.0 SDK base on cpp.
To get the Photon C# Client SDK in Photon official websit, you must to sign up to download it. But I integrate it to this sdk, if this way may cause some legal issues,please notify me, I will remove C# SDK files and add description for how to integrate it manually.
=======================================================================
用于GDScript 的 Photon 客户端 SDK, 具体实现是将 C# SDK 的重要对象包装为Godot识别的对象给 GDScript 进行对接。包含光子实时客户端(Photon Realtime Client) 和 光子聊天客户端( Photon Chat Client) 。
由于时间不够,我无法在脚本和文档中做完善的描述,但是这个SDK的用法与光子C#客户端SDK类似,基本上你可以参考官方文档进行开发.
最重要的类在“addons\addons\PhotonGDScriptClientSDK\core”中,另外一些数据类和对象表示类在“addons\addons\PhotonGDScriptClientSDK\wraps”中
你必须使用 Godot 3.x mono.
- 像其他插件一样安装该插件;
- 为了生成
.csproj
文件,你必须至少构建一次你的项目. - 将C# SDK 的
.dll
包含到 C# project. - 启用该插件.
如果你不清楚如何包含C# SDK 的
.dll
,你可以把以下内容作为一个xml项目置于.cspro
中的Project
项目下:
调试用:
<ItemGroup>
<Reference Include="addons\PhotonGDScriptClientSDK\dependents\libs\Debug\netstandard2.0\Photon-NetStandard.dll" />
</ItemGroup>
发布用:
<ItemGroup>
<Reference Include="addons\PhotonGDScriptClientSDK\dependents\libs\Release\netstandard2.0\Photon-NetStandard.dll" />
</ItemGroup>
- C# SDK中的关键字
LoadingBalling
等同于GDScript SDK中的Realtime
(在C# SDK中使用LoadingBalling
的原因是为了兼容旧的实现,但现在是GDScript的新实现,所以我用GDScript SDK中直接使用Realtime
进行描述)。
2.你应该通过 Photon.<EnumName>.<EnumItemName>
来访问 Phton 的枚举。
-
C# SDK中的
Player
、Room
和RoomInfo
在 GDScript 中被重命名为PhotonPLayer
、PhotonRoom
和PhotonRoomInfo
。 -
你应该通过
<DataClassName>.Prefeb.<Default/PrefebName>
来访问数据类的预置对象, 等同于 C# SDK 的中的相关类的预置静态变量( 如 C# SDK 中的TypedLobby.Default
等同于 GDScript SDK 中的TypedLobby.Prefeb.Default
)。 -
C# SDK 的回调接口中的方法 和 客户端事件在GDScript SDK中实现如下:
-
可重写的方法(实时调用,用于扩展客户端情况);
-
信号(适用于任何在可重写方法之后调用);
-
组对象回调方法(默认情况下称为延迟调用,你可以通过设置
<RealtimeClient/ChatClient>.notify_when_idle = false
,以让它们被实时调用,但它们仍然在信号之后被调用)。
-
-
GDScript中,回调
web_rpc_responsed
的参数类型是WebrpResponse
, 不同于C# SDK(在C#中,它是OperationResponse
)。 -
你不能访问
PhotonPeer
(RealtimeClient
和ChatClient
的底层实现),常用情况下你不需要访问它。如果你有必要访问它,请提交issue来描述其必要性。 -
因为这个SDK是C# SDK的包装,为了尽量提高性能,我将
PhotonPeer.ReuseEventInstance
默认设置为true
。在 GDScript SDK 中你可以通过RealtimeClient.reuse_event_instance
和ChatClient.reuse_event_instance
来控制它。 -
与上一条相同的原因,从
RealtimeClient和ChatClient
获取到的类名为ErroInfo
、OperationResponse
和WebRPResponse
的实例总是同一个对象, 即使是从不同的客户端实例对象中获取,同样的数据类型总是同一个对象。如果你需要缓存其中的信息,请在每次获取时提取这些信息。 -
我没有将属性
ChatClient.UseBackgroundWorkerForSending
暴露给 GDSctipt SDK。我实现了一个后台线程系统来取代它, 用于RealtimeClient
和ChatClient
在后台线程中发送传出命令和调度传入命令:-
使用
bg_send
控制是否通过后台线程发送传出命令; -
使用
bg_dispatch
控制是否通过后台线程调度传入命令; -
使用
bg_send_interval_ms
控制发送传出命令的间隔(毫秒); -
使用
bg_dispatch_interval_ms
控制调度传入命令的间隔(毫秒); -
使用
bg_send_single
来控制是一次性发送所有被缓存的传出命令,还是每个发送周期发送单个被缓存的传出命令(默认为false
,如果你修改了它,请确保你知道自己在做什么); -
使用
bg_dispatch_single
控制是一次性调度所有被缓存的传入命令,还是每个调度周期调度单个被缓存的传入命令(默认为false
,如果你修改它,请确保你知道自己在做什么)。 -
所有的
RealtimeClient
和ChatClient
实例在你应用中公用一个后台线程。
-
-
我将
send_outgoing_commands()
和dispatch_incoming_commands()
从PhotonPeer
中暴露给 GDScript SDK 中的RealtimeClient
和ChatClient
,以让你灵活控制 发送 和 调度 的时机,但你必须学会如何准确的使用它们以避免错误。通常情况下,如果你不希望通过后台线程来发送和调度命令,只需要以你的方式有规律的频繁调用RealtimeClient.service()
和ChatClient.service()
即可。
同样,由于时间不够,我不能为这个SDK做很多测试。我希望大家都能参与这个SDK的开发。如果遇到错误,请尝试修复或改进,然后提交请求。
此外,如果你尝试修复错误或制作文档,我将不胜感激。
1.完善文档。
2.等待Godot 4.0的GDExtension,在cpp基础上构建GDScrip 2.0 SDK。
要在光子官方网站上获得光子C#Client SDK,你必须注册登录并下载。但我将其集成到这个sdk中,如果这种方式可能会引起一些法律问题,请通知我,我将删除C# sdk相关文件,并添加如何手动集成的说明。