aboutsummaryrefslogtreecommitdiff
blob: 1aef3599660b8b06d81b5631f6119475582bf0fd (plain)
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
using System;
using System.Collections;
using System.Collections.Generic;

public class EventTimeline
{
	public enum SpawnEventType {alfa, beta};
	
    public class SpawnEvent
	{
		public float time;
		public float height;
		public SpawnEventType type;
		
		public SpawnEvent(float time, float height, SpawnEventType type)
		{
			this.time = time;
			this.height = height;
			this.type = type;
		}
	}
	
	public event Action<SpawnEvent> OnSpawnEvent;
	
	private List<SpawnEvent> futureEvents;
	private float currentTime;
	
	public EventTimeline()
	{
		futureEvents = new List<SpawnEvent>();
		currentTime = 0;
	}
	
	public void Add(float time, float height, SpawnEventType type)
	{
		futureEvents.Add(new SpawnEvent(time, height, type));
		futureEvents.Sort((x,y) => x.time.CompareTo(y.time));
	}
	
	public void timeTick(float deltaTime)
	{
		currentTime += deltaTime;
		
		while(futureEvents.Count > 0 && currentTime > futureEvents[0].time)
		{
			SpawnEvent e = futureEvents[0];
			futureEvents.RemoveAt(0);
			if(OnSpawnEvent != null)
				OnSpawnEvent(e);
		}
	}
}