-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCAN_SettingsBackground.cs
129 lines (100 loc) · 2.99 KB
/
SCAN_SettingsBackground.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCAN_SettingsBackground - Script for controlling the background settings page
*
* Copyright (c)2014 David Grandy <david.grandy@gmail.com>;
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using SCANsat.Unity.Interfaces;
namespace SCANsat.Unity.Unity
{
public class SCAN_SettingsBackground : SettingsPage
{
[SerializeField]
private GameObject m_BodyInfoPrefab = null;
[SerializeField]
private Transform m_BodyInfoTransform = null;
[SerializeField]
private SCAN_Toggle m_ScanActiveToggle = null;
[SerializeField]
private Slider m_TimeWarpResolution = null;
[SerializeField]
private TextHandler m_SensorInfo = null;
private bool loaded;
private ISCAN_Settings settings;
private List<SCAN_BackgroundElement> backgroundBodies = new List<SCAN_BackgroundElement>();
private void Update()
{
if (settings == null || !settings.IsVisible)
return;
for (int i = backgroundBodies.Count - 1; i >= 0; i--)
{
SCAN_BackgroundElement background = backgroundBodies[i];
background.UpdateText(settings.BodyPercentage(background.BodyName));
}
if (m_SensorInfo != null)
m_SensorInfo.OnTextUpdate.Invoke(settings.SensorCount);
}
public void setup(ISCAN_Settings set)
{
if (set == null)
return;
settings = set;
if (m_ScanActiveToggle != null)
m_ScanActiveToggle.isOn = set.BackgroundScanning;
if (m_TimeWarpResolution != null)
m_TimeWarpResolution.value = set.TimeWarp;
CreateBodySections(set.BackgroundBodies);
loaded = true;
}
private void CreateBodySections(IList<string> bodies)
{
if (bodies == null || settings == null || m_BodyInfoPrefab == null || m_BodyInfoTransform == null)
return;
for (int i = 0; i < bodies.Count; i++)
{
string s = bodies[i];
if (string.IsNullOrEmpty(s))
continue;
CreateBodySection(s);
}
}
private void CreateBodySection(string body)
{
SCAN_BackgroundElement background = Instantiate(m_BodyInfoPrefab).GetComponent<SCAN_BackgroundElement>();
if (background == null)
return;
background.transform.SetParent(m_BodyInfoTransform, false);
background.Setup(body, settings.ToggleBodyActive(body), settings);
backgroundBodies.Add(background);
}
public void ScanToggle(bool isOn)
{
if (!loaded || settings == null)
return;
settings.BackgroundScanning = isOn;
}
public void TimeWarpSlider(float value)
{
if (!loaded || settings == null)
return;
settings.TimeWarp = (int)value;
}
public void UpdateScanners(string s)
{
if (settings == null || m_SensorInfo == null)
return;
m_SensorInfo.OnTextUpdate.Invoke(s);
}
}
}