Skip to content

Commit 4528880

Browse files
committed
Merge branch 'feature' into release
2 parents 6520488 + 1012d1c commit 4528880

13 files changed

+327
-147
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
## [2.1.0] - 2018-08-28
4+
### Added
5+
- Customize background color, text color and font size on `RateDebug` screen data.
6+
- Enable/disable verbose screen data on `RateDebug`.
7+
- `RateManager.HasInstance` to check if the instance exists without creating it.
8+
### Changed
9+
- Renamed `Debugger` to `RateDebug`.
10+
- Renamed `LogLevel` to `RateLogLevel`.
11+
- Increased `RateDebug.LogLevel` default value.

CHANGELOG.md.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+72-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# UniRate
22

3-
by Renan Wolf Pace
3+
Created by Renan Wolf Pace
4+
5+
[![Release](https://img.shields.io/github/v/release/renanwolf/UniRate.svg)](https://github.com/renanwolf/UniRate/releases)
6+
[![OpenUPM](https://img.shields.io/npm/v/com.pflowr.unirate?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.pflowr.unirate/)
7+
[![Changelog](https://img.shields.io/github/release-date/renanwolf/UniRate?color=green&label=changelog)](CHANGELOG.md)
8+
![UnityVersion](https://img.shields.io/badge/dynamic/json?color=green&label=unity&query=%24.unity&suffix=%20or%20later&url=https%3A%2F%2Fraw.githubusercontent.com%2Frenanwolf%2FUniRate%2Frelease%2Fpackage.json)
9+
[![License](https://img.shields.io/github/license/renanwolf/UniRate)](LICENSE.md)
410

511
## Overview
612

@@ -21,6 +27,13 @@ Add the following dependency to the `Packages/manifest.json` file of your Unity
2127
}
2228
```
2329

30+
#### via OpenUPM
31+
32+
This 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):
33+
```
34+
openupm add com.pflowr.unirate
35+
```
36+
2437
#### via Assets Import Package
2538

2639
Import the [.unitypackage](https://github.com/renanwolf/UniRate/releases/latest) from the latest release to your Unity project.
@@ -35,7 +48,7 @@ Just access the `RateManager.Instance` by code and it will be automatically crea
3548

3649
#### Setting Up
3750

38-
- `UpdateRateMode`: set to `VSyncCount` or `ApplicationTargetFrameRate` to choose how the update rate will be managed.
51+
- `UpdateRateMode`: set to `VSyncCount` or `ApplicationTargetFrameRate` to choose how the update rate should be managed.
3952

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

@@ -95,7 +108,7 @@ Is the number of `FixedUpdate` per second that the game executes.
95108

96109
## Render Interval
97110

98-
Is the number of `Update` that will take 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.
111+
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.
99112

100113
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.
101114

@@ -107,18 +120,69 @@ There are a few components already created to manage requests in some circumstan
107120

108121
#### RateRequestWhileEnabledComponent
109122

110-
This component will keep the requests active while it is active and enabled.
123+
This component keeps the requests active while it is active and enabled.
111124

112125
#### RateRequestTouchComponent
113126

114-
This component will keep the requests active while `Input.touchCount` is greater then zero or `Input.GetMouseButton(0, 1, 2)` is true.
127+
This component keeps the requests active while `Input.touchCount` is greater then zero or `Input.GetMouseButton(0, 1, 2)` is true.
115128

116129
#### RateRequestScrollRectComponent
117130

118-
This component will keep the requests active while the `ScrollRect.velocity` is not zero or when it changes the normalized position.
131+
This component keeps the requests active while the `ScrollRect.velocity` is not zero or when it changes the normalized position.
119132

120133
#### RateRequestInputFieldComponent _and_ RateRequestTMPInputFieldComponent
121134

122-
These components will keep the requests active while the input field is focused or when the text changes.
135+
These components keep the requests active while the input field is focused or when the text changes.
136+
137+
To enable the `RateRequestTMPInputFieldComponent` you need to add the `TMPRO` define symbol in your player settings.
138+
139+
## Debugging
140+
141+
All the debug options can be modified accessing the `RateDebug` static class.
142+
143+
```csharp
144+
using UniRate.Debug;
145+
...
146+
147+
private void SetUniRateDebugSettingsForProduction() {
148+
RateDebug.LogLevel = RateLogLevel.Warning;
149+
RateDebug.DisplayOnScreenData = false;
150+
}
151+
152+
private void SetUniRateDebugSettingsForTests() {
153+
RateDebug.LogLevel = RateLogLevel.Debug;
154+
RateDebug.ScreenDataBackgroundColor = new Color(0, 0, 0, 0.5f);
155+
RateDebug.ScreenDataFontSize = 10;
156+
RateDebug.ScreenDataFontColor = Color.white;
157+
RateDebug.ScreenDataVerbose = false;
158+
RateDebug.DisplayOnScreenData = true;
159+
}
160+
```
161+
162+
#### DisplayOnScreenData
163+
164+
If enabled, display on the top-left corner of the screen informations about current rates and intervals.
165+
166+
To modify how the on screen data is displayed, change the following properties `ScreenDataVerbose`, `ScreenDataBackgroundColor`, `ScreenDataFontSize` and `ScreenDataFontColor`.
167+
168+
#### IsDebugBuild
169+
170+
On editor returns `EditorUserBuildSettings.development`, otherwise returns `Debug.isDebugBuild`.
171+
172+
#### LogLevel
173+
174+
Set to one of the following values to filter which logs should be enabled:
175+
176+
- `Trace`: changes to `QualitySettings.vSyncCount`, `Application.targetFrameRate`, `Time.fixedDeltaTime`, `OnDemandRendering.renderFrameInterval` and `RateRequest` creation/cancellation are logged with this level.
177+
178+
- `Debug`: changes to `TargetUpdateRate`, `TargetFixedUpdateRate` and `TargetRenderInterval` are logged with this level.
179+
180+
- `Info`: changes to `UpdateRateMode`, `MinimumUpdateRate`, `MinimumFixedUpdateRate` and `MaximumRenderInterval` are logged with this level.
181+
182+
- `Warning`
183+
184+
- `Error`
185+
186+
- `Off`
123187

124-
To enable the `RateRequestTMPInputFieldComponent` you need to add the `TMPRO` define symbol in your player settings.
188+
The default value on editor is `Debug` if `IsDebugBuild` is true, otherwise `Info`. In runtime is `Info` if `IsDebugBuild` is true, otherwise `Warning`.

Runtime/Debug/Debugger.cs

-66
This file was deleted.

Runtime/Debug/RateDebug.cs

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using System;
2+
using UnityEngine;
3+
#if UNITY_EDITOR
4+
using UnityEditor;
5+
#endif
6+
using UnityDebug = UnityEngine.Debug;
7+
using UnityObject = UnityEngine.Object;
8+
9+
namespace UniRate.Debug {
10+
11+
public static class RateDebug {
12+
13+
#region <<---------- Initializers ---------->>
14+
15+
static RateDebug() {
16+
#if UNITY_EDITOR
17+
LogLevel = (IsDebugBuild ? RateLogLevel.Debug : RateLogLevel.Info);
18+
#else
19+
LogLevel = (IsDebugBuild ? RateLogLevel.Info : RateLogLevel.Warning);
20+
#endif
21+
22+
ScreenDataBackgroundColor = new Color(0, 0, 0, 0.25f);
23+
ScreenDataFontSize = 12;
24+
ScreenDataFontColor = Color.white;
25+
ScreenDataVerbose = true;
26+
DisplayOnScreenData = IsDebugBuild;
27+
}
28+
29+
#endregion <<---------- Initializers ---------->>
30+
31+
32+
33+
34+
#region <<---------- Properties and Fields ---------->>
35+
36+
public static bool IsDebugBuild {
37+
get {
38+
#if UNITY_EDITOR
39+
return EditorUserBuildSettings.development;
40+
#else
41+
return UnityDebug.isDebugBuild;
42+
#endif
43+
}
44+
}
45+
46+
public static RateLogLevel LogLevel { get; set; }
47+
48+
public static bool DisplayOnScreenData { get; set; }
49+
50+
public static bool ScreenDataVerbose { get; set; }
51+
52+
public static Color ScreenDataBackgroundColor {
53+
get => _screenDataBackgroundColor;
54+
set {
55+
if (_screenDataBackgroundColor == value) return;
56+
_screenDataBackgroundColor = value;
57+
OnScreenDataBackgroundColorChanged(_screenDataBackgroundColor);
58+
}
59+
}
60+
private static Color _screenDataBackgroundColor;
61+
62+
public static int ScreenDataFontSize {
63+
get => _screenDataFontSize;
64+
set {
65+
if (_screenDataFontSize == value) return;
66+
_screenDataFontSize = value;
67+
OnScreenDataFontSizeChanged(_screenDataFontSize);
68+
}
69+
}
70+
private static int _screenDataFontSize;
71+
72+
public static Color ScreenDataFontColor {
73+
get => _screenDataFontColor;
74+
set {
75+
if (_screenDataFontColor == value) return;
76+
_screenDataFontColor = value;
77+
OnScreenDataFontColorChanged(_screenDataFontColor);
78+
}
79+
}
80+
private static Color _screenDataFontColor;
81+
82+
private static Texture2D ScreenDataBackgroundTexture {
83+
get {
84+
if (_screenDataBackgroundTexture == null) {
85+
_screenDataBackgroundTexture = CreateScreenDataBackgroundTexture(_screenDataBackgroundColor);
86+
}
87+
return _screenDataBackgroundTexture;
88+
}
89+
}
90+
private static Texture2D _screenDataBackgroundTexture;
91+
92+
internal static GUIStyle ScreenDataStyle {
93+
get {
94+
if (_screenDataStyle == null) {
95+
_screenDataStyle = CreateScreenDataStyle(
96+
_screenDataFontSize,
97+
_screenDataFontColor,
98+
ScreenDataBackgroundTexture
99+
);
100+
}
101+
return _screenDataStyle;
102+
}
103+
}
104+
private static GUIStyle _screenDataStyle;
105+
106+
private const string LOG_PREFIX = "[UniRate] ";
107+
108+
#endregion <<---------- Properties and Fields ---------->>
109+
110+
111+
112+
113+
#region <<---------- Callbacks ---------->>
114+
115+
private static void OnScreenDataBackgroundColorChanged(Color color) {
116+
if (_screenDataBackgroundTexture != null) {
117+
UnityObject.Destroy(_screenDataBackgroundTexture);
118+
}
119+
if (_screenDataStyle == null) return;
120+
_screenDataStyle.normal.background = ScreenDataBackgroundTexture;
121+
}
122+
123+
private static void OnScreenDataFontSizeChanged(int fontSize) {
124+
if (_screenDataStyle == null) return;
125+
_screenDataStyle.fontSize = fontSize;
126+
}
127+
128+
private static void OnScreenDataFontColorChanged(Color color) {
129+
if (_screenDataStyle == null) return;
130+
_screenDataStyle.normal.textColor = color;
131+
}
132+
133+
#endregion <<---------- Callbacks ---------->>
134+
135+
136+
137+
138+
#region <<---------- General ---------->>
139+
140+
public static bool IsLogLevelActive(RateLogLevel level) {
141+
return (level >= LogLevel);
142+
}
143+
144+
internal static void Log(RateLogLevel level, string message, UnityObject context = null) {
145+
switch (level) {
146+
case RateLogLevel.Trace: UnityDebug.Log($"{LOG_PREFIX}{message}", context); return;
147+
case RateLogLevel.Debug: UnityDebug.Log($"{LOG_PREFIX}{message}", context); return;
148+
case RateLogLevel.Info: UnityDebug.Log($"{LOG_PREFIX}{message}", context); return;
149+
case RateLogLevel.Warning: UnityDebug.LogWarning($"{LOG_PREFIX}{message}", context); return;
150+
case RateLogLevel.Error: UnityDebug.LogError($"{LOG_PREFIX}{message}", context); return;
151+
case RateLogLevel.Off: return;
152+
default: throw new NotImplementedException($"not handling {nameof(RateLogLevel)}.{level.ToString()}");
153+
}
154+
}
155+
156+
private static Texture2D CreateScreenDataBackgroundTexture(Color color) {
157+
var texture = new Texture2D(1, 1);
158+
var colorArray = texture.GetPixels();
159+
for (int i = colorArray.Length - 1; i >= 0; i--) {
160+
colorArray[i] = color;
161+
}
162+
texture.SetPixels(colorArray);
163+
texture.Apply();
164+
return texture;
165+
}
166+
167+
private static GUIStyle CreateScreenDataStyle(int fontSize, Color fontColor, Texture2D backgroundTexture) {
168+
var style = new GUIStyle(GUI.skin.label);
169+
style.fontSize = fontSize;
170+
style.normal.textColor = fontColor;
171+
style.normal.background = backgroundTexture;
172+
style.padding = new RectOffset(2, 2, 1, 1);
173+
return style;
174+
}
175+
176+
#endregion <<---------- General ---------->>
177+
}
178+
}

Runtime/Debug/Debugger.cs.meta Runtime/Debug/RateDebug.cs.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)