-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationCommandReceiver.cs
127 lines (112 loc) · 4.49 KB
/
NavigationCommandReceiver.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NavigationCommandReceiver : MonoBehaviour {
private void OnEnable()
{
hom3r.coreLink.SubscribeCommandObserver(DoNavigationCommand, UndoNavigationCommand); //Subscribe a method to the event delegate
}
private void OnDisable()
{
hom3r.coreLink.UnsubscribeCommandObserver(DoNavigationCommand, UndoNavigationCommand); //Unsubscribe a method to the event delegate
}
private void DoNavigationCommand(CCoreCommand command)
{
if (command.GetType() == typeof(CNavigationCommand)) { command.Do(this); }
else { /* Do nothing */ }
}
private void UndoNavigationCommand(CCoreCommand command)
{
if (command.GetType() == typeof(CNavigationCommand)) { command.Undo(this); }
else { /* Do nothing */ }
}
}
/// <summary>Navigation Commands</summary>
public enum TNavigationCommands
{
InitializeNavigation, StopNavigation,
MouseMovement,
ZoomToClosest, ZoomToInitial,
ResetPanNavigation
}
/// <summary>Navigation data</summary>
public class CNavigationCommandData
{
public TNavigationCommands commandEvent;
public float mouseX { get; set; }
public float mouseY { get; set; }
public float mouseWheel { get; set; }
public float value { get; set; }
public TMainAxis main3DModelAxis { get; set; }
public CNavigationCommandData(TNavigationCommands _commandEvent) { this.commandEvent = _commandEvent; }
}
/// <summary>A 'ConcreteCommand' class</summary>
public class CNavigationCommand : CCoreCommand
{
public CNavigationCommandData data;
//////////////////
// Constructors //
//////////////////
public CNavigationCommand(TNavigationCommands _command)
{
data = new CNavigationCommandData(_command);
}
public CNavigationCommand(TNavigationCommands _command, TMainAxis _mainAxis = TMainAxis.Vertical)
{
data = new CNavigationCommandData(_command);
data.main3DModelAxis = _mainAxis;
}
public CNavigationCommand(TNavigationCommands _command, float _mouseX, float _mouseY, float _mouseWheel)
{
data = new CNavigationCommandData(_command);
data.mouseX = _mouseX;
data.mouseY = _mouseY;
data.mouseWheel = _mouseWheel;
}
public CNavigationCommand(TNavigationCommands _command, float _value)
{
data = new CNavigationCommandData(_command);
data.value = _value;
}
//////////////////
// Execute //
//////////////////
public void Do(MonoBehaviour m)
{
if (data != null)
{
switch (data.commandEvent)
{
case TNavigationCommands.InitializeNavigation:
hom3r.quickLinks.navigationSystemObject.GetComponent<NavigationManager>().InitNavigation();
break;
case TNavigationCommands.StopNavigation:
hom3r.quickLinks.navigationSystemObject.GetComponent<NavigationManager>().StopNavigation();
break;
case TNavigationCommands.MouseMovement:
hom3r.quickLinks.navigationSystemObject.GetComponent<NavigationManager>().SetMouseMovement(data.mouseX, data.mouseY, data.mouseX, data.mouseY, data.mouseWheel);
break;
case TNavigationCommands.ZoomToClosest:
hom3r.quickLinks.navigationSystemObject.GetComponent<NavigationManager>().SetRadialPosition(TNavigationRadialPositions.closest, data.value);
break;
case TNavigationCommands.ZoomToInitial:
hom3r.quickLinks.navigationSystemObject.GetComponent<NavigationManager>().SetRadialPosition(TNavigationRadialPositions.initial, data.value);
break;
case TNavigationCommands.ResetPanNavigation:
hom3r.quickLinks.navigationSystemObject.GetComponent<NavigationManager>().ResetPanNavigation();
break;
default:
Debug.LogError("Error: This command " + data.commandEvent + " is not valid.");
break;
}
}
else
{
Debug.LogError("Error: Has been called a Navigation command without command.");
}
}
public void Undo(MonoBehaviour m)
{
throw new System.NotImplementedException();
}
}