Scripting

Everything the built-in screens do goes through public code you can call yourself. All types are in the RareGeometry.Photoworthy namespace; reference the RareGeometry.Photoworthy assembly from your own assembly definition if you use one.

The camera #

using RareGeometry.Photoworthy;
using UnityEngine;

public class MyCameraButtons : MonoBehaviour
{
    public PhotoCamera photoCamera;   // or PhotoCamera.Main

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F)) photoCamera.ToggleHandheld();
        if (photoCamera.IsOpen && Input.GetMouseButtonDown(0))
        {
            var shot = photoCamera.TakePhoto();
            if (shot == null) Debug.Log("Refused: " + photoCamera.WhyNot());
        }
    }
}
Member What it does
OpenHandheld(), OpenPhotoMode(), Close(), ToggleHandheld(), TogglePhotoMode() Open and close the camera screens.
TakePhoto() A photo through the open screen. Returns the shot, or null when refused.
Capture() A photo of the current view with no screen needed (taken by the game).
CaptureFrom(spot) A photo from a Photo Spot, with the game camera put straight back.
TakePhotoAfter(seconds), CancelTimer(), TimerSeconds, TimerLeft The shutter timer.
TakeBurst(count, interval) Several photos in a row from one call.
AutoFocus, PictureShape, ResetPictureShape() Auto focus, and the picture shape for this session (the profile is never changed).
Orbit, PhotoModeFocus, HideCharacter, GoToSpot(spot), StepSpot(direction) The photo mode's orbit camera, hiding the character, and viewpoints.
Body, BodyIndex, StepBody(1), ResetBody(), Bodies The camera body players look through.
Lenses, LensInUse, LensIndex, StepLens(1), UnlockLens(name), LockLens(name) The handheld camera's lenses.
Selfie, ToggleSelfie(), CanSelfie, SelfieFocus, ShownInSelfie The selfie camera. Every shot's Selfie says whether it was one.
FlashMode, StepFlash(), FlashCharge, FlashReady The flash. Every shot's Flash says whether it fired.
TakeStrip(photos, secondsBetween), StripRunning, LastStrip A photo strip: several photos printed as one picture.
ShowGhost(photo), ClearGhost(), GhostOpacity An earlier photo shown faintly over the view.
FocusTarget The subject the viewfinder is locked on to.
Mode, IsOpen What the camera is doing.
Zoom, Tilt, Lens, FilterIndex, FrameIndex, ResetLens() The lens.
FilmLeft, AddFilm(n) Film.
Blocked, CanOpen, CanShoot Your game's say over when the camera works.
DecideKeep Your own rule for which photos are kept.
SetStamp(key, value) Your own values on every photo taken from now on.
WhyNot() Why a photo would be refused right now.
ShutterFired, ShotReady, ShotDecided, ShotRefused, ModeChanged, LensChanged, BodyChanged, LensSwapped, SelfieChanged, FlashFired, StripMade, FocusLocked, GhostChanged Events.

A shot and a photo #

TakePhoto returns a PhotoShot at once. Its picture arrives a moment later (Ready, or the ShotReady event), because reading pixels back and writing the file do not block the game.

photoCamera.ShotDecided += shot =>
{
    if (!shot.Kept) return;
    Photo photo = shot.Photo;
    Debug.Log(photo.mainSubject + ": " + photo.score + " (" + photo.medal + ")");
    foreach (PhotoSubjectRecord s in photo.subjects)
        Debug.Log(s.subject + " doing " + s.behaviour + ", " + Mathf.RoundToInt(s.visible * 100f) + "% visible");
};

A Photo is the saved record: id, source, judged, score, topScore, medal, passed, mainSubject, subjects (each with its score, behaviour, details, regions, visible share, picture share, facing, distance and reasons), regions, requests completed, your data, favourite, caption, filter, frame, where the camera stood, and the picture's file. Helpers: Shows(id), Find(id), Count(id), GetData(key).

Change a result #

void OnEnable() => PhotoEvents.PhotoEvaluated += Adjust;
void OnDisable() => PhotoEvents.PhotoEvaluated -= Adjust;

void Adjust(Photo photo, PhotoContext context)
{
    // Double points at night.
    if (photo.GetData("time") != "night") return;
    photo.score = Mathf.Min(photo.topScore, photo.score * 2f);
    photo.medal = context.Profile.Scoring.MedalFor(photo.Share);
}

Photos with no camera component #

PhotoShot shot = PhotoShoot.Take(anyCamera, profile, PhotoSource.Script, ready: s => Debug.Log("Picture is in"));

PhotoShoot.Take runs the whole pipeline for any Unity Camera: capture, recognise, judge, keep or discard, save. Decide yourself with PhotoShoot.Keep(shot) and PhotoShoot.Discard(shot) when the profile's keep rule is Player Chooses.

Only recognition, no photo #

Ask what a camera can see without taking anything, for AI, tutorials or your own viewfinder:

var view = PhotoView.From(Camera.main, profile);
SubjectSighting sighting = PhotoRecognizer.Look(view, profile.recognition, subject);
if (sighting != null && sighting.Recognised) Debug.Log("In view, " + sighting.Visible + " visible");

Subjects #

var subject = GetComponent<PhotoSubject>();
subject.SetBehaviour("eat");        // doing only this
subject.BeginBehaviour("glow");     // doing this as well
subject.EndBehaviour("glow");
subject.Photographable = false;     // hide from the camera
subject.SetData("mood", "angry");   // copied into photos of it

SubjectRegistry.All lists every enabled subject; SubjectRegistry.Find(id) finds one by its definition key.

Requests, journal and album #

PhotoRequests.Offer(request);
PhotoRequests.Withdraw(request);
bool done = PhotoJournal.Main.IsCompleted(request.Id);

bool found = PhotoJournal.Main.IsDiscovered("zebra");
JournalEntry entry = PhotoJournal.Main.Entry("zebra");

foreach (Photo photo in PhotoAlbum.Main.Photos) { }
PhotoAlbum.Main.LoadThumbnail(photo, texture => image.texture = texture);
PhotoAlbum.Main.SetFavourite(photo, true);
PhotoAlbum.Main.Remove(photo);
string copy = PhotoAlbum.Main.Export(photo);

Textures handed over by the album belong to it. Do not destroy them, and ask again when a screen reopens: the album lets go of pictures it has not been asked for in a while.

Events #

PhotoEvents (static, for the whole game): CameraOpened, CameraClosed, CaptureRequested, PhotoEvaluated, PhotoAccepted, PhotoRejected, PhotoSaved, SubjectDiscovered, BehaviourDiscovered, NewBestShot, RequestCompleted. Remember to unsubscribe in OnDisable.

Extending #

To change Write
How photos are judged A CustomPhotoScorer asset. See Scoring.
A request rule A CustomPhotoRule asset. See Photo requests.
Where photos are stored An IPhotoStore, opened with PhotoAlbum.Open(store).
Where input comes from An IPhotoInput, set with PhotoInput.Use(input).
Lens effects An IPhotoEffects, for a custom render pipeline.
Words PhotoText.Translate, PhotoText.Set, or a Text Table asset.

Editor #

Tools > Photoworthy > Check Scene For Problems uses the shared Diagnostics window, which lists the checks of every Rare Geometry product in the project.

Something unclear or wrong? Tell us · Get help