-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapEx.cs
More file actions
91 lines (82 loc) · 2.58 KB
/
MapEx.cs
File metadata and controls
91 lines (82 loc) · 2.58 KB
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
using System;
namespace ExpMapGen
{
public static class MapEx
{
public static float[] MinMaxValue(this float[,] self)
{
float min = -1;
float max = -1;
bool firstRun = true;
foreach (float current in self) {
if (firstRun) {
min = current;
max = current;
firstRun = false;
continue;
}
if (min > current)
min = current;
if (max < current)
max = current;
}
return new float[]{ min, max };
}
public static float GetAvrgValueAt(this float[,] self, float x, float z)
{
try {
int xmin = UnityEngine.Mathf.FloorToInt(x);
int zmin = UnityEngine.Mathf.FloorToInt(z);
int xmax = xmin + 1;
int zmax = zmin + 1;
float xpercent = GetPercent(xmin, xmax, x);
float zpercent = GetPercent(zmin, zmax, z);
float xbw = GetValueAtPercent(self[xmin, zmin], self[xmax, zmin], xpercent);
float zbw = GetValueAtPercent(self[xmin, zmin], self[xmin, zmax], zpercent);
return (zbw + xbw) / 2;
} catch (Exception ex) {
return 0f;
}
}
public static float GetAvrgValueAt(this float[,,] self, float x, float z, int splattype)
{
try {
int xmin = UnityEngine.Mathf.FloorToInt(x);
int zmin = UnityEngine.Mathf.FloorToInt(z);
int xmax = xmin + 1;
int zmax = zmin + 1;
float xpercent = GetPercent(xmin, xmax, x);
float zpercent = GetPercent(zmin, zmax, z);
float xbw = GetValueAtPercent(self[xmin, zmin, splattype], self[xmax, zmin, splattype], xpercent);
float zbw = GetValueAtPercent(self[xmin, zmin, splattype], self[xmin, zmax, splattype], zpercent);
return (zbw + xbw) / 2;
} catch (Exception ex) {
return 0f;
}
}
public static float GetAvrgValueAt(this byte[,,] self, float x, float z, int splattype)
{
try {
int xmin = UnityEngine.Mathf.FloorToInt(x);
int zmin = UnityEngine.Mathf.FloorToInt(z);
int xmax = xmin + 1;
int zmax = zmin + 1;
float xpercent = GetPercent(xmin, xmax, x);
float zpercent = GetPercent(zmin, zmax, z);
float xbw = GetValueAtPercent((float)self[xmin, zmin, splattype] / 255f, (float)self[xmax, zmin, splattype] / 255f, xpercent);
float zbw = GetValueAtPercent((float)self[xmin, zmin, splattype] / 255f, (float)self[xmin, zmax, splattype] / 255f, zpercent);
return (zbw + xbw) / 2;
} catch (Exception ex) {
return 0f;
}
}
public static float GetPercent(float min, float max, float pointbetween)
{
return (pointbetween - min) / ((max - min) / 100);
}
public static float GetValueAtPercent(float min, float max, float percent)
{
return ((max - min) / 100) * percent + min;
}
}
}