-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDepthMonitorMarker.cs
More file actions
61 lines (51 loc) · 1.81 KB
/
DepthMonitorMarker.cs
File metadata and controls
61 lines (51 loc) · 1.81 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
using Timberborn.AutomationBuildings;
using Timberborn.BaseComponentSystem;
using Timberborn.BlockSystem;
using Timberborn.Rendering;
using Timberborn.SelectionSystem;
using UnityEngine;
namespace Calloatti.DepthMonitor
{
internal class DepthMonitorMarker : BaseComponent, IAwakableComponent, IUpdatableComponent, ISelectionListener
{
// Custom colors to help tell the markers apart
private static readonly Color32 MarkerOnColor = Color.green;
private static readonly Color32 MarkerOffColor = Color.red;
private static readonly float MarkerYOffset = 0.02f;
private readonly MarkerDrawerFactory _markerDrawerFactory;
private DepthMonitor _depthMonitor;
private MeshDrawer _markerOnDrawer;
private MeshDrawer _markerOffDrawer;
private BlockObject _blockObject;
public DepthMonitorMarker(MarkerDrawerFactory markerDrawerFactory)
{
_markerDrawerFactory = markerDrawerFactory;
}
public void Awake()
{
_depthMonitor = GetComponent<DepthMonitor>();
_blockObject = GetComponent<BlockObject>();
_markerOnDrawer = _markerDrawerFactory.CreateTileDrawer(MarkerOnColor);
_markerOffDrawer = _markerDrawerFactory.CreateTileDrawer(MarkerOffColor);
DisableComponent();
}
public void Update()
{
Vector3Int sensorCoordinates = _depthMonitor.SensorCoordinates;
Vector3Int renderCoords = new Vector3Int(sensorCoordinates.x, sensorCoordinates.y, 0);
_markerOnDrawer.DrawAtCoordinates(renderCoords, _depthMonitor.ThresholdOn + MarkerYOffset);
_markerOffDrawer.DrawAtCoordinates(renderCoords, _depthMonitor.ThresholdOff + MarkerYOffset);
}
public void OnSelect()
{
if (!_blockObject.IsPreview)
{
EnableComponent();
}
}
public void OnUnselect()
{
DisableComponent();
}
}
}