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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
using UnityEngine;
using UnityEditor;
using AC;

public class NewGameWizardWindow : EditorWindow
{

	private string gameName = "";

	private int cameraPerspective_int;
	private string[] cameraPerspective_list = { "2D", "2.5D", "3D" };
	private bool screenSpace = false;
	private bool oneScenePerBackground = false;
	private MovementMethod movementMethod = MovementMethod.PointAndClick;

	private InputMethod inputMethod = InputMethod.MouseAndKeyboard;
	private AC_InteractionMethod interactionMethod = AC_InteractionMethod.ContextSensitive;
	private HotspotDetection hotspotDetection = HotspotDetection.MouseOver;

	public bool directControl;
	public bool touchScreen;
	public bool createNewMenu;

	private int pageNumber = 0;
	private References references;

	private int numPages = 6;
	private Texture2D logo = (Texture2D) AssetDatabase.LoadAssetAtPath ("Assets/AdventureCreator/Graphics/Textures/logo.png", typeof (Texture2D));

	// To process
	private CameraPerspective cameraPerspective = CameraPerspective.ThreeD;
	private MovingTurning movingTurning = MovingTurning.TopDown;


	[MenuItem ("Adventure Creator/Getting started/New Game wizard")]
	static void Init ()
	{
		NewGameWizardWindow window = (NewGameWizardWindow) EditorWindow.GetWindow (typeof (NewGameWizardWindow));
		window.GetReferences ();
	}
	
	
	private void GetReferences ()
	{
		references = (References) Resources.Load (Resource.references);
	}


	public void OnInspectorUpdate()
	{
		Repaint();
	}


	private void OnGUI ()
	{
		GUILayout.Label (GetTitle (), EditorStyles.largeLabel);
		if (GetTitle () != "")
		{
			EditorGUILayout.Separator ();
			GUILayout.Space (10f);
		}

		ShowPage ();

		GUILayout.Space (15f);
		GUILayout.BeginHorizontal ();
		if (pageNumber < 1)
		{
			if (pageNumber < 0)
			{
				pageNumber = 0;
			}
			GUI.enabled = false;
		}
		if (pageNumber < numPages)
		{
			if (GUILayout.Button ("Previous", EditorStyles.miniButtonLeft))
			{
				pageNumber --;
			}
		}
		else
		{
			if (GUILayout.Button ("Restart", EditorStyles.miniButtonLeft))
			{
				pageNumber = 1;
				gameName = "";
			}
		}
		GUI.enabled = true;
		if (pageNumber < numPages - 1)
		{
			if (pageNumber == 1 && gameName == "")
			{
				GUI.enabled = false;
			}
			if (GUILayout.Button ("Next", EditorStyles.miniButtonRight))
			{
				pageNumber ++;
				if (pageNumber == numPages - 1)
				{
					Process ();
				}
			}
			GUI.enabled = true;
		}
		else
		{
			if (pageNumber == numPages)
			{
				GUI.enabled = false;
			}
			if (GUILayout.Button ("Finish", EditorStyles.miniButtonRight))
			{
				pageNumber ++;
				Finish ();
			}
			GUI.enabled = true;
		}
		GUILayout.EndHorizontal ();

		GUILayout.Label ("Page " + (pageNumber + 1) + " of " + (numPages + 1));
	}


	private string GetTitle ()
	{
		if (pageNumber == 1)
		{
			return "Game name";
		}
		else if (pageNumber == 2)
		{
			return "Camera perspective";
		}
		else if (pageNumber == 3)
		{
			return "Interface";
		}
		else if (pageNumber == 4)
		{
			return "GUI system";
		}
		else if (pageNumber == 5)
		{
			return "Confirm choices";
		}
		else if (pageNumber == 6)
		{
			return "Complete";
		}

		return "";
	}


	private void Finish ()
	{
		if (!references)
		{
			GetReferences ();
		}
		
		if (!references)
		{
			return;
		}

		string managerPath = gameName + "/Managers";
		try
		{
			System.IO.Directory.CreateDirectory (Application.dataPath + "/" + managerPath);
		}
		catch
		{
			Debug.LogWarning ("Could not create directory: " + Application.dataPath + "/" + managerPath);
			pageNumber --;
			return;
		}

		try
		{
			ScriptableObject t = CustomAssetUtility.CreateAndReturnAsset<SceneManager> ("SceneManager", managerPath);
			AssetDatabase.RenameAsset ("Assets/" + managerPath + "/SceneManager.asset", gameName + "_SceneManager");
			references.sceneManager = (SceneManager) t;

			t = CustomAssetUtility.CreateAndReturnAsset<SettingsManager> ("SettingsManager", managerPath);
			AssetDatabase.RenameAsset ("Assets/" + managerPath + "/SettingsManager.asset", gameName + "_SettingsManager");
			references.settingsManager = (SettingsManager) t;

			references.settingsManager.saveFileName = gameName;
			references.settingsManager.cameraPerspective = cameraPerspective;
			references.settingsManager.movementMethod = movementMethod;
			references.settingsManager.inputMethod = inputMethod;
			references.settingsManager.interactionMethod = interactionMethod;
			references.settingsManager.hotspotDetection = hotspotDetection;
			references.settingsManager.movingTurning = movingTurning;

			t = CustomAssetUtility.CreateAndReturnAsset<ActionsManager> ("ActionsManager", managerPath);
			AssetDatabase.RenameAsset ("Assets/" + managerPath + "/ActionsManager.asset", gameName + "_ActionsManager");
			references.actionsManager = (ActionsManager) t;
			references.actionsManager.RefreshList ();

			t = CustomAssetUtility.CreateAndReturnAsset<VariablesManager> ("VariablesManager", managerPath);
			AssetDatabase.RenameAsset ("Assets/" + managerPath + "/VariablesManager.asset", gameName + "_VariablesManager");
			references.variablesManager = (VariablesManager) t;

			t = CustomAssetUtility.CreateAndReturnAsset<InventoryManager> ("InventoryManager", managerPath);
			AssetDatabase.RenameAsset ("Assets/" + managerPath + "/InventoryManager.asset", gameName + "_InventoryManager");
			references.inventoryManager = (InventoryManager) t;

			t = CustomAssetUtility.CreateAndReturnAsset<SpeechManager> ("SpeechManager", managerPath);
			AssetDatabase.RenameAsset ("Assets/" + managerPath + "/SpeechManager.asset", gameName + "_SpeechManager");
			references.speechManager = (SpeechManager) t;

			if (createNewMenu)
			{
				t = CustomAssetUtility.CreateAndReturnAsset<CursorManager> ("CursorManager", managerPath);
				AssetDatabase.RenameAsset ("Assets/" + managerPath + "/CursorManager.asset", gameName + "_CursorManager");
				references.cursorManager = (CursorManager) t;

				t = CustomAssetUtility.CreateAndReturnAsset<MenuManager> ("MenuManager", managerPath);
				AssetDatabase.RenameAsset ("Assets/" + managerPath + "/MenuManager.asset", gameName + "_MenuManager");
				references.menuManager = (MenuManager) t;
			}
			else
			{
				CursorManager _cursorManager = AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Demo/Managers/Demo_CursorManager.asset", typeof(CursorManager)) as CursorManager;
				references.cursorManager = _cursorManager;

				MenuManager _menuManager = AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Demo/Managers/Demo_MenuManager.asset", typeof(MenuManager)) as MenuManager;
				references.menuManager = _menuManager;
			}

			references.sceneManager.InitialiseObjects ();
		}
		catch
		{
			Debug.LogWarning ("Could not create Manager. Does the subdirectory " + Resource.managersDirectory + " exist?");
			pageNumber --;
		}
	}


	private void Process ()
	{
		if (cameraPerspective_int == 0)
		{
			cameraPerspective = CameraPerspective.TwoD;
			if (screenSpace)
			{
				movingTurning = MovingTurning.ScreenSpace;
			}
			else
			{
				movingTurning = MovingTurning.TopDown;
			}

			movementMethod = MovementMethod.PointAndClick;
			inputMethod = InputMethod.MouseAndKeyboard;
			hotspotDetection = HotspotDetection.MouseOver;
		}
		else if (cameraPerspective_int == 1)
		{
			if (oneScenePerBackground)
			{
				cameraPerspective = CameraPerspective.TwoD;
				movingTurning = MovingTurning.ScreenSpace;
				movementMethod = MovementMethod.PointAndClick;
				inputMethod = InputMethod.MouseAndKeyboard;
				hotspotDetection = HotspotDetection.MouseOver;
			}
			else
			{
				cameraPerspective = CameraPerspective.TwoPointFiveD;

				if (directControl)
				{
					movementMethod = MovementMethod.Direct;
					inputMethod = InputMethod.KeyboardOrController;
					hotspotDetection = HotspotDetection.PlayerVicinity;
				}
				else
				{
					movementMethod = MovementMethod.PointAndClick;
					inputMethod = InputMethod.MouseAndKeyboard;
					hotspotDetection = HotspotDetection.MouseOver;
				}
			}
		}
		else if (cameraPerspective_int == 2)
		{
			cameraPerspective = CameraPerspective.ThreeD;
			hotspotDetection = HotspotDetection.MouseOver;

			if (movementMethod == MovementMethod.PointAndClick)
			{
				inputMethod = InputMethod.MouseAndKeyboard;
			}
			else if (movementMethod == MovementMethod.Direct)
			{
				inputMethod = InputMethod.KeyboardOrController;
				hotspotDetection = HotspotDetection.PlayerVicinity;
			}
			else if (movementMethod == MovementMethod.FirstPerson)
			{
				inputMethod = InputMethod.MouseAndKeyboard;
			}
			else if (movementMethod == MovementMethod.Drag)
			{
				if (touchScreen)
				{
					inputMethod = InputMethod.TouchScreen;
				}
				else
				{
					inputMethod = InputMethod.MouseAndKeyboard;
				}
			}
		}
	}


	private void ShowPage ()
	{
		GUI.skin.label.wordWrap = true;

		if (pageNumber == 0)
		{
			if (logo != null)
			{
				GUILayout.Label (logo);
			}
			GUILayout.Space (5f);
			GUILayout.Label ("Welcome to the New Game Wizard. This window can help you get started with making a new Adventure Creator game.");
			GUILayout.Label ("To begin, click 'Next'. Changes will not be implemented until you are finished.");
		}

		else if (pageNumber == 1)
		{
			GUILayout.Label ("Enter a name for your game. This will be used for filenames, so alphanumeric characters only.");
			gameName = GUILayout.TextField (gameName);
		}
		
		else if (pageNumber == 2)
		{
			GUILayout.Label ("What kind of perspective will your game have?");
			cameraPerspective_int = EditorGUILayout.Popup (cameraPerspective_int, cameraPerspective_list);

			if (cameraPerspective_int == 0)
			{
				GUILayout.Space (5f);
				GUILayout.Label ("By default, 2D games are built entirely in the X-Z plane, and characters are scaled to achieve a depth effect.\nIf you prefer, you can position your characters in 3D space, so that they scale accurately due to camera perspective.");
				screenSpace = EditorGUILayout.ToggleLeft ("I'll position my characters in 3D space", screenSpace);
			}
			else if (cameraPerspective_int == 1)
			{
				GUILayout.Space (5f);
				GUILayout.Label ("2.5D games mixes 3D characters with 2D backgrounds. By default, 2.5D games group several backgrounds into one scene, and swap them out according to the camera angle.\nIf you prefer, you can work with just one background in a scene, to create a more traditional 2D-like adventure.");
				oneScenePerBackground = EditorGUILayout.ToggleLeft ("I'll work with one background per scene", oneScenePerBackground);
			}
			else if (cameraPerspective_int == 2)
			{
				GUILayout.Label ("3D games can still have sprite-based Characters, but having a true 3D environment is more flexible so far as Player control goes. How should your Player character be controlled?");
				movementMethod = (MovementMethod) EditorGUILayout.EnumPopup (movementMethod);
			}
		}

		else if (pageNumber == 3)
		{
			if (cameraPerspective_int == 1 && !oneScenePerBackground)
			{
				GUILayout.Label ("Do you want to control the Player character directly using cursor keys or a controller?");
				directControl = EditorGUILayout.ToggleLeft ("Yes", directControl);
				GUILayout.Space (5f);
			}
			else if (cameraPerspective_int == 2 && movementMethod == MovementMethod.Drag)
			{
				GUILayout.Label ("Is your game designed for Touch-screen devices?");
				touchScreen = EditorGUILayout.ToggleLeft ("Yes", touchScreen);
				GUILayout.Space (5f);
			}

			GUILayout.Label ("How do you want to interact with Hotspots?");
			interactionMethod = (AC_InteractionMethod) EditorGUILayout.EnumPopup (interactionMethod);
			if (interactionMethod == AC_InteractionMethod.ContextSensitive)
			{
				EditorGUILayout.HelpBox ("This method simplifies interactions to either Use, Examine, or Use Inventory. Hotspots can be interacted with in just one click.", MessageType.Info);
			}
			else if (interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot)
			{
				EditorGUILayout.HelpBox ("This method emulates the classic 'Sierra-style' interface, in which the player chooses from a list of verbs, and then the Hotspot they wish to interact with.", MessageType.Info);
			}
			else if (interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction)
			{
				EditorGUILayout.HelpBox ("This method involves first choosing a Hotspot, and then from a range of available interactions, which can be customised in the Editor.", MessageType.Info);
			}
		}

		else if (pageNumber == 4)
		{
			GUILayout.Label ("By default, your game will be set up with the same GUI as the Demo game. Would you prefer to create a new GUI from scratch?");
			createNewMenu = EditorGUILayout.ToggleLeft ("Yes", createNewMenu);
		}

		else if (pageNumber == 5)
		{
			GUILayout.Label ("The following values have been set based on your choices. Please review them and amend if necessary, then click 'Finish' to create your game template.");
			GUILayout.Space (5f);

			gameName = EditorGUILayout.TextField ("Game name:", gameName);
			cameraPerspective_int = (int) cameraPerspective;
			cameraPerspective_int = EditorGUILayout.Popup ("Camera perspective:", cameraPerspective_int, cameraPerspective_list);
			cameraPerspective = (CameraPerspective) cameraPerspective_int;

			if (cameraPerspective == CameraPerspective.TwoD)
			{
				movingTurning = (MovingTurning) EditorGUILayout.EnumPopup ("Moving and turning:", movingTurning);
			}

			movementMethod = (MovementMethod) EditorGUILayout.EnumPopup ("Movement method:", movementMethod);
			inputMethod = (InputMethod) EditorGUILayout.EnumPopup ("Input method:", inputMethod);
			interactionMethod = (AC_InteractionMethod) EditorGUILayout.EnumPopup ("Interaction method:", interactionMethod);
			hotspotDetection = (HotspotDetection) EditorGUILayout.EnumPopup ("Hotspot detection method:", hotspotDetection);

			createNewMenu = EditorGUILayout.Toggle ("Create blank GUI?:", createNewMenu);
		}

		else if (pageNumber == 6)
		{
			GUILayout.Label ("Congratulations, your game's Managers have been set up!");
			GUILayout.Space (5f);
			GUILayout.Label ("Your scene objects have also been organised for Adventure Creator to use. Your next step is to create and set your Player prefab, which you can assign in your Settings Manager.");
		}
	}
}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/Managers/Editor/NewGameWizardWindow.cs

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