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.
- Listed in Customization and screenshots
- Inherits or implements
NetworkEntityBehaviour,IBuildRendererBakeable,IBuildBakeable
Constructors
| Member | What it is |
|---|---|
HandCamera() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
46 private and internal fields
| Member | What it is |
|---|---|
private static readonly int _Emission | Shader property ID for _Emission, used on the marker. |
private static readonly int _MainTex | Shader property ID for _MainTex, used on the viewfinder. |
private static readonly int _Progress | Shader property ID for _Progress. |
private int androidFarClipPlane | Far clip distance for the cameras on Android builds. |
private Renderer captureAlert | Renderer flashed when a photo is taken; turns red if saving failed. |
private HandCameraEvent currentEvent | What the camera is rendering for (idle or photo), passed to the render events. |
private int currentTimer | Index of the selected self-timer option. |
private static Material darkFadeMaterial | Shared material that darkens the viewfinder when the lens is blocked. |
private BlockableCamera frontCamera | The forward-facing camera. |
private Pickup[] handles | Backing field for Handles; only the owner can grab them. |
private bool isCameraLocked | True while a photo is being taken, so visibility changes don't turn rendering on. |
private bool isForcingHighRes | When set, the viewfinder renders at the streaming resolution. |
private bool isTakingPicture | True during a photo, its timer and review. |
private LocalPlayerHeadRenderer localPlayerHandler | Handles showing the local player's head in the camera's view. |
private static readonly Logger logger | NLog logger for this class. |
private Dictionary<PlayerInput, Coroutine> longHaptics | Running long-press haptic coroutine per hand. |
private Renderer marker | The light that blinks for the timer and photo. |
private Material markerMaterial | Instance of the marker's material whose emission is animated. |
private RendererMaterializer materializer | Fades the camera's renderers in and out. |
private static HandCamera nonOwnedRenderingCamera | The one other player's camera this client renders, if any. |
private TransformEvent onPhotoTakenEffects | Effects played when a photo is taken. |
private TransformEvent onTimerMarkEffects | Effects played on each timer tick. |
private int owner | Player identifier of the camera's owner. |
private RemoteObiturator remoteObiturator | Serialized reference not used in this class. |
private RendererGroup renderersToMaterialize | Renderers faded by materializer. |
private RenderTexture renderTexture | Render texture the cameras draw the viewfinder image into. |
private Screenshot screenshot | Helper that captures and saves photos. |
private const int ScreenShotHeight | Base photo height (1080) before the resolution scale setting. |
private const int ScreenShotWidth | Base photo width (1920) before the resolution scale setting. |
private BlockableCamera selfieCamera | The backward-facing camera. |
private HandCameraSettings settings | Timer options, colours and durations for this camera. |
private MethodSyncStruct<bool> syncEffect | Message carrying fade in or out. |
private MethodSync syncOwner | Message carrying the owner. |
private MethodSync syncPhoto | Message sent when a photo is taken. |
private MethodSync syncSelfie | Message carrying the selfie state. |
private MethodSync syncStreaming | Message carrying the streaming state. |
private Canvas timerCanvas | Canvas showing the self-timer count. |
private Text timerText | Text showing the seconds left. |
private Renderer viewFinder | Renderer showing the camera image. |
private const int ViewFinderHeight | Base viewfinder height (1080). |
private GameObject viewfinderObject | Viewfinder object hidden while fading. |
private HandCameraViewfinderResizerSettings viewfinderResizerSettings | Lets the owner resize the viewfinder. |
private const int ViewFinderWidth | Base viewfinder width (1920). |
private VisibilityTrigger visibilityTrigger | Reports when the viewfinder is visible, to save rendering. |
private PostProcessVolume volume | Post-process volume; ambient occlusion is turned off for the photo on Windows. |
private TaskCompletionSource<bool> waitForEvent | Completes when the next pre-render happens during a photo. |
Properties
| Member | What 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
Events
| Member | What it is |
|---|---|
event Action<Player> OnConnectedCalled | Raised after OnConnected for a player. |
static event HandCameraRender onPostRender | Static event after either camera renders. |
static event HandCameraRender onPreRender | Static event before either camera renders, with the reason (for example a photo). UI uses it to hide things. |
event Action<HandCamera> OnUpdatedSettings | Raised when timer, streaming or resolution settings change. |
event Action<bool> OwnerUpdated | Raised when the owner is set, with whether it is the local player. |
event Action PhotoStart | Raised when a long press to take a photo begins. |
event Action<bool> SelfieModeChanged | Raised when selfie mode turns on or off. |
Methods
| Member | What 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
| Member | What 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:
DockVisual.PostCameraRender, DockVisual.PreCameraRender, ButtonGroup.baseCamera, CameraButton.handCamera, CameraButton.UpdateSettings, CameraEventsListener.Post, CameraEventsListener.Pre, CameraFilters.handCamera, CameraStabilization.handCamera, Filter.Initialize, Filter.Terminate, FilterAction.Initialize, FilterAction.Terminate, FiltersButton.handCamera, FocusButton.UpdateSettings, FocusPuller.baseCamera, FocusPuller.FinishedRender, FocusPuller.PrepareToRender, HandCameraRender.BeginInvoke, HandCameraRender.Invoke, HandyCameraManager.PlayerCameraHandler.Camera, HandyCameraManager.PlayerCameraHandler.PlayerCameraHandler, LocalPlayerHeadRenderer.OnPostRender, LocalPlayerHeadRenderer.OnPreCull, OnDrawFilter.Initialize, OnDrawFilter.PostRender, OnDrawFilter.PreRender, OnDrawFilter.renderingCameras, OnDrawFilter.Terminate, OpticalZoom.PostRender, OpticalZoom.PreRender, PlayerSwapMaterialFilter.PreRender, PlayerSwapMaterialFilter.Terminate, PostProcessFilter.Initialize, PostProcessFilter.Terminate, RemoteObiturator.handCamera, RemoteObiturator.OnTakingPhoto, RemoteObiturator.OnTookPhoto, StreamingButton.UpdateSettings, TimerButton.UpdateSettings, TouchScreenMenu.handCamera, TouchScreenMenu.PostRenderEnableButtons, TouchScreenMenu.PreRenderDisableButtons, StatBarBase.OnTakingPhoto, StatBarBase.OnTookPhoto, Screenshot.Camera, Screenshot.Screenshot.