All Projects → renanwolf → UniRate

renanwolf / UniRate

Licence: MIT license
Unity plugin to easily manage the application frame rate and rendering interval. Preventing battery power consumption and device heat, especially on mobile platforms.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to UniRate

Fg
Rendering abstraction which describes a frame as a directed acyclic graph of render tasks and resources.
Stars: ✭ 390 (+1400%)
Mutual labels:  rendering, frame
Fake-Interior-Shader-for-GodotEngine
Interior Mapping shader for the Godot Game Engine 3.x that works with both GLES3 and GLES2.
Stars: ✭ 40 (+53.85%)
Mutual labels:  rendering
mahler.c
Western music theory library in C99
Stars: ✭ 13 (-50%)
Mutual labels:  interval
audio-context-timers
A replacement for setInterval() and setTimeout() which works in unfocused windows.
Stars: ✭ 12 (-53.85%)
Mutual labels:  interval
tesla powerwall
Python API for Tesla Powerwall
Stars: ✭ 43 (+65.38%)
Mutual labels:  battery
flamingo
FreeCAD - flamingo workbench
Stars: ✭ 30 (+15.38%)
Mutual labels:  frame
bisml
Implementation of the paper: Adaptive BRDF-Oriented Multiple Importance Sampling of Many Lights
Stars: ✭ 26 (+0%)
Mutual labels:  rendering
gamedevguide
Game Development & Unreal Engine Programming Guide
Stars: ✭ 314 (+1107.69%)
Mutual labels:  rendering
feels
🌀 Calculate apparent temperature using heat index, approximate wet-bulb globe temperature, humidex, australian apparent temperature and wind chill.
Stars: ✭ 25 (-3.85%)
Mutual labels:  heat
SLProject
SLProject is a platform independent 3D computer graphics scene graph library. Read more on:
Stars: ✭ 47 (+80.77%)
Mutual labels:  rendering
swaystatus
A minimal executable for displaying sway status per second
Stars: ✭ 14 (-46.15%)
Mutual labels:  battery
InstaSmart
A Flutter app to plan and beautify your Instagram feed
Stars: ✭ 18 (-30.77%)
Mutual labels:  frame
ssr
React Server-Side Rendering Example
Stars: ✭ 265 (+919.23%)
Mutual labels:  rendering
prax
Experimental rendering library geared towards hybrid SSR+SPA apps. Focus on radical simplicity and performance. Tiny and dependency-free.
Stars: ✭ 18 (-30.77%)
Mutual labels:  rendering
rating
⭐ A true Bayesian rating system with scope and cache enabled
Stars: ✭ 49 (+88.46%)
Mutual labels:  rate
Nabla
OpenGL/OpenGL ES/Vulkan/CUDA/OptiX Modular Rendering Framework for PC/Linux/Android
Stars: ✭ 235 (+803.85%)
Mutual labels:  rendering
isometric-renders
Creates high-resolution isometric screenshots of Minecraft's game objects
Stars: ✭ 42 (+61.54%)
Mutual labels:  rendering
SHSoftwareRasterizer
软光栅器的简单实现
Stars: ✭ 31 (+19.23%)
Mutual labels:  rendering
bat
Battery management utility for Linux laptops.
Stars: ✭ 107 (+311.54%)
Mutual labels:  battery
pbrtbook
pbrt 中文整合翻译 基于物理的渲染:从理论到实现 Physically Based Rendering: From Theory To Implementation
Stars: ✭ 221 (+750%)
Mutual labels:  rendering

UniRate

Created by Renan Wolf Pace

Release OpenUPM Changelog UnityVersion License

Overview

A Unity plugin to easily manage the application frame rate and rendering interval.

It's not desirable to keep your game always running at the highest frame rate, especially on mobile platforms where you can quickly consume a lot of battery power and increase device heat.

To help you solve these problems, UniRate provides you a simple solution to control the update rate, fixed update rate and render interval from everywhere in your code without worrying about multiple requests.

Installation

via Package Manager

Add the following dependency to the Packages/manifest.json file of your Unity project:

"dependencies": {
    "com.pflowr.unirate": "https://github.com/renanwolf/UniRate.git",
}

via OpenUPM

This package is available on OpenUPM registry, you can install it via openupm-cli:

openupm add com.pflowr.unirate

via Assets Import Package

Import the .unitypackage from the latest release to your Unity project.

Rate Manager

The main plugin singleton that allows you to control all the rates and intervals. It is recommended that for anything else than throwaway code, you keep the instance referenced with you while using it.

It manages multiples rate/interval requests and apply the best one.

Just access the RateManager.Instance by code and it will be automatically created, or create an empty GameObject and attach the RateManager component to it.

Setting Up

  • UpdateRateMode: set to VSyncCount or ApplicationTargetFrameRate to choose how the update rate should be managed.

  • MinimumUpdateRate: is the minimum allowed update rate that can be applied. Any request bellow this value will be ignored.

  • MinimumFixedUpdateRate: is the minimum allowed fixed update rate that can be applied. Any request bellow this value will be ignored.

  • MaximumRenderInterval: is the maximum allowed render interval that can be applied. Any request above this value will be ignored.

Rate and Interval Requests

To start a request you need to access the RateManager.Instance and use one of the following methods:

  • RequestUpdateRate(int) to start a new update rate request, it returns the UpdateRateRequest.

  • RequestFixedUpdateRate(int) to start a new fixed update rate request, it returns the FixedUpdateRateRequest.

  • RequestRenderInterval(int) to start a new render interval request, it returns the RenderIntervalRequest.

All the requests returned from these methods inherits from RateRequest and implements IDisposable. Keep the requests with you to be able to cancel them later.

To cancel a request just dispose it!

using UniRate;
...

private IEnumerator ExampleCoroutineThatPerformsAnimation() {

  // get the RateManager instance
  var rateManager = RateManager.Instance;
  
  // starts the requests you need
  var updateRateRequest = rateManager.RequestUpdateRate(60);
  var fixedUpdateRateRequest = rateManager.RequestFixedUpdateRate(50);
  var renderIntervalRequest = rateManager.RequestRenderInterval(1); // only works on Unity 2019.3 or newer

  while (isAnimating) {
    ...
    yield return null;
  }

  // cancel them when you are done
  updateRateRequest.Dispose();
  fixedUpdateRateRequest.Dispose();
  renderIntervalRequest.Dispose();
}

Update Rate

Is the number of Update per second that the game executes.

Unity uses the update rate to manage the input system, so if it's too low the engine will not detect user's inputs correctly. It should be fine if it stays at least around 18.

Fixed Update Rate

Is the number of FixedUpdate per second that the game executes.

Render Interval

Is the number of Update that takes before the game executes a render. A value of 1 means the game will render on every update, a value of 2 on every other update, and so on.

It only works on Unity 2019.3 or newer, since its use the new Unity OnDemandRendering API. For any previous version the render interval will always be 1, ignoring the requests.

To verify if the current frame will render just access the WillRender property inside the RateManager instance.

Ready to use Components

There are a few components already created to manage requests in some circumstances, if they aren't enough you can create yours.

RateRequestWhileEnabledComponent

This component keeps the requests active while it is active and enabled.

RateRequestTouchComponent

This component keeps the requests active while Input.touchCount is greater then zero or Input.GetMouseButton(0, 1, 2) is true.

RateRequestScrollRectComponent

This component keeps the requests active while the ScrollRect.velocity is not zero or when it changes the normalized position.

RateRequestInputFieldComponent and RateRequestTMPInputFieldComponent

These components keep the requests active while the input field is focused or when the text changes.

To enable the RateRequestTMPInputFieldComponent you need to add the TMPRO define symbol in your player settings.

RateRequestAnimationComponent

This component keeps the requests active while an Animation component is playing.

RateRequestAnimatorComponent

This component keeps the requests active while an Animator component is playing.

Debugging

All the debug options can be modified accessing the RateDebug static class.

using UniRate.Debug;
...

private void SetUniRateDebugSettingsForProduction() {
  RateDebug.LogLevel = RateLogLevel.Warning;
  RateDebug.DisplayOnScreenData = false;
}

private void SetUniRateDebugSettingsForTests() {
  RateDebug.LogLevel = RateLogLevel.Debug;
  RateDebug.ScreenDataBackgroundColor = new Color(0, 0, 0, 0.5f);
  RateDebug.ScreenDataFontSize = 10;
  RateDebug.ScreenDataFontColor = Color.white;
  RateDebug.ScreenDataVerbose = false;
  RateDebug.DisplayOnScreenData = true;
}

DisplayOnScreenData

If enabled, display on the top-left corner of the screen informations about current rates and intervals.

To modify how the on screen data is displayed, change the following properties ScreenDataVerbose, ScreenDataBackgroundColor, ScreenDataFontSize and ScreenDataFontColor.

IsDebugBuild

On editor returns EditorUserBuildSettings.development, otherwise returns Debug.isDebugBuild.

LogLevel

Set to one of the following values to filter which logs should be enabled:

  • Trace: changes to QualitySettings.vSyncCount, Application.targetFrameRate, Time.fixedDeltaTime, OnDemandRendering.renderFrameInterval and RateRequest creation/cancellation are logged with this level.

  • Debug: changes to TargetUpdateRate, TargetFixedUpdateRate and TargetRenderInterval are logged with this level.

  • Info: changes to UpdateRateMode, MinimumUpdateRate, MinimumFixedUpdateRate and MaximumRenderInterval are logged with this level.

  • Warning

  • Error

  • Off

The default value on editor is Debug if IsDebugBuild is true, otherwise Info. In runtime is Info if IsDebugBuild is true, otherwise Warning.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].