Skip to main content

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.

Constructors​

MemberWhat it is
CaveTeleporter()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
protected CaveTeleportConnection currentConnectionThe connection between this layer and the target layer.
protected int layerThe cave layer this teleporter is on (0 is the surface). -1 until worked out.
protected static Logger loggerThe class's NLog logger.
8 private and internal fields
MemberWhat it is
private TextRenderer costRendererText showing the fuel cost to teleport from here. Not set on a headless server.
private PickupDock fuelDockDock holding the teleporter's fuel. Optional; without it teleporting costs nothing here.
private Interactable handTriggerThe interactable players touch to teleport.
private bool isValidTeleportWhether the current connection is usable.
private BoolEvent IsValidTeleportChangedInspector event raised with true or false when the connection becomes usable or not.
private MethodSync syncLayerMethod sync that sends the layer to clients.
private readonly HashSet<IPlayer> teleportingPlayers whose teleport is in progress, so a second touch does nothing.
private Transform teleportToTargetTransform marking where players arrive when teleporting to this teleporter's layer.

Properties​

MemberWhat it is
int QuantityStored { get; }Fuel in the dock, or 0 if there is no dock.
virtual int TargetLayer { get; }Layer this teleporter sends players to. 0 (the surface) unless overridden.
Vector3 TeleportToTarget { get; }World position players arrive at when teleported to this teleporter.

Events​

MemberWhat it is
event Action QuantityChangedRaised when the amount of fuel in the dock changes.

Methods​

MemberWhat 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
MemberWhat 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: