aboutsummaryrefslogtreecommitdiff
blob: 21b0bdb0bbe5cea5d4dcb0c2eb33b06c1dbf0581 (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
using System;
using System.Collections;
using System.Collections.Generic;

public class EventTimeline
{
	public class SpawnEvent
	{
		public float time;
		public float height;
		public ObstacleType type;
		
		public SpawnEvent(float time, float height, ObstacleType 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, ObstacleType 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);
		}
	}
}