Subversion Repository Public Repository

Nextrek

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"KickStarter.cs"
 * 
 *	This script will make sure that PersistentEngine and the Player gameObjects are always created,
 *	regardless of which scene the game is begun from.  It will also check the key gameObjects for
 *	essential scripts and references.
 * 
 */

using UnityEngine;
using System.Collections;
using AC;

public class KickStarter : MonoBehaviour
{

	public static void ResetPlayer (Player ref_player, int ID, bool resetReferences)
	{
		// Delete current player
		if (GameObject.FindWithTag (Tags.player))
		{
			Player oldPlayer = GameObject.FindWithTag (Tags.player).GetComponent <Player>();
			DestroyImmediate (oldPlayer.gameObject);
		}

		// Load new player
		Player newPlayer = (Player) Instantiate (ref_player);
		newPlayer.ID = ID;
		newPlayer.name = ref_player.name;

		// Reset player references
		if (resetReferences)
		{
			GameObject.FindWithTag (Tags.gameEngine).SendMessage ("ResetPlayerReference");
			_Camera[] cameras = FindObjectsOfType (typeof (_Camera)) as _Camera[];
			foreach (_Camera camera in cameras)
			{
				camera.ResetTarget ();
			}
		}
	}


	private void Awake ()
	{
		// Test for key imports
		References references = (References) Resources.Load (Resource.references);

		if (references)
		{
			SceneManager sceneManager = AdvGame.GetReferences ().sceneManager;
			SettingsManager settingsManager = AdvGame.GetReferences ().settingsManager;
			ActionsManager actionsManager = AdvGame.GetReferences ().actionsManager;
			InventoryManager inventoryManager = AdvGame.GetReferences ().inventoryManager;
			VariablesManager variablesManager = AdvGame.GetReferences ().variablesManager;
			SpeechManager speechManager = AdvGame.GetReferences ().speechManager;
			CursorManager cursorManager = AdvGame.GetReferences ().cursorManager;
			MenuManager menuManager = AdvGame.GetReferences ().menuManager;
			
			if (sceneManager == null)
			{
				Debug.LogError ("No Scene Manager found - please set one using the Adventure Creator Kit wizard");
			}
			
			if (settingsManager == null)
			{
				Debug.LogError ("No Settings Manager found - please set one using the Adventure Creator Kit wizard");
			}
			else
			{
				if (!GameObject.FindGameObjectWithTag (Tags.player))
				{
					KickStarter.ResetPlayer (AdvGame.GetReferences ().settingsManager.GetDefaultPlayer (), AdvGame.GetReferences ().settingsManager.GetDefaultPlayerID (), false);
				}
			}
			
			if (actionsManager == null)
			{
				Debug.LogError ("No Actions Manager found - please set one using the main Adventure Creator window");
			}
			
			if (inventoryManager == null)
			{
				Debug.LogError ("No Inventory Manager found - please set one using the main Adventure Creator window");
			}
			
			if (variablesManager == null)
			{
				Debug.LogError ("No Variables Manager found - please set one using the main Adventure Creator window");
			}
			
			if (speechManager == null)
			{
				Debug.LogError ("No Speech Manager found - please set one using the main Adventure Creator window");
			}

			if (cursorManager == null)
			{
				Debug.LogError ("No Cursor Manager found - please set one using the main Adventure Creator window");
			}

			if (menuManager == null)
			{
				Debug.LogError ("No Menu Manager found - please set one using the main Adventure Creator window");
			}
			
			if (GameObject.FindWithTag (Tags.player) == null)
			{
				Debug.LogError ("No Player found - please set one using the Settings Manager, tagging it as Player and placing it in a Resources folder");
			}
			
		}
		else
		{
			Debug.LogError ("No References object found. Please set one using the main Adventure Creator window");
		}
		
		if (!GameObject.FindGameObjectWithTag (Tags.persistentEngine))
		{
			try
			{
				GameObject persistentEngine = (GameObject) Instantiate (Resources.Load (Resource.persistentEngine));
				persistentEngine.name = AdvGame.GetName (Resource.persistentEngine);
			}
			catch {}
		}
		
		if (GameObject.FindWithTag (Tags.persistentEngine) == null)
		{
			Debug.LogError ("No PersistentEngine prefab found - please place one in the Resources directory, and tag it as PersistentEngine");
		}
		else
		{
			GameObject persistentEngine = GameObject.FindWithTag (Tags.persistentEngine);
			
			if (persistentEngine.GetComponent <Options>() == null)
			{
				Debug.LogError (persistentEngine.name + " has no Options component attached.");
			}
			if (persistentEngine.GetComponent <RuntimeInventory>() == null)
			{
				Debug.LogError (persistentEngine.name + " has no RuntimeInventory component attached.");
			}
			if (persistentEngine.GetComponent <RuntimeVariables>() == null)
			{
				Debug.LogError (persistentEngine.name + " has no RuntimeVariables component attached.");
			}
			if (persistentEngine.GetComponent <StateHandler>() == null)
			{
				Debug.LogError (persistentEngine.name + " has no StateHandler component attached.");
			}
			if (persistentEngine.GetComponent <SceneChanger>() == null)
			{
				Debug.LogError (persistentEngine.name + " has no SceneChanger component attached.");
			}
			if (persistentEngine.GetComponent <SaveSystem>() == null)
			{
				Debug.LogError (persistentEngine.name + " has no SaveSystem component attached.");
			}
			if (persistentEngine.GetComponent <LevelStorage>() == null)
			{
				Debug.LogError (persistentEngine.name + " has no LevelStorage component attached.");
			}
		}
		
		if (GameObject.FindWithTag (Tags.mainCamera) == null)
		{
			Debug.LogError ("No MainCamera found - please click 'Organise room objects' in the Scene Manager to create one.");
		}
		else
		{
			if (GameObject.FindWithTag (Tags.mainCamera).GetComponent <MainCamera>() == null)
			{
				Debug.LogError ("MainCamera has no MainCamera component.");
			}
		}
		
		if (this.tag == Tags.gameEngine)
		{
			if (this.GetComponent <MenuSystem>() == null)
			{
				Debug.LogError (this.name + " has no MenuSystem component attached.");
			}
			if (this.GetComponent <Dialog>() == null)
			{
				Debug.LogError (this.name + " has no Dialog component attached.");
			}
			if (this.GetComponent <PlayerInput>() == null)
			{
				Debug.LogError (this.name + " has no PlayerInput component attached.");
			}
			if (this.GetComponent <PlayerInteraction>() == null)
			{
				Debug.LogError (this.name + " has no PlayerInteraction component attached.");
			}
			if (this.GetComponent <PlayerMenus>() == null)
			{
				Debug.LogError (this.name + " has no PlayerMenus component attached.");
			}
			if (this.GetComponent <PlayerMovement>() == null)
			{
				Debug.LogError (this.name + " has no PlayerMovement component attached.");
			}
			if
				(this.GetComponent <PlayerCursor>() == null)
			{
				Debug.LogError (this.name + " has no PlayerCursor component attached.");
			}
			if (this.GetComponent <SceneSettings>() == null)
			{
				Debug.LogError (this.name + " has no SceneSettings component attached.");
			}
			else
			{
				if (this.GetComponent <SceneSettings>().navigationMethod == AC_NavigationMethod.meshCollider && this.GetComponent <SceneSettings>().navMesh == null)
				{
					Debug.LogWarning ("No NavMesh set.  Characters will not be able to PathFind until one is defined - please choose one using the Scene Manager.");
				}
				
				if (this.GetComponent <SceneSettings>().defaultPlayerStart == null)
				{
					Debug.LogWarning ("No default PlayerStart set.  The game may not be able to begin if one is not defined - please choose one using the Scene Manager.");
				}
			}
			if (this.GetComponent <RuntimeActionList>() == null)
			{
				Debug.LogError (this.name + " has no RuntimeActionList component attached.");
			}
			if (this.GetComponent <NavigationManager>() == null)
			{
				Debug.LogError (this.name + " has no NavigationManager component attached.");
			}
			if (this.GetComponent <ActionListManager>() == null)
			{
				Debug.LogError (this.name + " has no ActionListManager component attached.");
			}
		}
	}


	public void TurnOnAC ()
	{
		if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <StateHandler>())
		{
			GameObject.FindWithTag (Tags.persistentEngine).GetComponent <StateHandler>().gameState = GameState.Normal;
		}
	}
	
	
	public void TurnOffAC ()
	{
		this.GetComponent <ActionListManager>().KillAllLists ();
		this.GetComponent <Dialog>().KillDialog ();

		Moveable[] moveables = FindObjectsOfType (typeof (Moveable)) as Moveable[];
		foreach (Moveable moveable in moveables)
		{
			moveable.Kill ();
		}
		
		Char[] chars = FindObjectsOfType (typeof (Char)) as Char[];
		foreach (Char _char in chars)
		{
			_char.EndPath ();
		}

		if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <StateHandler>())
		{
			GameObject.FindWithTag (Tags.persistentEngine).GetComponent <StateHandler>().gameState = GameState.Cutscene;
		}
	}
	
}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs

Diff revisions: vs.
Revision Author Commited Message
83 FMMortaroli picture FMMortaroli Tue 13 May, 2014 11:32:51 +0000