Table of Contents

Class EquipmentPreviewRenderer

Namespace
FishMMO.Client
Assembly
FishMMO.Client.dll
public sealed class EquipmentPreviewRenderer : IDisposable
Inheritance
EquipmentPreviewRenderer
Implements
Inherited Members

Fields

CameraDistance

How far in front of the character the camera sits, in metres.

public const float CameraDistance = 3

Field Value

float

Remarks

Matches the distance the character prefabs author for their equipment view camera, so the perspective's framing of a character that fills its bounds is unchanged by this class taking the camera over.

Properties

Camera

The camera being driven, or null. Exposed so callers can assert the handover.

public Camera Camera { get; }

Property Value

Camera

IsReady

Whether there is a camera and a texture, so a render can be submitted.

public bool IsReady { get; }

Property Value

bool

LastIsolatedCount

How many renderers the last render isolated. Exposed so a test can see the swap happened.

public int LastIsolatedCount { get; }

Property Value

int

Texture

The texture the panel should draw. Null until a render has been submitted.

public RenderTexture Texture { get; }

Property Value

RenderTexture

Methods

ComputeCameraLocalPosition(Bounds, float)

Where the camera sits, in its parent's space, to look at the centre of bounds from distance in front of it.

public static Vector3 ComputeCameraLocalPosition(Bounds bounds, float distance)

Parameters

bounds Bounds

The subject, in camera-parent space.

distance float

How far in front of the subject to sit, in metres.

Returns

Vector3

The local position to assign.

Remarks

Centring on the subject rather than on the character's origin is what makes a short race and a tall one both appear centred. The camera prefabs set their height through a RectTransform's anchoredPosition, which does nothing at all under a plain Transform parent — so the authored offset never applied and the camera sat at the character's feet.

ComputeOrthographicSize(Bounds, float)

The orthographic half-height that fits bounds in a viewport of aspect, with a little room around it.

public static float ComputeOrthographicSize(Bounds bounds, float aspect)

Parameters

bounds Bounds

The subject, in camera-parent space.

aspect float

Viewport width divided by height.

Returns

float

The orthographic size to assign.

Remarks

An orthographic camera's size is half its visible height, so a subject wider than the viewport's aspect allows has to be fitted by width instead — dividing its half-width by the aspect converts it into the height that would contain it. Taking the larger of the two is what keeps a broad subject from being cropped at the sides.

Configure(Camera)

Adopts existing as the preview camera, releasing whichever camera was held before.

public void Configure(Camera existing)

Parameters

existing Camera

The character's equipment view camera. May be null to release.

Remarks

Releasing the outgoing camera is not optional. The panel is handed a fresh camera on every keypress, including the one that closes it, so a handover without a release leaves the previous character's camera enabled and rendering into a texture nobody draws — for the rest of the session.

Dispose()

Releases the texture and hands the camera back.

public void Dispose()

Frame(Transform)

Frames everything drawn beneath subject so it fits the viewport.

public bool Frame(Transform subject)

Parameters

subject Transform

The character's mesh root. May be null.

Returns

bool

True when the subject had drawable renderers and the camera was framed.

Remarks

Derived from the subject's own renderer bounds rather than from constants, because the character's height is a property of its race model and the game has hundreds of them. The camera prefabs were authored against one placeholder model, at a height that frames a standing human from the knees up.

False means "ask again": the race model is loaded from an addressable and the character may legitimately have no renderers yet on the frame the panel opens.

Render(int, int, Transform)

Resizes the render texture to the viewport and renders the character into it.

public bool Render(int pixelWidth, int pixelHeight, Transform subject = null)

Parameters

pixelWidth int

Viewport width in pixels. Values below 2 are refused.

pixelHeight int

Viewport height in pixels. Values below 2 are refused.

subject Transform

The hierarchy to photograph, alone. Its renderers are moved to the CharacterPreview layer for this render and restored before the call returns. Null renders whatever the camera's mask sees, which on a shared layer includes any neighbour.

Returns

bool

True when a render was submitted.

Remarks

A refusal is not an error: the first tick after a panel opens can run before the UI layout engine has measured anything, and those measurements arrive a frame later. The caller is expected to keep asking.