Skip to content

Commit 8e86988

Browse files
committed
Documentation; Removed unused code.
1 parent c5579dd commit 8e86988

13 files changed

Lines changed: 123 additions & 67 deletions

Assets/Plugins/UnityTutorialSystem/Scenes/TutorialAssembly.unity

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Plugins/UnityTutorialSystem/Scripts/Events/BasicEventStreamMessage.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ public BasicEventStream Stream
2929
protected set => stream = value;
3030
}
3131

32+
/// <summary>
33+
/// A simple non-public entry point so that BasicEventStreams can
34+
/// pass itself to instances of this class at design time.
35+
/// </summary>
36+
/// <param name="eventStream"></param>
3237
internal void SetUpStream(BasicEventStream eventStream)
3338
{
3439
stream = eventStream;
3540
}
3641

42+
/// <summary>
43+
/// Publishes the message to the associated stream.
44+
/// </summary>
3745
public void Publish()
3846
{
3947
if (stream != null)

Assets/Plugins/UnityTutorialSystem/Scripts/Events/EventMessageAggregatorStatePublisher.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22
using UnityEngine;
33
using UnityEngine.Events;
44
using UnityTutorialSystem.Aggregators;
5+
using UnityTutorialSystem.UI;
56

67
namespace UnityTutorialSystem.Events
78
{
9+
/// <summary>
10+
/// <para>A companion <see cref="MonoBehaviour"/> for <see cref="EventMessageAggregator"/> instances that monitors the
11+
/// EventMessageAggregator and republishes the events as UnityEvents. The <see cref="EventMessageAggregatorStatePublisher"/>
12+
/// is also used by the <see cref="EventStreamTreeModelBuilder"/> to detect parent-child relationships between
13+
/// EventMessageAggregator instances.</para>
14+
/// <para>If no <see cref="EventMessageAggregator"/> is injected into the <see cref="stateChain"/> field, this
15+
/// class will try to locate a EventMessageAggregator on the same GameObject.
16+
/// </para>
17+
/// </summary>
818
public class EventMessageAggregatorStatePublisher : StreamEventSource
919
{
20+
/// <summary>
21+
/// Materialization of a generic UnityEvent.
22+
/// </summary>
1023
public class ProgressEvent : UnityEvent<EventMessageAggregatorStatePublisher, BasicEventStreamMessage>
1124
{
1225
}
@@ -20,11 +33,35 @@ public EventMessageAggregatorStatePublisher()
2033
stateChanged = new ProgressEvent();
2134
}
2235

36+
/// <summary>
37+
/// Republishes the EventMessageAggregator's matchProgress event.
38+
/// </summary>
39+
/// <seealso cref="EventMessageAggregator.matchProgress"/>
2340
public ProgressEvent StateChanged => stateChanged;
41+
42+
/// <summary>
43+
/// A BasicEventStreamMessage that is fired when the associated EventMessageAggregator successfully
44+
/// finished its matching. The EventStream associated with this message will be considered a parent
45+
/// stream by the EventStreamTreeModelBuilder.
46+
/// </summary>
2447
public BasicEventStreamMessage SuccessMessage => successMessage;
2548

49+
/// <summary>
50+
/// Republishes the associated EventMessageAggregator's current match result state.
51+
/// </summary>
2652
public EventMessageMatcherState MatchResult => stateChain.MatchResult;
2753

54+
/// <summary>
55+
/// Queries the internal state of the associated message aggregator. The given buffer will be filled
56+
/// with <see cref="EventMessageState"/> structs containing the expected event in the order they are
57+
/// expected to be seen as well as flags indicating whether the event has been seen or is expected to
58+
/// be seen next.
59+
/// </summary>
60+
/// <param name="buffer">
61+
/// A receive buffer. If null, a new list will be created. If the list is non-empty,
62+
/// the list will be cleared.
63+
/// </param>
64+
/// <returns>The buffer provided or a new list if the buffer given is null.</returns>
2865
public List<EventMessageState> FetchEvents(List<EventMessageState> buffer)
2966
{
3067
return stateChain.ListEvents(buffer);
@@ -58,6 +95,12 @@ void OnDisable()
5895
}
5996
}
6097

98+
/// <summary>
99+
/// Checks whether the message given matches the success message that is fired when the
100+
/// EventMessageAggregator successfully matches its events received.
101+
/// </summary>
102+
/// <param name="msg"></param>
103+
/// <returns></returns>
61104
public override bool WillGenerateMessage(BasicEventStreamMessage msg)
62105
{
63106
return Equals(SuccessMessage, msg);
@@ -79,8 +122,6 @@ void OnMatchComplete()
79122
{
80123
successMessage.Publish();
81124
}
82-
83-
Debug.Log("Fired success message " + successMessage);
84125
}
85126
}
86127
}

Assets/Plugins/UnityTutorialSystem/Scripts/Events/LogEventStream.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace UnityTutorialSystem.Events
55
{
6+
/// <summary>
7+
/// A debug component that prints out all messages received by the given event stream.
8+
/// </summary>
69
public class LogEventStream : MonoBehaviour
710
{
811
[SerializeField] BasicEventStream stream;

Assets/Plugins/UnityTutorialSystem/Scripts/Events/StreamEventSource.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
namespace UnityTutorialSystem.Events
44
{
5+
/// <summary>
6+
/// A base type for all MonoBehaviours that can activate EventStream messages.
7+
/// StreamEventSources are referenced by the NextEvent-predictor system to
8+
/// simplify the wiring up of event cascades.
9+
/// </summary>
510
public abstract class StreamEventSource : MonoBehaviour
611
{
12+
/// <summary>
13+
/// Checks whether the message given will be generated by is source. The
14+
/// NextEventSelector implementations will use this method to locate components
15+
/// that could trigger the event in question.
16+
/// </summary>
17+
/// <param name="msg">The message object to be evaluated</param>
18+
/// <returns>true if the source will generate this message, false otherwise.</returns>
719
public abstract bool WillGenerateMessage(BasicEventStreamMessage msg);
820
}
921
}

Assets/Plugins/UnityTutorialSystem/Scripts/Tutorial/TutorialEventTreeBinding.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using UnityEngine;
2+
using UnityTutorialSystem.UI;
23

34
namespace UnityTutorialSystem.Tutorial
45
{
56
public class TutorialEventTreeBinding : MonoBehaviour
67
{
7-
[SerializeField] TutorialEventStreamManager modelSource;
8+
[SerializeField] EventStreamTreeModelBuilder modelSource;
89
[SerializeField] TutorialEventTreeView treeView;
910

1011
void Awake()

Assets/Plugins/UnityTutorialSystem/Scripts/Tutorial/TutorialEventTreeItemRenderer.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
using UnityEngine;
44
using UnityEngine.UI;
55
using UnityTutorialSystem.Events;
6+
using UnityTutorialSystem.UI;
67
using UnityTutorialSystem.UI.Trees;
78
using VRKitchenSimulator.UI;
89

910
namespace UnityTutorialSystem.Tutorial
1011
{
11-
public class TutorialEventTreeItemRenderer : TreeItemRenderer<TutorialEventStateData>
12+
public class TutorialEventTreeItemRenderer : TreeItemRenderer<EventStreamTreeModelData>
1213
{
1314
[SerializeField] Color whenNextEventColor;
1415
[SerializeField] Color whenCompletedColor;
@@ -36,7 +37,7 @@ void Reset()
3637
label = GetComponentInChildren<TextMeshProUGUI>();
3738
}
3839

39-
bool IsNextEvent(TutorialEventStateData data)
40+
bool IsNextEvent(EventStreamTreeModelData data)
4041
{
4142
if (data.ExpectedNext == false)
4243
{
@@ -113,7 +114,7 @@ void MarkLayoutDirty()
113114
}
114115
}
115116

116-
protected override void OnUpdateValue(TreePath<TutorialEventStateData> treePath)
117+
protected override void OnUpdateValue(TreePath<EventStreamTreeModelData> treePath)
117118
{
118119
if (treePath == null)
119120
{
@@ -122,7 +123,7 @@ protected override void OnUpdateValue(TreePath<TutorialEventStateData> treePath)
122123
return;
123124
}
124125

125-
TutorialEventStateData data;
126+
EventStreamTreeModelData data;
126127
if (treePath.TryGetLastComponent(out data) && (data.SourceMessage != null))
127128
{
128129
if (label != null)
@@ -169,7 +170,7 @@ void ApplyIndent(RectTransform rt)
169170
{
170171
if (!anchorStored)
171172
{
172-
var tree = gameObject.GetComponentInParent<TreeView<TutorialEventStateData>>();
173+
var tree = gameObject.GetComponentInParent<TreeView<EventStreamTreeModelData>>();
173174
if (tree != null)
174175
{
175176
indentCorrection = tree.ShowRootNode ? 0 : -1;

Assets/Plugins/UnityTutorialSystem/Scripts/Tutorial/TutorialEventTreeView.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
using UnityEngine;
2+
using UnityTutorialSystem.UI;
23
using UnityTutorialSystem.UI.Trees;
34

45
namespace UnityTutorialSystem.Tutorial
5-
{
6-
public class TutorialEventTreeView : TreeView<TutorialEventStateData>
6+
{
7+
public class TutorialEventTreeView : TreeView<EventStreamTreeModelData>
78
{
89
[SerializeField] TutorialEventTreeItemRenderer template;
910
[SerializeField] bool showAllNodes;
1011
[SerializeField] bool hideCompletedSubTrees;
11-
ITreeModel<TutorialEventStateData> model;
12+
protected override TreeItemRenderer<EventStreamTreeModelData> ItemRenderer => template;
1213

13-
protected override TreeItemRenderer<TutorialEventStateData> ItemRenderer => template;
14-
15-
public ITreeModel<TutorialEventStateData> Model
16-
{
17-
get { return model; }
18-
set
19-
{
20-
model = value;
21-
InternalModel = value;
22-
}
23-
}
24-
25-
protected override bool IsPathVisible(TreePath<TutorialEventStateData> path)
14+
protected override bool IsPathVisible(TreePath<EventStreamTreeModelData> path)
2615
{
2716
if (hideCompletedSubTrees)
2817
{
@@ -38,8 +27,7 @@ protected override bool IsPathVisible(TreePath<TutorialEventStateData> path)
3827

3928
if (!showAllNodes)
4029
{
41-
TutorialEventStateData stateData;
42-
if (path.TryGetLastComponent(out stateData) && (stateData != null))
30+
if (path.TryGetLastComponent(out var stateData) && (stateData != null))
4331
{
4432
// Debug.Log("Maybe Hiding node " + path);
4533
return stateData.Completed || stateData.ExpectedNext;

Assets/Plugins/UnityTutorialSystem/Scripts/Tutorial/TutorialEventStreamManager.cs renamed to Assets/Plugins/UnityTutorialSystem/Scripts/UI/EventStreamTreeModelBuilder.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
using UnityTutorialSystem.Events;
77
using UnityTutorialSystem.UI.Trees;
88

9-
namespace UnityTutorialSystem.Tutorial
9+
namespace UnityTutorialSystem.UI
1010
{
11-
public class TutorialEventStreamManager : MonoBehaviour
11+
public class EventStreamTreeModelBuilder : MonoBehaviour
1212
{
1313
readonly List<EventMessageState> buffer;
14+
readonly ListTreeModel<EventStreamTreeModelData> model;
1415

1516
[SerializeField] [ReorderableList] List<EventMessageAggregatorStatePublisher> tutorialStateTrackers;
1617
[SerializeField] bool debug;
1718

18-
ListTreeModel<TutorialEventStateData> model;
19-
Dictionary<EventMessageAggregatorStatePublisher, TutorialEventStateData> nodeMapper;
20-
TutorialEventStateData rootNode;
19+
Dictionary<EventMessageAggregatorStatePublisher, EventStreamTreeModelData> nodeMapper;
20+
EventStreamTreeModelData rootNode;
2121
bool started;
2222

23-
public TutorialEventStreamManager()
23+
public EventStreamTreeModelBuilder()
2424
{
2525
buffer = new List<EventMessageState>();
26-
model = new ListTreeModel<TutorialEventStateData>();
26+
model = new ListTreeModel<EventStreamTreeModelData>();
2727
}
2828

29-
public ITreeModel<TutorialEventStateData> Model => model;
29+
public ITreeModel<EventStreamTreeModelData> Model => model;
3030

3131
void DebugLog(string message)
3232
{
@@ -40,7 +40,7 @@ void DebugLog(string message)
4040

4141
void Start()
4242
{
43-
nodeMapper = new Dictionary<EventMessageAggregatorStatePublisher, TutorialEventStateData>();
43+
nodeMapper = new Dictionary<EventMessageAggregatorStatePublisher, EventStreamTreeModelData>();
4444
started = true;
4545

4646
var data = CollectTreeData();
@@ -78,7 +78,7 @@ void OnTrackerStateChanged(EventMessageAggregatorStatePublisher source, BasicEve
7878
return;
7979
}
8080

81-
TutorialEventStateData data;
81+
EventStreamTreeModelData data;
8282
if (!nodeMapper.TryGetValue(source, out data))
8383
{
8484
data = rootNode;
@@ -143,22 +143,22 @@ List<ExpectedStates> CollectTreeData()
143143
return data.Where(d => !d.IsDependency).ToList();
144144
}
145145

146-
TutorialEventStateData CreateTreeNodes(List<ExpectedStates> data,
147-
Dictionary<EventMessageAggregatorStatePublisher, TutorialEventStateData> nodeMapper)
146+
EventStreamTreeModelData CreateTreeNodes(List<ExpectedStates> data,
147+
Dictionary<EventMessageAggregatorStatePublisher, EventStreamTreeModelData> nodeMapper)
148148
{
149149
var roots = data.Where(s => !s.IsDependency).ToList();
150-
var childStates = new List<TutorialEventStateData>();
150+
var childStates = new List<EventStreamTreeModelData>();
151151
foreach (var s in roots)
152152
{
153153
var item = AddTree(s, nodeMapper);
154154
item.ExpectedNext = false;
155155
AddGeneratedChildItems(childStates, item);
156156
}
157157

158-
return new TutorialEventStateData(null, false, true, childStates);
158+
return new EventStreamTreeModelData(null, false, true, childStates);
159159
}
160160

161-
static void AddGeneratedChildItems(List<TutorialEventStateData> childStates, TutorialEventStateData item)
161+
static void AddGeneratedChildItems(List<EventStreamTreeModelData> childStates, EventStreamTreeModelData item)
162162
{
163163
if (item.SourceMessage != null)
164164
{
@@ -173,10 +173,10 @@ static void AddGeneratedChildItems(List<TutorialEventStateData> childStates, Tut
173173
}
174174
}
175175

176-
static TutorialEventStateData AddTree(ExpectedStates state,
177-
Dictionary<EventMessageAggregatorStatePublisher, TutorialEventStateData> nodeMapper)
176+
static EventStreamTreeModelData AddTree(ExpectedStates state,
177+
Dictionary<EventMessageAggregatorStatePublisher, EventStreamTreeModelData> nodeMapper)
178178
{
179-
var childStates = new List<TutorialEventStateData>();
179+
var childStates = new List<EventStreamTreeModelData>();
180180
foreach (var s in state.RequiredMessages)
181181
{
182182
ExpectedStates dependency;
@@ -189,11 +189,11 @@ static TutorialEventStateData AddTree(ExpectedStates state,
189189
else
190190
{
191191
var message = (s.Message);
192-
childStates.Add(new TutorialEventStateData(message, s.Completed, s.ExpectedNext));
192+
childStates.Add(new EventStreamTreeModelData(message, s.Completed, s.ExpectedNext));
193193
}
194194
}
195195

196-
var stateData = new TutorialEventStateData(state.SuccessMessage, state.Completed, false, childStates);
196+
var stateData = new EventStreamTreeModelData(state.SuccessMessage, state.Completed, false, childStates);
197197
nodeMapper[state.MessageSource] = stateData;
198198
return stateData;
199199
}

Assets/Plugins/UnityTutorialSystem/Scripts/Tutorial/TutorialEventStreamManager.cs.meta renamed to Assets/Plugins/UnityTutorialSystem/Scripts/UI/EventStreamTreeModelBuilder.cs.meta

File renamed without changes.

0 commit comments

Comments
 (0)