X Tutup

Scripting Support (C#)

advanced scripting

X-Frame FPS Accelerator · Scripting Support (C#)

Class: All members on this page belong to the XFrameManager component (namespace XFrameEffect). Access via GetComponent<XFrameManager>().
Tip: X-Frame provides raycasting and UI interaction helpers that account for the downsampled resolution. Always use these instead of Unity's built-in methods when X-Frame is active.

Getting Started

Add a using directive and access the singleton instance:

using XFrameEffect;

XFrameManager xframe = XFrameManager.instance;

Downsampling Control

XFRAME_DOWNSAMPLING_METHOD method { get; set; }
bool hdr { get; set; }
float downsamplingMax { get; set; }
float staticCameraPositionThreshold { get; set; }

Camera movement threshold below which the camera is considered stationary.

Maximum downsampling factor allowed (0.1–1.0).

float downsamplingStart { get; set; }

Initial downsampling factor at startup (0.1–1.0).

Enable HDR rendering on the secondary camera.

CameraClearFlags cameraClearFlags { get; set; }

Clear flags for the secondary camera.

Downsampling algorithm: Disabled, AdaptativeDownsampling, HorizontalDownsampling, or QuadDownsampling.

float downsampling { get; set; }

Downsampling factor for moving camera (0.1–1.0). Lower values = better performance, lower quality.

float staticCameraDownsampling { get; set; }

Downsampling factor when the camera is stationary (0.1–1.0).

float appliedDownsampling { get; }

The downsampling factor currently being applied (read-only).

float activeDownsampling { get; }

Active target downsampling value based on camera movement state (read-only).

FPS Targeting

int targetFPS { get; set; }
int targetFPSforStaticCamera { get; set; }
int activeTargetFPS { get; }

The active target FPS based on camera state — returns targetFPSforStaticCamera when static, targetFPS when moving (read-only).

Target frame rate when the camera is stationary.

Target frame rate (10–120). X-Frame adapts downsampling to reach this target.

int currentFPS { get; }

Current measured FPS (read-only).

float fpsChangeSpeedUp { get; set; }

Speed of quality increase when FPS is above target (0.01–0.1).

float fpsChangeSpeedDown { get; set; }

Speed of quality decrease when FPS is below target (0.01–0.1).

bool boostFrameRate { get; set; }

Boosts Unity's target frame rate to 300 FPS to remove engine-side caps.

Nice FPS Mode

bool niceFPSEnabled { get; set; }

When enabled, X-Frame upscales quality when the target FPS is consistently reached.

int niceFPS { get; set; }

FPS threshold for Nice FPS mode to activate (30–120).

bool niceFPSisActive { get; }

Returns true if Nice FPS mode is currently active (read-only).

Quality Settings

XFRAME_FILTERING_MODE filtering { get; set; }
float reducePixelLightsThreshold { get; set; }
bool manageLODBias { get; set; }
float manageShadowsMinDistance { get; set; }

Minimum shadow distance when shadow management is active.

float manageShadowsMinInterval { get; set; }

Minimum interval between shadow quality adjustments.

Automatically adjust LOD bias during downsampling for better performance.

float lodBiasMinimum { get; set; }

Minimum LOD bias value when LOD management is active.

float lodBiasMaximum { get; set; }

Maximum LOD bias value when LOD management is active.

Downsampling threshold below which pixel light count is reduced.

Texture filtering: Bilinear (smoother) or NearestNeighbour (sharper, pixelated).

bool sharpen { get; set; }

Enable sharpening filter to counteract downsampling blur.

int antialias { get; set; }

Antialiasing level for the secondary camera.

bool reducePixelLights { get; set; }

Reduce the pixel light count during downsampling for extra performance.

bool manageShadows { get; set; }

Automatically manage shadow quality during downsampling.

Compositing

XFRAME_COMPOSITING_METHOD compositingMethod { get; set; }
bool blendWithBackground { get; set; }

Blend the downsampled image with the background for smoother compositing.

How the downsampled image is composited: SecondCameraBillboardWorldSpace, SecondCameraBlit, or UniversalRenderingPipeline.

bool prewarm { get; set; }

Pre-allocate render textures on initialization to avoid runtime allocation stalls.

RenderTexture rt { get; }

The render texture currently being used (read-only).

FPS Display

bool showFPS { get; set; }
bool showQuality { get; set; }

Show or hide the quality level indicator in the FPS overlay.

Show or hide the FPS counter overlay.

XFRAME_FPS_LOCATION fpsLocation { get; set; }

Screen position: TopLeftCorner, TopRightCorner, BottomLeftCorner, or BottomRightCorner.

int fpsFontSize { get; set; }

Font size of the FPS counter text.

Color fpsColor { get; set; }

Color of the FPS counter text.

Raycast & UI Interaction

X-Frame renders at a lower resolution, so screen coordinates need adjustment. Use these methods instead of Unity's built-in equivalents.

Vector3 AdjustScreenPosition(Vector3 position)
void UpdateUICanvases()

Update all UI Canvas scalers to account for the current downsampling factor.

void UpdateUICanvas(Canvas canvas)

Update a specific UI Canvas scaler to account for the current downsampling factor.

void RestoreUICanvases()

Restore all UI Canvas scalers to their original values.

void RestoreUICanvas(Canvas canvas)

Restore a specific UI Canvas scaler to its original value.

Adjusts a screen position to account for the current downscaling factor. Use when converting screen coordinates.

Ray ScreenPointToRay(Camera camera, Vector3 position)

Replacement for Camera.ScreenPointToRay that accounts for downsampling.

RaycastResult Raycast(Camera camera, Vector3 pointerPosition)

Performs a physics raycast from a screen position, adjusted for downsampling.

bool IsPointerOverUIElement()

Checks if the mouse pointer is over any UI element. Accounts for downsampling.

bool IsPointerOverUIElement(Vector3 pointerPosition)

Checks if a pointer is over any UI element at a specific screen position.

bool IsPointerOverUIButton()

Checks if the mouse pointer is over an interactive UI button.

bool IsPointerOverUIButton(Vector3 pointerPosition)

Checks if a pointer is over an interactive UI button at a specific position.

bool IsPointerOverGameObject(Camera camera, Vector3 pointerPosition)

Checks if a pointer is over a game object with a collider, adjusted for downsampling.

bool enableClickEvents { get; set; }

Enable mouse click event handling through the X-Frame system.

Enums Reference

XFRAME_DOWNSAMPLING_METHOD

Disabled, AdaptativeDownsampling, HorizontalDownsampling, QuadDownsampling

XFRAME_COMPOSITING_METHOD

SecondCameraBillboardWorldSpace, SecondCameraBlit

XFRAME_FILTERING_MODE

Bilinear, NearestNeighbour

XFRAME_FPS_LOCATION

TopLeftCorner, TopRightCorner, BottomLeftCorner, BottomRightCorner

Code Examples

using UnityEngine;
using XFrameEffect;

public class XFrameDemo : MonoBehaviour {
    void Start() {
        var xframe = XFrameManager.instance;

        // Set adaptive downsampling targeting 60 FPS
        xframe.method = XFRAME_DOWNSAMPLING_METHOD.AdaptativeDownsampling;
        xframe.targetFPS = 60;
        xframe.downsampling = 0.5f;
        xframe.staticCameraDownsampling = 0.75f;

        // Enable Nice FPS mode for quality boost
        xframe.niceFPSEnabled = true;
        xframe.niceFPS = 55;

        // Enable sharpening
        xframe.sharpen = true;

        // Show FPS counter
        xframe.showFPS = true;
        xframe.fpsLocation = XFRAME_FPS_LOCATION.TopRightCorner;
    }

    void Update() {
        var xframe = XFrameManager.instance;

        // Use X-Frame's adjusted raycast
        if (Input.GetMouseButtonDown(0)) {
            if (!xframe.IsPointerOverUIElement()) {
                Ray ray = xframe.ScreenPointToRay(Camera.main, Input.mousePosition);
                if (Physics.Raycast(ray, out RaycastHit hit)) {
                    Debug.Log("Hit: " + hit.collider.name);
                }
            }
        }
    }
}
Was this page helpful?
X Tutup