From 19d32b28f4888407a5c06ed84a751a2c35691d2b Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 27 Apr 2019 18:00:48 +0200 Subject: Added messaging --- nGJ2019/Assets/Scripts/EventTimeline.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'nGJ2019/Assets/Scripts/EventTimeline.cs') diff --git a/nGJ2019/Assets/Scripts/EventTimeline.cs b/nGJ2019/Assets/Scripts/EventTimeline.cs index 21b0bdb..b864ae7 100644 --- a/nGJ2019/Assets/Scripts/EventTimeline.cs +++ b/nGJ2019/Assets/Scripts/EventTimeline.cs @@ -17,15 +17,30 @@ public class EventTimeline this.type = type; } } + + public class MessageEvent + { + public float time; + public String message; + + public MessageEvent(float time, String message) + { + this.time = time; + this.message = message; + } + } public event Action OnSpawnEvent; + public event Action OnMessageEvent; private List futureEvents; + private List futureMessages; private float currentTime; public EventTimeline() { futureEvents = new List(); + futureMessages = new List(); currentTime = 0; } @@ -34,17 +49,28 @@ public class EventTimeline futureEvents.Add(new SpawnEvent(time, height, type)); futureEvents.Sort((x,y) => x.time.CompareTo(y.time)); } + + public void Add(float time, String message) + { + futureMessages.Add(new MessageEvent(time, message)); + futureMessages.Sort((x,y) => x.time.CompareTo(y.time)); + } public void timeTick(float deltaTime) { currentTime += deltaTime; - while(futureEvents.Count > 0 && currentTime > futureEvents[0].time) + while(futureEvents.Count > 0 && currentTime > futureEvents[0].time && futureMessages.Count > 0 && currentTime > futureMessages[0].time) { SpawnEvent e = futureEvents[0]; futureEvents.RemoveAt(0); if(OnSpawnEvent != null) OnSpawnEvent(e); + + MessageEvent m = futureMessages[0]; + futureMessages.RemoveAt(0); + if(OnMessageEvent != null) + OnMessageEvent(m); } } } -- cgit v1.2.3