| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | namespace DCL.FPSDisplay |
| | 4 | | { |
| | 5 | | public class FPSColoring |
| | 6 | | { |
| 0 | 7 | | private static readonly Color GREAT_COLOR = Color.green; |
| 0 | 8 | | private static readonly Color GOOD_COLOR = Color.white; |
| 0 | 9 | | private static readonly Color BAD_COLOR = Color.yellow; |
| 0 | 10 | | private static readonly Color WORSE_COLOR = new Color(0.9764706f, 0.4117647f, 0.05490196f); |
| 0 | 11 | | private static readonly Color UNBEARABLE_COLOR = Color.red; |
| | 12 | |
|
| 0 | 13 | | public static FPSColor[] coloring = |
| | 14 | | { |
| | 15 | | new FPSColor(GREAT_COLOR, FPSEvaluation.GREAT), |
| | 16 | | new FPSColor(GOOD_COLOR, FPSEvaluation.GOOD), |
| | 17 | | new FPSColor(BAD_COLOR, FPSEvaluation.BAD), |
| | 18 | | new FPSColor(WORSE_COLOR, FPSEvaluation.WORSE), |
| | 19 | | new FPSColor(UNBEARABLE_COLOR, FPSEvaluation.UNBEARABLE), |
| | 20 | | }; |
| | 21 | |
|
| | 22 | | private static Color GeFPSDisplayColor(float fps) |
| | 23 | | { |
| 0 | 24 | | for (int i = 0; i < coloring.Length; i++) |
| | 25 | | { |
| 0 | 26 | | if (fps >= coloring[i].fps) |
| | 27 | | { |
| 0 | 28 | | return coloring[i].color; |
| | 29 | | } |
| | 30 | | } |
| 0 | 31 | | return coloring[coloring.Length - 1].color; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | private static Color GetPercentageColoring(float value, float limit) |
| | 35 | | { |
| 0 | 36 | | float currentPercentage = value / limit; |
| 0 | 37 | | if (currentPercentage > 0.99) |
| | 38 | | { |
| 0 | 39 | | return UNBEARABLE_COLOR; |
| | 40 | | } |
| 0 | 41 | | if (currentPercentage > 0.9) |
| | 42 | | { |
| 0 | 43 | | return BAD_COLOR; |
| | 44 | | } |
| 0 | 45 | | return GOOD_COLOR; |
| | 46 | | } |
| | 47 | |
|
| | 48 | | private static Color GetMemoryColoring(float memoryValue) |
| | 49 | | { |
| 0 | 50 | | if (memoryValue > 1800) |
| | 51 | | { |
| 0 | 52 | | return UNBEARABLE_COLOR; |
| | 53 | | } |
| 0 | 54 | | if (memoryValue > 1500) |
| | 55 | | { |
| 0 | 56 | | return BAD_COLOR; |
| | 57 | | } |
| 0 | 58 | | return GOOD_COLOR; |
| | 59 | | } |
| | 60 | |
|
| 0 | 61 | | public static string GetDisplayColorString(float fps) { return GetColor(GetHexColor(GeFPSDisplayColor(fps))); } |
| | 62 | |
|
| 0 | 63 | | public static string GetPercentageColoringString(int value, int limit) { return GetColor(GetHexColor(GetPercenta |
| | 64 | |
|
| 0 | 65 | | private static string GetHexColor(Color color) { return $"#{ColorUtility.ToHtmlStringRGB(color)}"; } |
| | 66 | |
|
| 0 | 67 | | private static string GetColor(string color) { return $"<color={color}>"; } |
| | 68 | |
|
| 0 | 69 | | public static object GetMemoryColoringString(float memoryValue) { return GetColor(GetHexColor(GetMemoryColoring( |
| | 70 | | } |
| | 71 | | } |