{"id":13730878,"url":"https://github.com/renanwolf/UniRate","last_synced_at":"2025-05-08T03:32:10.688Z","repository":{"id":48405593,"uuid":"144413121","full_name":"renanwolf/UniRate","owner":"renanwolf","description":"Unity plugin to easily manage the application frame rate and rendering interval. Reducing battery power consumption and device heat, especially on mobile platforms.","archived":false,"fork":false,"pushed_at":"2023-10-30T14:28:52.000Z","size":932,"stargazers_count":81,"open_issues_count":0,"forks_count":7,"subscribers_count":5,"default_branch":"feature","last_synced_at":"2024-10-29T23:55:31.286Z","etag":null,"topics":["battery","frame","framerate-management","heat","idle-game","interval","mobile","rate","rendering","rendering-optimizations","unity","unity-plugin","unity3d"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renanwolf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-08-11T19:33:04.000Z","updated_at":"2024-10-17T14:15:39.000Z","dependencies_parsed_at":"2023-11-08T10:17:09.766Z","dependency_job_id":null,"html_url":"https://github.com/renanwolf/UniRate","commit_stats":{"total_commits":117,"total_committers":3,"mean_commits":39.0,"dds":"0.042735042735042694","last_synced_commit":"f89445be8bf93c9a13698e09d7cbe2d5e532fdab"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renanwolf%2FUniRate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renanwolf%2FUniRate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renanwolf%2FUniRate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renanwolf%2FUniRate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renanwolf","download_url":"https://codeload.github.com/renanwolf/UniRate/tar.gz/refs/heads/feature","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224318698,"owners_count":17291721,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["battery","frame","framerate-management","heat","idle-game","interval","mobile","rate","rendering","rendering-optimizations","unity","unity-plugin","unity3d"],"created_at":"2024-08-03T02:01:20.765Z","updated_at":"2024-11-14T21:31:45.798Z","avatar_url":"https://github.com/renanwolf.png","language":"C#","readme":"# UniRate\n\nCreated by Renan Wolf Pace\n\n[![Release](https://img.shields.io/github/v/release/renanwolf/UniRate.svg)](https://github.com/renanwolf/UniRate/releases)\n[![OpenUPM](https://img.shields.io/npm/v/com.pflowr.unirate?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.pflowr.unirate/)\n[![Unity](https://img.shields.io/badge/dynamic/json?logo=unity\u0026color=green\u0026label=Asset%20Store\u0026query=%24.unity\u0026prefix=Unity%20\u0026suffix=%2B\u0026url=https%3A%2F%2Fraw.githubusercontent.com%2Frenanwolf%2FUniRate%2Ffeature%2Fpackage.json)](https://assetstore.unity.com/packages/slug/234108)\n[![Changelog](https://img.shields.io/github/release-date/renanwolf/UniRate?color=green\u0026label=changelog)](CHANGELOG.md)\n[![License](https://img.shields.io/github/license/renanwolf/UniRate)](LICENSE.md)\n\n## Overview\n\nA Unity plugin to easily manage the application frame rate and rendering interval.\n\nIt'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.\n\nTo 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.\n\n## Installation\n\n#### via Unity Asset Store\n\nhttps://assetstore.unity.com/packages/slug/234108\n\n#### via Package Manager\n\nAdd the following dependency to the `Packages/manifest.json` file of your Unity project:\n```json\n\"dependencies\": {\n    \"com.pflowr.unirate\": \"https://github.com/renanwolf/UniRate.git\",\n}\n```\n\n#### via OpenUPM\n\nThis package is available on [OpenUPM](https://openupm.com/packages/com.pflowr.unirate/) registry, you can install it via [openupm-cli](https://github.com/openupm/openupm-cli):\n```\nopenupm add com.pflowr.unirate\n```\n\n#### via Assets Import Package\n\nImport the [.unitypackage](https://github.com/renanwolf/UniRate/releases/latest) from the latest release to your Unity project.\n\n## Rate Manager\n\nThe 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.\n\nIt manages multiples rate/interval requests and apply the best one.\n\nJust access the `RateManager.Instance` by code and it will be automatically created, or create an empty `GameObject` and attach the `RateManager` component to it.\n\n#### Setting Up\n\n- `UpdateRate.Mode`: set to `VSyncCount` or `ApplicationTargetFrameRate` to choose how the update rate should be managed.\n\n- `UpdateRate.Minimum`: is the minimum allowed update rate that can be applied. Any request bellow this value will be ignored.\n\n- `FixedUpdateRate.Minimum`: is the minimum allowed fixed update rate that can be applied. Any request bellow this value will be ignored.\n\n- `RenderInterval.Maximum`: is the maximum allowed render interval that can be applied. Any request above this value will be ignored.\n\n## Rate and Interval Requests\n\nTo start a request you need to access the `RateManager.Instance` and use one of the following methods:\n\n- `UpdateRate.Request(int)` to start a new update rate request, it returns an `UpdateRateRequest`.\n\n- `FixedUpdateRate.Request(int)` to start a new fixed update rate request, it returns a `FixedUpdateRateRequest`.\n\n- `RenderInterval.Request(int)` to start a new render interval request, it returns a `RenderIntervalRequest`.\n\nAll the requests returned from these methods inherits from `RateRequest` and implements `IDisposable`. Keep the requests with you to be able to cancel them later.\n\nTo cancel a request just dispose it!\n\n```csharp\nusing UniRate;\n...\n\nprivate IEnumerator ExampleCoroutineThatPerformsAnimation() {\n\n  // get the RateManager instance\n  var rateManager = RateManager.Instance;\n  \n  // starts the requests you need\n  var updateRateRequest = rateManager.UpdateRate.Request(60);\n  var fixedUpdateRateRequest = rateManager.FixedUpdateRate.Request(50);\n  var renderIntervalRequest = rateManager.RenderInterval.Request(1); // only works on Unity 2019.3 or newer\n\n  while (isAnimating) {\n    ...\n    yield return null;\n  }\n\n  // cancel them when you are done\n  updateRateRequest.Dispose();\n  fixedUpdateRateRequest.Dispose();\n  renderIntervalRequest.Dispose();\n}\n```\n\n## Update Rate\n\nIs the number of `Update` per second that the game executes.\n\nUnity 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.\n\n## Fixed Update Rate\n\nIs the number of `FixedUpdate` per second that the game executes.\n\n## Render Interval\n\nIs 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.\n\nIt **only works on Unity 2019.3 or newer**, since its use the new [Unity OnDemandRendering API](https://docs.unity3d.com/ScriptReference/Rendering.OnDemandRendering.html). For any previous version the render interval will always be 1, ignoring the requests.\n\nTo verify if the current frame will render just access the `RenderInterval.WillRender` property inside the `RateManager` instance.\n\n## Ready to use Components\n\nThere are a few components already created to manage requests in some circumstances, if they aren't enough you can create yours.\n\n#### RateRequestWhileEnabledComponent\n\nThis component keeps the requests active while it is active and enabled.\n\n#### RateRequestTouchComponent\n\nThis component keeps the requests active while `Input.touchCount` is greater then zero or `Input.GetMouseButton(0, 1, 2)` is true.\n\n#### RateRequestScrollRectComponent\n\nThis component keeps the requests active while the `ScrollRect.velocity` is not zero or when it changes the normalized position.\n\n#### RateRequestInputFieldComponent _and_ RateRequestTMPInputFieldComponent\n\nThese components keep the requests active while the input field is focused or when the text changes.\n\nTo enable the `RateRequestTMPInputFieldComponent` you need to add the `TMPRO` define symbol in your player settings.\n\n#### RateRequestAnimationComponent\n\nThis component keeps the requests active while an `Animation` component is playing.\n\n#### RateRequestAnimatorComponent\n\nThis component keeps the requests active while an `Animator` component is playing.\n\n## UniRate Tracker\n\nThe tracker is useful to debug requests lifecycle, you can open the tracker window through `Window \u003e UniRate Tracker`.\n\n## Debugging\n\nAll the debug options can be modified accessing the `RateDebug` static class.\n\n```csharp\nusing UniRate.Debug;\n...\n\nprivate void SetUniRateDebugSettingsForProduction() {\n  RateDebug.LogLevel = RateLogLevel.Warning;\n  RateDebug.DisplayOnScreenData = false;\n}\n\nprivate void SetUniRateDebugSettingsForTests() {\n  RateDebug.LogLevel = RateLogLevel.Debug;\n  RateDebug.ScreenDataBackgroundColor = new Color(0, 0, 0, 0.5f);\n  RateDebug.ScreenDataFontSize = 10;\n  RateDebug.ScreenDataFontColor = Color.white;\n  RateDebug.ScreenDataVerbose = false;\n  RateDebug.DisplayOnScreenData = true;\n}\n```\n\n#### DisplayOnScreenData\n\nIf enabled, display on the top-left corner of the screen informations about current rates and intervals.\n\nTo modify how the on screen data is displayed, change the following properties `ScreenDataVerbose`, `ScreenDataBackgroundColor`, `ScreenDataFontSize` and `ScreenDataFontColor`.\n\n#### IsDebugBuild\n\nOn editor returns `EditorUserBuildSettings.development`, otherwise returns `Debug.isDebugBuild`.\n\n#### LogLevel\n\nSet to one of the following values to filter which logs should be enabled:\n\n- `Trace`: changes to `QualitySettings.vSyncCount`, `Application.targetFrameRate`, `Time.fixedDeltaTime`, `OnDemandRendering.renderFrameInterval` and `RateRequest` creation/cancellation are logged with this level.\n\n- `Debug`: changes to `UpdateRate.Target`, `FixedUpdateRate.Target` and `RenderInterval.Target` are logged with this level.\n\n- `Info`: changes to `UpdateRate.Mode`, `UpdateRate.Minimum`, `FixedUpdateRate.Minimum` and `RenderInterval.Maximum` are logged with this level.\n\n- `Warning`\n\n- `Error`\n\n- `Off`\n\nThe default value on editor is `Debug` if `IsDebugBuild` is true, otherwise `Info`. In runtime is `Info` if `IsDebugBuild` is true, otherwise `Warning`.\n\n## FAQ\n\n#### My camera/canvas is flickering\n\nIt is probably related to a [Unity OnDemandRendering API](https://docs.unity3d.com/ScriptReference/Rendering.OnDemandRendering.html) bug. The cause may be the combination of some factors like Unity version, canvas render mode, camera clear flags, update rate mode, plataform and some others. In most of the cases the bug only occurs in the Unity Editor and not in runtime.\n\nTo ignore all the render interval requests set the `RateManager.Instance.RenderInterval.Maximum` to 1.\n\nFor more information from the community access: https://unity3d.com/search?gq=ondemandrendering%20flicker","funding_links":[],"categories":["Open Source Repositories","C#","Optimization"],"sub_categories":["Utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenanwolf%2FUniRate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenanwolf%2FUniRate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenanwolf%2FUniRate/lists"}