SyncLib

版本 v1.1.0·更新於 2026-05-23

REPO 聯機同步通用庫。封裝 RPC、RaiseEvent、房間屬性、快照補發和動態配置同步,爲模組開發提供開箱即用的網絡層。

模組介紹 作者原文

SyncLib - 聯機同步庫

爲 REPO 模組開發提供開箱即用的網絡同步能力。封裝 Photon RPC、RaiseEvent、房間屬性同步、快照補發與動態配置同步。

版本:1.1.0

⚠️ 免責聲明 / Disclaimer

本庫爲個人項目輔助工具,按“現狀 (AS IS)”提供,不提供任何形式的明示或暗示擔保,包括但不限於對適銷性、特定用途適用性或不侵權的擔保。作者不保證代碼無缺陷、無中斷或無錯誤。因使用本庫產生的任何直接、間接或附帶損失,作者不承擔責任。功能可能根據作者自身需求隨時變更。

This library is a personal development utility provided "AS IS" without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. The author makes no guarantee that the code is defect-free, uninterrupted, or error-free. The author shall not be liable for any direct, indirect, or consequential damages arising from the use of this library. Features may change at any time based on the author's needs.

✨ 功能

| 分類 | 功能 | 說明 |

|------|------|------|

| RPC | 廣播 / 緩衝廣播 / 點對點 / 請求房主 | 封裝四種常用 RPC 模式,自動檢查權限 |

| RaiseEvent | 事件廣播 / 請求-響應 | 無需 PhotonView 的輕量通信 |

| 房間屬性 | 設置 / 讀取 | 鍵值對存儲,適合全局配置 |

| 快照補發 | 自動捕獲 / 主動請求 | 新玩家加入時自動補發當前狀態 |

| 動態配置 | 註冊 / 房主同步 / 快照序列化 | 配置變更自動推送給所有客機 |

安裝

  • 依賴 BepInExPack
  • 將 SyncLib.dll 放入 BepInEx/plugins/SyncLib/
  • 在你的模組項目中引用 SyncLib.dll
  • 在模組的 manifest.json 中添加依賴:"cn_xc-SyncLib-1.1.0"

⚙️ 快速開始

using cn_xc.SyncLib;

// 1. 初始化(自動掛載到 PunManager,跨場景不銷燬)

var relay = SyncRelay.Instance;

// 2. RPC 廣播

SyncRelay.RegisterRpc("OnSomethingChanged");

relay.Broadcast("OnSomethingChanged", arg1, arg2);

// 3. 房間屬性

SyncRelay.SetRoomProperty("MyModSetting", 5);

int val = SyncRelay.GetRoomProperty("MyModSetting", 1);

// 4. 動態配置(房主改,自動同步)

SyncRelay.RegisterSyncedConfig("TokenMultiplier", "10", (key, val) => {

MyMod.UpdateMultiplier(int.Parse(val));

});

SyncRelay.SetSyncedConfig("TokenMultiplier", "20");

// 5. 快照補發(新玩家加入自動補狀態)

SyncRelay.EnableSnapshotSync(

snapshotProvider: () => {

return JsonUtility.ToJson(myState);

},

snapshotApplier: (snapshot) => {

myState = JsonUtility.FromJson(snapshot);

}

);

// 6. 新玩家加入回調

SyncRelay.RegisterOnPlayerJoinedCallback(player => {

// 自定義補發邏輯

});

安裝與使用 安裝:BepInEx 外掛

  1. 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
  2. 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
  3. 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
  4. 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。

帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。

前置依賴

下面這些內容需要先安裝,否則該模組不會生效:

BepInEx-BepInExPack

檔案與校驗

檔案名稱
SyncLib-1.1.0.zip
檔案大小
94.8 KiB