diff options
author | miakata <miakata@gmail.com> | 2019-04-27 18:08:27 +0200 |
---|---|---|
committer | miakata <miakata@gmail.com> | 2019-04-27 18:08:27 +0200 |
commit | a5df3253047945b54a5ec25c3661b2c4967460e7 (patch) | |
tree | c5b42f3f39c2a65aa644d8d51542ee983a60edfd /nGJ2019/Assets/Scripts/EventTimeline.cs | |
parent | 7568372af43405a0d2b1d1a3adb7f817527098db (diff) | |
parent | 53a8d342ee667d1b28c1dc1e173ad73338a930b9 (diff) |
Merge branch 'master' of https://github.com/marcinzelent/ngj2019
Diffstat (limited to 'nGJ2019/Assets/Scripts/EventTimeline.cs')
-rw-r--r-- | nGJ2019/Assets/Scripts/EventTimeline.cs | 28 |
1 files changed, 27 insertions, 1 deletions
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<SpawnEvent> OnSpawnEvent; + public event Action<MessageEvent> OnMessageEvent; private List<SpawnEvent> futureEvents; + private List<MessageEvent> futureMessages; private float currentTime; public EventTimeline() { futureEvents = new List<SpawnEvent>(); + futureMessages = new List<MessageEvent>(); 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); } } } |