Skip to main content

HandCamera

A class in Root.Township, Alta.ScreenshotCamera.

The handheld photo camera a player spawns from the quick access menu. Only its owner can pick it up; photos, selfie mode and streaming sync to others. Never saved. HandCamera.Current is the local player's.

Constructors​

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

Fields​

46 private and internal fields
MemberWhat it is
private static readonly int _EmissionShader property ID for _Emission, used on the marker.
private static readonly int _MainTexShader property ID for _MainTex, used on the viewfinder.
private static readonly int _ProgressShader property ID for _Progress.
private int androidFarClipPlaneFar clip distance for the cameras on Android builds.
private Renderer captureAlertRenderer flashed when a photo is taken; turns red if saving failed.
private HandCameraEvent currentEventWhat the camera is rendering for (idle or photo), passed to the render events.
private int currentTimerIndex of the selected self-timer option.
private static Material darkFadeMaterialShared material that darkens the viewfinder when the lens is blocked.
private BlockableCamera frontCameraThe forward-facing camera.
private Pickup[] handlesBacking field for Handles; only the owner can grab them.
private bool isCameraLockedTrue while a photo is being taken, so visibility changes don't turn rendering on.
private bool isForcingHighResWhen set, the viewfinder renders at the streaming resolution.
private bool isTakingPictureTrue during a photo, its timer and review.
private LocalPlayerHeadRenderer localPlayerHandlerHandles showing the local player's head in the camera's view.
private static readonly Logger loggerNLog logger for this class.
private Dictionary<PlayerInput, Coroutine> longHapticsRunning long-press haptic coroutine per hand.
private Renderer markerThe light that blinks for the timer and photo.
private Material markerMaterialInstance of the marker's material whose emission is animated.
private RendererMaterializer materializerFades the camera's renderers in and out.
private static HandCamera nonOwnedRenderingCameraThe one other player's camera this client renders, if any.
private TransformEvent onPhotoTakenEffectsEffects played when a photo is taken.
private TransformEvent onTimerMarkEffectsEffects played on each timer tick.
private int ownerPlayer identifier of the camera's owner.
private RemoteObiturator remoteObituratorSerialized reference not used in this class.
private RendererGroup renderersToMaterializeRenderers faded by materializer.
private RenderTexture renderTextureRender texture the cameras draw the viewfinder image into.
private Screenshot screenshotHelper that captures and saves photos.
private const int ScreenShotHeightBase photo height (1080) before the resolution scale setting.
private const int ScreenShotWidthBase photo width (1920) before the resolution scale setting.
private BlockableCamera selfieCameraThe backward-facing camera.
private HandCameraSettings settingsTimer options, colours and durations for this camera.
private MethodSyncStruct<bool> syncEffectMessage carrying fade in or out.
private MethodSync syncOwnerMessage carrying the owner.
private MethodSync syncPhotoMessage sent when a photo is taken.
private MethodSync syncSelfieMessage carrying the selfie state.
private MethodSync syncStreamingMessage carrying the streaming state.
private Canvas timerCanvasCanvas showing the self-timer count.
private Text timerTextText showing the seconds left.
private Renderer viewFinderRenderer showing the camera image.
private const int ViewFinderHeightBase viewfinder height (1080).
private GameObject viewfinderObjectViewfinder object hidden while fading.
private HandCameraViewfinderResizerSettings viewfinderResizerSettingsLets the owner resize the viewfinder.
private const int ViewFinderWidthBase viewfinder width (1920).
private VisibilityTrigger visibilityTriggerReports when the viewfinder is visible, to save rendering.
private PostProcessVolume volumePost-process volume; ambient occlusion is turned off for the photo on Windows.
private TaskCompletionSource<bool> waitForEventCompletes when the next pre-render happens during a photo.

Properties​

MemberWhat it is
BlockableCamera ActiveCamera { get; }The front camera, or the selfie camera when selfie mode is on.
static HandCamera Current { get; private set; }Static: the camera owned by the local player, or null.
int CurrentTimer { get; }Seconds of the selected photo timer.
IEnumerable<Pickup> Handles { get; }The pickups the camera is held by.
bool IsLocalPlayer { get; private set; }True if the local player owns this camera.
bool IsScreenFree { get; }False while a photo is being taken.
bool IsStreaming { get; private set; }True while the camera feed is being streamed out.
bool IsUsingSelfieCamera { get; private set; }True in selfie mode.
1 private and internal property
MemberWhat it is
private int IBuildRendererBakeable.SortingOrder { get; }Bake order (10).

Events​

MemberWhat it is
event Action<Player> OnConnectedCalledRaised after OnConnected for a player.
static event HandCameraRender onPostRenderStatic event after either camera renders.
static event HandCameraRender onPreRenderStatic event before either camera renders, with the reason (for example a photo). UI uses it to hide things.
event Action<HandCamera> OnUpdatedSettingsRaised when timer, streaming or resolution settings change.
event Action<bool> OwnerUpdatedRaised when the owner is set, with whether it is the local player.
event Action PhotoStartRaised when a long press to take a photo begins.
event Action<bool> SelfieModeChangedRaised when selfie mode turns on or off.

Methods​

MemberWhat it is
void ChangeTimer()Client: cycles to the next photo timer option.
void EndHaptics(PlayerInput playerInput)Stops the long-press vibration for a hand.
void Fade(bool isFadingIn)Fades the camera in or out. Server: sends it to clients, and fading out destroys the camera afterwards.
void FlipCamera()Switches between front and selfie camera and syncs it.
override void Initialize()Sets up sync messages and marks the handles as not saved.
void InteractionFilter(Interactor interactor, Interactable interactable, ref bool result)Blocks anyone but the owner from grabbing the handles.
bool IsInteractorOwner(Interactor interactor)True if the hand belongs to the camera's owner.
override void OnConnected(Player player)Sends the owner and selfie state to a newly connected player.
void Screenshot(PlayerInput playerInput)Input handler for the photo button: stops the haptics and takes a photo.
void SetForcedHighRes(bool isforced)Forces the high resolution render texture even when not streaming.
void SetupOwner(IPlayer player)Server: sets which player owns the camera and syncs it. Called when the camera is spawned for a player.
void StartHaptics(PlayerInput playerInput)Starts a light vibration on a hand while the photo button is held.
void TakeScreenshot()Takes a photo (after the timer) and tells others so they see it too.
void ToggleStreaming()Turns streaming of the camera feed on or off and syncs it.
33 private and internal methods
MemberWhat it is
private void AddLocalPlayer(PlayerController playerController)Client: registers the local player's head renderer handling when the local player is set, or releases it when cleared.
private IEnumerator AnimateMarker(Color color, bool hasEffectss = false, int blips = 1) (iterator)Coroutine: lights the marker in a colour, blinking for timer ticks, then turns it off.
private void Awake()Client: sets up the marker, viewfinder visibility trigger, handle hooks, settings and render events. Also marks the camera as never saved.
private void IBuildRendererBakeable.Bake(bool isSaving)Build bake: on Android, sets the far clip plane and strips post processing layers.
private void IBuildRendererBakeable.Clean()Empty build-bake step.
private void ClearRenderTexture()Releases the viewfinder render texture and detaches it from both cameras.
private void FinishFadeIn()After fading in: shows the viewfinder, makes the handles grabbable and, for the owner, enables viewfinder resizing.
private void InternalFlipCamera(bool value)Switches between the front and selfie camera, mirrors the viewfinder for selfies and raises SelfieModeChanged.
private IEnumerator LongHaptic(PlayerInput playerInput) (iterator)Coroutine: buzzes the hand lightly every frame while the long photo button is held.
private void OnDestroy()Unhooks events, cleans materials, stops streaming if on and releases the head renderer handling.
private void OnDestroyedByScene(NetworkEntity entity, bool isUnload)Clears Current if it was this camera.
private void OnDisable()Releases the render texture and turns off the active camera.
private void OnEnable()Turns on the active camera and makes a render texture at the viewfinder (or forced high) resolution.
private void OnPostRender()Raises the static onPostRender event for this camera's render.
private void OnPreRender()Raises the static onPreRender event for this camera's render.
private async void RemoteScreenshot()Client: plays the timer, marker and capture effects for a photo another player took, without saving one.
private async Task RunTimer(int timer)Counts the self-timer down once a second on the timer canvas, blinking the marker.
private async void Screenshot()Input handler for the photo button: stops the haptics and takes a photo.
private void SetAntialiasing(bool isEnabled)Not on Android: sets both cameras' post-process antialiasing to the settings' mode or none.
private void SetupForLocalPlayerOwner()Client: marks the local player as owner and makes this the Current camera.
private void SetViewFinderTexture(Texture texture)Shows a texture on the viewfinder.
private void StartScreenshots(Interactable interactable, Interactor interactor)When the local player grabs a handle, hooks the take-photo action and the long photo button.
private void StopScreenshots(Interactable interactable, Interactor interactor)When the local player lets go, unhooks the photo inputs and stops the haptics.
private void SyncEffect(IPlayer player, Stream stream, bool isFadingIn)Serializes a fade in or out; clients run Fade.
private void SyncOwner(IPlayer player, Stream stream)Serializes the owner's player identifier plus the selfie state; a client that owns it sets itself up as owner.
private void SyncPhoto(IPlayer player, Stream stream)Serializes the timer index when a photo is taken; other clients play the remote effects and the server logs and relays it.
private void SyncSelfie(IPlayer player, Stream stream)Serializes whether the selfie camera is in use; the server relays it to the chunk.
private void SyncStreaming(IPlayer player, Stream stream)Serializes whether the camera is streaming; the server relays it to the chunk.
private void Update()Updates the active camera's blocked check and darkens the viewfinder image while blocked.
private void UpdatedSettings(Settings settings)Remakes the Screenshot helper at the photo resolution scale setting.
private void UpdateRenderTexture(float scale)Remakes the render texture at 1920 by 1080 times the scale and points both cameras and the viewfinder at it.
private void VisibilityUpdated(bool isVisible)Turns rendering on or off as the viewfinder becomes visible. For other players' cameras, only one renders at a time, and only if the setting allows it.
private void WaitForEvent(HandCamera renderingCamera, HandCameraEvent cameraEvent)One-shot pre-render hook that lets a pending photo continue on the next render.

Used in​

Members of other types that take, return or hold a HandCamera: