summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSManager.cs
blob: 0d964012b465804497c47d5115f8b4ac593ec388 (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
using UnityEngine;

namespace Pathfinding.Examples.RTS {
	[HelpURL("https://arongranberg.com/astar/documentation/stable/rtsmanager.html")]
	public class RTSManager : VersionedMonoBehaviour {
		public static RTSManager instance;

		public RTSUnitManager units;

		[UnityEngine.Serialization.FormerlySerializedAs("audio")]
		public RTSAudio audioManager;

		RTSPlayer[] players;

		protected override void Awake () {
			if (instance != null) throw new System.Exception("Multiple RTSManager instances in the scene. You should only have one.");
			instance = this;

			units = new RTSUnitManager();
			units.Awake();

			players = new RTSPlayer[3];
			for (int i = 0; i < players.Length; i++) {
				players[i] = new RTSPlayer();
				players[i].index = i;
			}
		}

		void OnDestroy () {
			units.OnDestroy();
			instance = null;
		}

		public int PlayerCount => players.Length;

		public RTSPlayer GetPlayer (int team) {
			return players[team];
		}
	}
}