Coming from Bolt
簡介
本文將描述 Photon Bolt 和Photon Fusion 在API方面的主要區別,以及如何將Bolt編寫遊戲的部分移植到Fusion項目中。
Bolt和Fusion有很多共同的概念,但用法、API和主要一般使用行為是不同的。
差異之處
以下列出Photon Bolt和Photon Fusion之間的主要區別:
在Bolt,一般的API可以通過靜態類
BoltNetwork和BoltMatchmaking來訪問,而在Fusion,則通過NetworkRunner的事件來完成。Fusion可以在同一個執行文件中運行多個對象,而Bolt只能單一運行。這意味著有可能從遊戲的同一個事件中運行多個客戶端。這對於測試和除錯是很有用的。
雖然兩個解決方案都支持
Client-Server架構,但Fusion也支持Shared Mode,這與PUN的工作方式更相似。另外,Fusion同時支持Delta Snapshots和Eventual Consistency,相比之下,Bolt只支持後者。Fusion通過使用內置的
NetworkRigidbody和NetworkRigidbody2D組件完全支持物理預測和回報,而在Bolt上,這需要由開發者處理/執行。在處理角色控制器時也是如此,Fusion有NetworkCharacterController,可以作為基本執行來移動玩家的角色,而在Bolt,這也需要自定義執行。
相似之處
這裡列出了Photon Bolt和Photon Fusion之間的主要相似之處:
Fusion有
NetworkObject的概念,代表Unity的Game Object,它有網路屬性,用於在對象之間同步數據,Bolt也有同樣的概念,名字是BoltEntity。NetworkObject的狀態可以在任何NetworkBehaviour上使用Networked屬性來描述,為了在Bolt上這樣做,有必要使用Bolt Assets窗口創建/編輯State資產來創建和配置屬性。更多訊息.所有主要的SDK事件(啟動、關閉、中斷等),在Bolt中使用
GlobalEventListener事件進行處理,Fusion通過執行與NetworkRunner相關的INetworkRunnerCallbacks來公開這類事件。兩個SDK都有
State Authority和Input Authority的概念,雖然在Bolt上被稱為Ownership和Control,但它們的含義完全相同。更多訊息.Fusion也是一個預測-回報系統,與Bolt類似。在Bolt中,
BoltEntity的Controller會發送Command,而在Fusion中,這是由對NetworkObject有Input Authority的對象發送NetworkInput完成的,但與Bolt不同的是,在Bolt中,回報(狀態重置)是手動完成的(在ExecuteCommand中,resetState=true),在Fusion中,在調用FixedUpdateNetwork方法之前,會在新框架的開始自動完成。對於每個受控的
BoltEntity,Bolt在與Entity相關的EntityEventListener上調用SimulateController方法。這在Fusion上是不同的,因為沒有多個NetworkInput的來源(Bolt上的Command),而且對於所有NetworkObject,只有一個NetworkInput可以與特定的框架相關。這是通過執行INetworkRunnerCallbacks.OnInput回調來執行的。更多訊息.Fusion上著名的遠程過程調用(
RPCs)在Bolt上被稱為Events。它們有非常相似的控制(誰可以發送,誰可以接收,以及可靠性),但是在Fusion上可以直接通過代碼定義,而在Bolt上則需要使用Bolt Assets窗口進行設置。更多訊息.Fusion有很多內置的組件可以幫助普通類型的數據同步,其中一個例子是
NetworkTransform,它可以被映射到Bolt的Transform Property。兩者都用於同步Game Object的位置和旋轉,同時提供快照之間的平滑過渡,能夠在數據點之間進行插值。更多訊息.Fusion也能夠使用
Area of InterestAPI只同步所需的NetworkObject集合。更多訊息.在這兩個SDK上都有一個
Scene Object的概念,它是一個預先創建的NetworkObject,與一個場景相關。當該特定場景被下載時,這些對象會自動附加到模擬中。在這兩個SDK上執行的另一個解決方案是
Lag Compensated Physics Checks,主要用於檢測考慮到發送者和目標之間的滯留造成的Raycast的衝突。更多訊息.
參考表
| Bolt | Fusion | Description |
|---|---|---|
| BoltNetwork, BoltMatchmaking | NetworkRunner | Main API entrypoint |
| BoltEntity | NetworkObject | Represents a Networked Game Object |
| BoltEntity State Properties | Networked Properties | Set of synchronized properties |
| GlobalEventListener | INetworkRunnerCallbacks | General Event handling |
| EntityEventListener | NetworkBehaviour, SimulationBehaviour | Networked Game Object Event handling |
| BoltNetwork.Instantiate() | NetworkRunner.Spawn() | Creates a new Networked Game Object |
| BoltNetwork.Destroy() | NetworkRunner.Despawn() | Removes a Networked Game Object from the simulation |
| BoltEntity.IsOwner | NetworkObject.HasStateAuthority | Signal if the peer can modify the State of a Networked Game Object |
| BoltEntity.HasControl | NetworkObject.HasInputAuthority | Signal if the peer that can push inputs to a Networked Game Object |
| Commands | NetworkInput | Control Structure used to predict on Client and alter the State on the Server |
| Objects | NetworkStructs | Reusable data structures that contain Networked Properties and can be used in more than one State |
| Events | RPC | Communication method used to transfer pieces of information that does not need to be part of the simulation |
| Transform Property | NetworkTransform | Built-in support to synchronize the Transform (position and rotation) of a Networked Game Object |
| BoltNetwork.LoadScene | NetworkSceneManager | API for switching/loading scenes in a synchronized manner |