CaveTeleporter
A class in Root.Township, Alta.Caves.
A fuelled teleporter in the caves that sends a player to another layer (the surface by default) through CaveTeleporterManager. Its layer is saved and synced; the teleport runs on the server.
- Listed in World generation
- Inherits or implements
NetworkEntityBehaviour,ISavable<CaveTeleporterData>,ISavableSave<CaveTeleporterData>,ISavableSaveBase - Derived types
CaveTeleporterData,LevelSelectCaveTeleporter
Constructors
| Member | What it is |
|---|---|
CaveTeleporter() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected CaveTeleportConnection currentConnection | The connection between this layer and the target layer. |
protected int layer | The cave layer this teleporter is on (0 is the surface). -1 until worked out. |
protected static Logger logger | The class's NLog logger. |
8 private and internal fields
| Member | What it is |
|---|---|
private TextRenderer costRenderer | Text showing the fuel cost to teleport from here. Not set on a headless server. |
private PickupDock fuelDock | Dock holding the teleporter's fuel. Optional; without it teleporting costs nothing here. |
private Interactable handTrigger | The interactable players touch to teleport. |
private bool isValidTeleport | Whether the current connection is usable. |
private BoolEvent IsValidTeleportChanged | Inspector event raised with true or false when the connection becomes usable or not. |
private MethodSync syncLayer | Method sync that sends the layer to clients. |
private readonly HashSet<IPlayer> teleporting | Players whose teleport is in progress, so a second touch does nothing. |
private Transform teleportToTarget | Transform marking where players arrive when teleporting to this teleporter's layer. |
Properties
Events
| Member | What it is |
|---|---|
event Action QuantityChanged | Raised when the amount of fuel in the dock changes. |
Methods
| Member | What it is |
|---|---|
void AddAmount(int fuelQuantity) | Spawns fuel and docks the given quantity into the fuel dock. |
void DestroyAmount(int amount) | Removes fuel from the dock. |
override void Initialize() | Blocks hand interaction while the connection is invalid and sets up the layer sync. |
override void InitializeAsServer(SpawnData spawnData) | Server: next frame, works out the layer and registers with the teleporter manager. |
override void OnConnected(Player player) | Server: sends the layer to a joining player. |
void Teleport(IPlayer player) | Server: if there is enough fuel, takes it, uses fuel at the other end and moves the player to the target layer. |
void UpdateLayerExternal() | Works out the layer again and re-registers. For callers outside the class. |
protected virtual void InitializeConnection() | Gets the connection from this layer to TargetLayer from the manager. |
protected void UpdateConnection(CaveTeleportConnection connection) | Switches to a connection, updates validity and shows its cost. |
7 private and internal methods
| Member | What it is |
|---|---|
private void AllowInteract(IPlayer player) | Lets the player use the teleporter again once their teleport has finished. |
private void Awake() | Hooks the fuel dock's quantity change to this teleporter's QuantityChanged event. |
private void ConnectionValidChanged(bool isValid) | Updates whether the teleport is usable and raises IsValidTeleportChanged when that changes. |
private void HandFilter(Interactor interactor, Interactable interactable, ref bool result) | Interaction filter on the hand trigger: blocks use while there is no valid connection. |
private void OnQuantityChanged() | Raises QuantityChanged when the fuel dock's amount changes. |
private void SyncLayer(IPlayer player, Stream stream) | Network sync of the teleporter's layer. Clients set up their connection once they receive it. |
private void UpdateLayer() | Server: works out the layer from the chunk's CaveLayerStreamer if unset (0 if none), registers with CaveTeleporterManager and syncs the layer. |
Used in
Members of other types that take, return or hold a CaveTeleporter: