Add JavaScript APIs for crosshair enable/disable/query#111
Conversation
…osshair, IsCrosshairEnabled) Agent-Logs-Url: https://github.com/Five-Squared-Interactive/WebVerse-Runtime/sessions/4ac41633-d627-4453-848f-2e87ec8fd298 Co-authored-by: dyfios <16926525+dyfios@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds JavaScript-accessible crosshair controls to the existing Camera JS API, enabling world scripts to programmatically enable/disable and query crosshair state.
Changes:
- Added
Camera.EnableCrosshair(),Camera.DisableCrosshair(), andCamera.IsCrosshairEnabled()to the JS-exposed Camera API. - Documented the Camera API surface (including new crosshair methods) in
docs/api/javascript-api.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| docs/api/javascript-api.md | Adds a new Camera documentation section and example usage for crosshair + camera operations. |
| Assets/Runtime/Handlers/JavascriptHandler/APIs/WorldBrowserUtilities/Scripts/Camera.cs | Introduces three new static JS API methods to set/query cameraManager.crosshairEnabled with null-guards. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (StraightFour.StraightFour.ActiveWorld == null || | ||
| StraightFour.StraightFour.ActiveWorld.cameraManager == null) | ||
| { | ||
| Logging.LogWarning("[Camera:EnableCrosshair] Camera manager not available."); | ||
| return false; |
There was a problem hiding this comment.
The null-guard checks both ActiveWorld and cameraManager, but the warning message only mentions the camera manager. To make diagnostics clearer, consider logging whether the world is missing vs. the camera manager is missing (or adjust the message to reflect both conditions).
| /// <returns>Whether or not the crosshair is enabled.</returns> | ||
| public static bool IsCrosshairEnabled() | ||
| { | ||
| if (StraightFour.StraightFour.ActiveWorld == null || | ||
| StraightFour.StraightFour.ActiveWorld.cameraManager == null) | ||
| { | ||
| Logging.LogWarning("[Camera:IsCrosshairEnabled] Camera manager not available."); | ||
| return false; |
There was a problem hiding this comment.
IsCrosshairEnabled() returns false both when the crosshair is actually disabled and when the camera manager/world is unavailable, which makes it impossible for scripts to distinguish "disabled" from "could not query". Since this is a newly introduced API, consider returning a nullable boolean (bool?) and returning null when unavailable (or providing a separate availability indicator).
| /// <returns>Whether or not the crosshair is enabled.</returns> | |
| public static bool IsCrosshairEnabled() | |
| { | |
| if (StraightFour.StraightFour.ActiveWorld == null || | |
| StraightFour.StraightFour.ActiveWorld.cameraManager == null) | |
| { | |
| Logging.LogWarning("[Camera:IsCrosshairEnabled] Camera manager not available."); | |
| return false; | |
| /// <returns>Whether or not the crosshair is enabled, or null if the camera manager is unavailable.</returns> | |
| public static bool? IsCrosshairEnabled() | |
| { | |
| if (StraightFour.StraightFour.ActiveWorld == null || | |
| StraightFour.StraightFour.ActiveWorld.cameraManager == null) | |
| { | |
| Logging.LogWarning("[Camera:IsCrosshairEnabled] Camera manager not available."); | |
| return null; |
…lities/Scripts/Camera.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The crosshair feature (
CameraManager.crosshairEnabled) had no JavaScript-accessible surface, making programmatic crosshair control impossible from world scripts.Changes
Camera.cs(JS API) — Three new static methods on theCameraAPI class:EnableCrosshair()→ setscrosshairEnabled = true, returnsboolDisableCrosshair()→ setscrosshairEnabled = false, returnsboolIsCrosshairEnabled()→ returns current crosshair state asboolEach method guards against null
ActiveWorld/cameraManager, logging a warning and returningfalseif unavailable.javascript-api.md— Added "Camera Control" section documenting the fullCameraAPI surface including the new crosshair methods with usage examples.Usage