-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointOnSurfaceCommandReceiver.cs
97 lines (87 loc) · 3.07 KB
/
PointOnSurfaceCommandReceiver.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PointOnSurfaceCommandReceiver : MonoBehaviour
{
private void OnEnable()
{
hom3r.coreLink.SubscribeCommandObserver(DoPointOnSurfaceCommand, UndoPointOnSurfaceCommand); //Subscribe a method to the event delegate
}
private void OnDisable()
{
hom3r.coreLink.UnsubscribeCommandObserver(DoPointOnSurfaceCommand, UndoPointOnSurfaceCommand); //Unsubscribe a method to the event delegate
}
private void DoPointOnSurfaceCommand(CCoreCommand command)
{
if (command.GetType() == typeof(CPointOnSurfaceCommand)) { command.Do(this); }
else { /* Do nothing */ }
}
private void UndoPointOnSurfaceCommand(CCoreCommand command)
{
if (command.GetType() == typeof(CPointOnSurfaceCommand)) { command.Undo(this); }
else { /* Do nothing */ }
}
}
/// <summary>Navigation Commands</summary>
public enum TPointOnSurfaceCommands
{
StartPointCapture, StartPointCaptureSpecificArea,
DrawAnchorPoint
}
/// <summary>Navigation data</summary>
public class CPointOnSurfaceCommandData
{
public TPointOnSurfaceCommands commandEvent;
public string areaId { get; set; }
public Vector3 pointPosition { get; set; }
public CPointOnSurfaceCommandData(TPointOnSurfaceCommands _commandEvent) { this.commandEvent = _commandEvent; }
}
/// <summary>A 'ConcreteCommand' class</summary>
public class CPointOnSurfaceCommand : CCoreCommand
{
public CPointOnSurfaceCommandData data;
//////////////////
// Constructors //
//////////////////
public CPointOnSurfaceCommand(TPointOnSurfaceCommands _command)
{
data = new CPointOnSurfaceCommandData(_command);
}
public CPointOnSurfaceCommand(TPointOnSurfaceCommands _command, string _areaId)
{
data = new CPointOnSurfaceCommandData(_command);
data.areaId = _areaId;
}
//////////////////
// Execute //
//////////////////
public void Do(MonoBehaviour m)
{
if (!hom3r.state.navigationBlocked)
{
if (data != null)
{
switch (data.commandEvent)
{
case TPointOnSurfaceCommands.StartPointCapture:
hom3r.quickLinks.scriptsObject.GetComponent<PointOnSurfaceManager>().StartPointCapture();
break;
case TPointOnSurfaceCommands.StartPointCaptureSpecificArea:
hom3r.quickLinks.scriptsObject.GetComponent<PointOnSurfaceManager>().StartPointCapture(data.areaId);
break;
default:
Debug.LogError("Error: This command " + data.commandEvent + " is not valid.");
break;
}
}
else
{
Debug.LogError("Error: Has been called a Point Capture command without command.");
}
}
}
public void Undo(MonoBehaviour m)
{
throw new System.NotImplementedException();
}
}