Skip to main content

HandyCameraManager

A class in Root.Township, Alta.ScreenshotCamera.

Spawns and despawns each player's hand camera (the summoned screenshot camera), despawns it when the player walks too far away, and runs the streaming output. One scene instance, used through static methods; the server owns the cameras.

Constructors​

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

Fields​

14 private and internal fields
MemberWhat it is
private NetworkPrefab cameraPrefabThe hand camera prefab that gets spawned.
private float distanceFromPlayerHow far in front of the player's head the camera spawns, in metres.
private static HandyCameraManager instanceThe scene's manager, set in Awake.
private float maxDistanceFromPlayerSquaredSquared distance from the head beyond which the camera counts as out of range (default 9, so 3 m).
private PositionEvent onCameraDisappearEffectsEffects played where a camera disappears.
private PositionEvent onCameraSpawnEffectsEffects played where a camera spawns.
private float outOfRangeHapticHaptic strength used to warn the player that the camera is out of range.
private Dictionary<IPlayer, HandyCameraManager.PlayerCameraHandler> playersCamerasServer: each player's live camera handler.
private IUnityUpdateMethod remoteDistanceCheckClient: the registered range check update for the local player's camera, or null.
private MethodSyncStruct<bool> requestSyncMessage a client sends to ask the server to spawn or remove its camera.
private HandCameraStreamer streamerThe streamer instance, created on first StartStreaming.
private HandCameraStreamer streamerPrefabPrefab for the HandCameraStreamer.
private MethodSyncStruct<HandyCameraManager.EffectArguments> syncEffectsMessage the server sends to play spawn and disappear effects.
private float timeToDespawnSeconds a camera may stay out of range before the server removes it.

Methods​

MemberWhat it is
override void Initialize()Sets up the spawn request and effect messages.
override void InitializeAsServer(SpawnData spawnData)Server: creates the player to camera table.
static void StartStreaming(RenderTexture renderTexture)Creates the streamer from its prefab if needed and starts streaming the given render texture.
static void StopStreaming()Stops the streamer if one exists.
static void UpdateCameraStatusForLocalPlayer()Toggles the local player's camera: spawns it if they have none, otherwise removes it. Asks the server when called on a client.
6 private and internal methods
MemberWhat it is
private void Awake()Stores this as the static instance.
private void DestroyPlayersCamera(IPlayer player)Server: removes the player's camera handler, plays the disappear effect on clients and fades the camera out.
private void RemoteDistanceCheck()Client (non-host): buzzes both controllers each frame while the local player's camera is out of range.
private void RequestSync(IPlayer player, Stream stream, bool isSpawnRequest)Message handler. On the server, spawns or destroys the sending player's camera depending on the received flag.
private void SpawnCameraForPlayer(IPlayer player)Server: spawns a camera in front of the player's head (unsaved, owned by the player), fades it in and plays the spawn effect.
private void SyncEffects(IPlayer player, Stream stream, HandyCameraManager.EffectArguments arguments)Message handler. Client: plays the spawn or disappear effect at a position, and starts or stops the range check for the local player's camera.