-
-
Notifications
You must be signed in to change notification settings - Fork 621
Helpful Functions Cheatsheet
This is a complicated codebase and it can be difficult for developers to how to check something or get a reference to what they need. This is a cheat sheet of common functions to help you quickly find what you need so you don't waste a lot of time looking or reimplementing something that already exists. This is not intended to be a complete list of functions, but just the most commonly used ones. Please expand it or modify it as you see fit.
To write to the debug log:
Logger.Log(string msg, Enum Category)To set the log level for different categories, go to unitystation/UnityProject/Assets/Scripts/Debug/Logger.cs, and modify
private static readonly Dictionary<Category, Level> LogOverrides = new Dictionary<Category, Level>{
[Category.Unknown] = Level.Info,
[Category.Movement] = Level.Error,
[Category.Health] = Level.Trace, to your liking.
Get player info by gameObject (serverside only)
ConnectedPlayer player = PlayerList.Instance.Get(gameObject);
if (player != ConnectedPlayer.Invalid) {
//Do your thing. If gameObject is not found in PlayerList, ConnectedPlayer.Invalid is returned
}Check if player has spawned
bool playerSpawned = (PlayerManager.LocalPlayer != null);Check if local player is dead
PlayerManager.LocalPlayerScript.playerHealth.IsDeadCheck if local player is in critical health
PlayerManager.LocalPlayerScript.playerHealth.IsCritfunctions related to items the player has equipped
PlayerManager.EquipmentFunctions related to player taking actions with the server
PlayerManager.LocalPlayerScript.NetworkActionsCheck if this is the server, but only inside a NetworkBehaviour
if(isServer)Check if this is the server
CustomNetworkManager.Instance._isServer == falseGet the room number of a tile (only enclosed spaces will be defined as a room. RoomNumber will = -1 if it is not a room)
MatrixManager.GetMetaDataAt(Vector3Int.RoundToInt(world_position)).RoomNumberThe Assets\Scripts\Util folder also contains a bunch of useful scripts to help deal with common problems. Have a look through there and you might find something useful!
Please join us on Discord: https://discord.gg/tFcTpBp