PhotonCustomPropsUtils
Helps modders easily synchronize room/player properties across all connected clients through Photon's Custom Properties.
模組介紹 作者原文
Photon Custom Props Utils
Helps modders easily synchronize room/player properties across all connected clients.
Utilizes Photon RoomProperties and PlayerProperties to make it easier to synchronize properties for all players.
To Modders
The best way to reach me is through the Photon Custom Props Utils thread on the Peak modding discord server.
Peak Modding Discord Server
Guide
First add this mod dll as a project reference for your mod. Then you can add a dependency to the mod to ensure your mod runs after PhotonCustomPropsUtils.
[BepInDependency("com.snosz.photoncustompropsutils", BepInDependency.DependencyFlags.HardDependency)]
Or if you dont want to set a dependancy you can just check for IsReady and listen for OnReady.
if (PhotonCustomPropsUtilsPlugin.IsReady)
DoPhotonStuff();
else
PhotonCustomPropsUtilsPlugin.OnReady += DoPhotonStuff;
Then you can create your scoped CustomPropsManager by passing your plugin GUID like so:
manager = PhotonCustomPropsUtilsPlugin.GetManager("com.author.modname");
This ensures that any properties you listen to are specific to your mod which helps avoid naming conflicts where multiple mods might have similar property names.
To start listening for a property change you can use either RegisterRoomProperty, or RegisterPlayerProperty. You can also set the event type, depending on if its a player or room event you can use RoomEventType.All (for both OnJoinedRoom, and OnRoomPropertyChanged) or either one seperately if you want to handle that logic seperately.
PlayerEventType is similar and can be PlayerEventType.All, OnPlayerPropertyChanged, and OnJoinedRoom.
For easy usage you can specify the expected type to be received which means you dont have to worry about casting it yourself.
// This will be called for either OnJoinedRoom (which runs for the local player), or OnRoomPropertyChanged.
manager.RegisterRoomProperty("myValue", RoomEventType.All, value =>
{
storedValue = value; //This is where you handle what to do with the updated property
});
// This will be called for OnPlayerPropertyChanged.
manager.RegisterPlayerProperty("myValue", PlayerEventType.OnPlayerPropertyChanged, (targetPlayer, value) =>
{
storedValue = value; //This is where you handle what to do with the updated property
});
To set a new value for a property you can just call SetRoomProperty
manager.SetRoomProperty("myValue", newValue);
To listen for when the local player has joined a room:
manager.RegisterOnJoinedRoom(localPlayer =>
{
// Do thing
});
To get all player properties, or all players with a specific property:
var allPlayersProperties = manager.GetAllPlayerProperties("targetProperty");
Please note that this should not be used in excess such as setting a property every frame. It should be only done in response to client behaviour such as pushing a button.
For further reading about Photon custom properties, the official Photon docs have both information on how it can be used, and the allowed types that are supported.
安裝與使用 安裝:BepInEx 外掛
- 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
- 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
- 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
- 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。
帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。
下面這些內容需要先安裝,否則該模組不會生效: