| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Skybox |
| | 6 | | { |
| | 7 | | public static class TransitioningValues |
| | 8 | | { |
| | 9 | | public static float GetTransitionValue(List<TransitioningFloat> list, float percentage, float defaultVal = 0) |
| | 10 | | { |
| 0 | 11 | | if (list == null || list.Count < 1) |
| | 12 | | { |
| 0 | 13 | | return defaultVal; |
| | 14 | | } |
| | 15 | |
|
| 0 | 16 | | if (list.Count == 1) |
| | 17 | | { |
| 0 | 18 | | return list[0].value; |
| | 19 | | } |
| | 20 | |
|
| 0 | 21 | | TransitioningFloat min = list[0], max = list[0]; |
| | 22 | |
|
| | 23 | |
|
| 0 | 24 | | for (int i = 0; i < list.Count; i++) |
| | 25 | | { |
| 0 | 26 | | if (percentage <= list[i].percentage) |
| | 27 | | { |
| 0 | 28 | | max = list[i]; |
| | 29 | |
|
| 0 | 30 | | if ((i - 1) > 0) |
| | 31 | | { |
| 0 | 32 | | min = list[i - 1]; |
| | 33 | | } |
| | 34 | |
|
| 0 | 35 | | break; |
| | 36 | | } |
| | 37 | | } |
| | 38 | |
|
| 0 | 39 | | float t = Mathf.InverseLerp(min.percentage, max.percentage, percentage); |
| 0 | 40 | | return Mathf.Lerp(min.value, max.value, t); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public static Vector2 GetTransitionValue(List<TransitioningVector2> list, float percentage, Vector2 defaultVal = |
| | 44 | | { |
| 0 | 45 | | Vector2 offset = defaultVal; |
| | 46 | |
|
| 0 | 47 | | if (list == null || list.Count == 0) |
| | 48 | | { |
| 0 | 49 | | return offset; |
| | 50 | | } |
| | 51 | |
|
| 0 | 52 | | if (list.Count == 1) |
| | 53 | | { |
| 0 | 54 | | offset = list[0].value; |
| 0 | 55 | | return offset; |
| | 56 | | } |
| | 57 | |
|
| | 58 | |
|
| 0 | 59 | | TransitioningVector2 min = list[0], max = list[0]; |
| | 60 | |
|
| 0 | 61 | | for (int i = 0; i < list.Count; i++) |
| | 62 | | { |
| 0 | 63 | | if (percentage <= list[i].percentage) |
| | 64 | | { |
| 0 | 65 | | max = list[i]; |
| | 66 | |
|
| 0 | 67 | | if ((i - 1) > 0) |
| | 68 | | { |
| 0 | 69 | | min = list[i - 1]; |
| | 70 | | } |
| | 71 | |
|
| 0 | 72 | | break; |
| | 73 | | } |
| | 74 | | } |
| 0 | 75 | | float t = Mathf.InverseLerp(min.percentage, max.percentage, percentage); |
| 0 | 76 | | offset = Vector2.Lerp(min.value, max.value, t); |
| | 77 | |
|
| 0 | 78 | | return offset; |
| | 79 | | } |
| | 80 | |
|
| | 81 | | public static Vector3 GetTransitionValue(List<TransitioningVector3> list, float percentage) |
| | 82 | | { |
| 0 | 83 | | Vector3 offset = new Vector3(0, 0, 0); |
| | 84 | |
|
| 0 | 85 | | if (list == null || list.Count == 0) |
| | 86 | | { |
| 0 | 87 | | return offset; |
| | 88 | | } |
| | 89 | |
|
| 0 | 90 | | if (list.Count == 1) |
| | 91 | | { |
| 0 | 92 | | offset = list[0].value; |
| 0 | 93 | | return offset; |
| | 94 | | } |
| | 95 | |
|
| | 96 | |
|
| 0 | 97 | | TransitioningVector3 min = list[0], max = list[0]; |
| | 98 | |
|
| 0 | 99 | | for (int i = 0; i < list.Count; i++) |
| | 100 | | { |
| 0 | 101 | | if (percentage <= list[i].percentage) |
| | 102 | | { |
| 0 | 103 | | max = list[i]; |
| | 104 | |
|
| 0 | 105 | | if ((i - 1) > 0) |
| | 106 | | { |
| 0 | 107 | | min = list[i - 1]; |
| | 108 | | } |
| | 109 | |
|
| 0 | 110 | | break; |
| | 111 | | } |
| | 112 | | } |
| | 113 | |
|
| 0 | 114 | | float t = Mathf.InverseLerp(min.percentage, max.percentage, percentage); |
| 0 | 115 | | offset = Vector3.Lerp(min.value, max.value, t); |
| | 116 | |
|
| 0 | 117 | | return offset; |
| | 118 | | } |
| | 119 | | } |
| | 120 | | } |