1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class FloatRange
{
public float Last { get; private set; }
public float Width
{
get
{
return this.max - this.min;
}
}
public float min;
public float max;
public FloatRange(float min, float max)
{
this.min = min;
this.max = max;
}
public float ChangeRange(float y, float min, float max)
{
return Mathf.Lerp(min, max, (y - this.min) / this.Width);
}
public float Clamp(float value)
{
return Mathf.Clamp(value, this.min, this.max);
}
public bool Contains(float t)
{
return this.min <= t && this.max >= t;
}
public float CubicLerp(float v)
{
if (this.min >= this.max)
{
return this.min;
}
v = Mathf.Clamp(0f, 1f, v);
return v * v * v * (this.max - this.min) + this.min;
}
public float EitherOr()
{
if (UnityEngine.Random.value <= 0.5f)
{
return this.max;
}
return this.min;
}
public float LerpUnclamped(float v)
{
return Mathf.LerpUnclamped(this.min, this.max, v);
}
public float Lerp(float v)
{
return Mathf.Lerp(this.min, this.max, v);
}
public float ExpOutLerp(float v)
{
return this.Lerp(1f - Mathf.Pow(2f, -10f * v));
}
public static float ExpOutLerp(float v, float min, float max)
{
return Mathf.Lerp(min, max, 1f - Mathf.Pow(2f, -10f * v));
}
public static float Next(float min, float max)
{
return UnityEngine.Random.Range(min, max);
}
public float Next()
{
return this.Last = UnityEngine.Random.Range(this.min, this.max);
}
public IEnumerable<float> Range(int numStops)
{
float num;
for (float i = 0f; i <= (float)numStops; i = num)
{
yield return Mathf.Lerp(this.min, this.max, i / (float)numStops);
num = i + 1f;
}
yield break;
}
public IEnumerable<float> RandomRange(int numStops)
{
float num;
for (float i = 0f; i <= (float)numStops; i = num)
{
yield return this.Next();
num = i + 1f;
}
yield break;
}
internal float ReverseLerp(float t)
{
return Mathf.Clamp((t - this.min) / this.Width, 0f, 1f);
}
public static float ReverseLerp(float t, float min, float max)
{
float num = max - min;
return Mathf.Clamp((t - min) / num, 0f, 1f);
}
public IEnumerable<float> SpreadToEdges(int stops)
{
return FloatRange.SpreadToEdges(this.min, this.max, stops);
}
public IEnumerable<float> SpreadEvenly(int stops)
{
return FloatRange.SpreadEvenly(this.min, this.max, stops);
}
public static IEnumerable<float> SpreadToEdges(float min, float max, int stops)
{
if (stops == 1)
{
yield break;
}
int num;
for (int i = 0; i < stops; i = num)
{
yield return Mathf.Lerp(min, max, (float)i / ((float)stops - 1f));
num = i + 1;
}
yield break;
}
public static IEnumerable<float> SpreadEvenly(float min, float max, int stops)
{
float step = 1f / ((float)stops + 1f);
for (float i = step; i < 1f; i += step)
{
yield return Mathf.Lerp(min, max, i);
}
yield break;
}
}
|