-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCANmapLegend.cs
111 lines (102 loc) · 3.08 KB
/
SCANmapLegend.cs
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
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCANmapLegend - Object to store data on map legend textures
*
* Copyright (c)2013 damny;
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using SCANsat.SCAN_Platform.Palettes;
using SCANsat.SCAN_Data;
using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette;
using UnityEngine;
namespace SCANsat.SCAN_Map
{
public class SCANmapLegend
{
private Texture2D legend;
private float legendMin, legendMax;
private Palette dataPalette;
private bool legendScheme;
public Texture2D Legend
{
get { return legend; }
set { legend = value; }
}
internal Texture2D getLegend(float min, float max, bool color, SCANterrainConfig terrain)
{
if (legend != null && legendMin == min && legendMax == max && legendScheme == color && terrain.ColorPal.hash == dataPalette.hash)
return legend;
legend = new Texture2D(256, 1, TextureFormat.RGB24, false);
legendMin = min;
legendMax = max;
legendScheme = color;
dataPalette = terrain.ColorPal;
Color[] pix = legend.GetPixels();
for (int x = 0; x < 256; ++x)
{
float val = (x * (max - min)) / 256f + min;
pix[x] = palette.heightToColor(val, color, terrain);
}
legend.SetPixels(pix);
legend.Apply();
return legend;
}
internal Texture2D getLegend(SCANterrainConfig terrain)
{
Texture2D t = new Texture2D(256, 1, TextureFormat.RGB24, false);
Color[] pix = t.GetPixels();
for (int x = 0; x < 256; ++x)
{
float val = (x * (terrain.MaxTerrain - terrain.MinTerrain)) / 256f + terrain.MinTerrain;
pix[x] = palette.heightToColor(val, true, terrain);
}
t.SetPixels(pix);
t.Apply();
return t;
}
internal Texture2D getLegend(float max, float min, float range, float? clamp, bool discrete, Color32[] c)
{
Texture2D t = new Texture2D(128, 1, TextureFormat.RGB24, false);
Color[] pix = t.GetPixels();
for (int x = 0; x < 128; x++)
{
float val = (x * (max - min)) / 128f + min;
pix[x] = palette.heightToColor(val, max, min, range, clamp, discrete, c);
}
t.SetPixels(pix);
t.Apply();
return t;
}
internal static Texture2D getStaticLegend(SCANterrainConfig terrain)
{
Texture2D t = new Texture2D(256, 1, TextureFormat.RGB24, false);
Color[] pix = t.GetPixels();
for (int x = 0; x < 256; ++x)
{
float val = (x * (terrain.MaxTerrain - terrain.MinTerrain)) / 256f + terrain.MinTerrain;
pix[x] = palette.heightToColor(val, true, terrain);
}
t.SetPixels(pix);
t.Apply();
return t;
}
internal static Texture2D getStaticLegend(float max, float min, float range, float? clamp, bool discrete, Color32[] c)
{
Texture2D t = new Texture2D(128, 1, TextureFormat.RGB24, false);
Color[] pix = t.GetPixels();
for (int x = 0; x < 128; x++)
{
float val = (x * (max - min)) / 128f + min;
pix[x] = palette.heightToColor(val, max, min, range, clamp, discrete, c);
}
t.SetPixels(pix);
t.Apply();
return t;
}
}
}