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
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"ActionNavMesh.cs"
 * 
 *	This action changes the active NavMesh.
 *	All NavMeshes must be on the same unique layer.
 * 
 */

using UnityEngine;
using System.Collections;
using AC;

#if UNITY_EDITOR
using UnityEditor;
#endif

[System.Serializable]
public class ActionNavMesh : Action
{

	public int constantID = 0;
	public NavigationMesh newNavMesh;
	public SortingMap sortingMap;
	public PlayerStart playerStart;
	public Cutscene cutscene;
	public SceneSetting sceneSetting = SceneSetting.DefaultNavMesh;
	
	public ActionNavMesh ()
	{
		this.isDisplayed = true;
		title = "Engine: Change scene setting";
	}
	
	
	override public float Run ()
	{
		if (isAssetFile && constantID != 0)
		{
			newNavMesh = null;
			sortingMap = null;
			playerStart = null;
			cutscene = null;

			// Attempt to find the correct scene object
			ConstantID idObject = Serializer.returnComponent <ConstantID> (constantID);
			if (idObject != null)
			{
				if (sceneSetting == SceneSetting.DefaultNavMesh)
				{
					if (idObject.GetComponent <NavigationMesh>())
					{
						newNavMesh = idObject.GetComponent <NavigationMesh>();
					}
					else 
					{
						Debug.LogWarning ("Cannot change NavMesh because referenced object has no NavigationMesh component!");
					}
				}
				else if (sceneSetting == SceneSetting.DefaultPlayerStart)
				{
					if (idObject.GetComponent <PlayerStart>())
					{
						playerStart = idObject.GetComponent <PlayerStart>();
					}
					else 
					{
						Debug.LogWarning ("Cannot change PlayerStart because referenced object has no PlayerStart component!");
					}
				}
				else if (sceneSetting == SceneSetting.SortingMap)
				{
					if (idObject.GetComponent <SortingMap>())
					{
						sortingMap = idObject.GetComponent <SortingMap>();
					}
					else 
					{
						Debug.LogWarning ("Cannot change SortingMap because referenced object has no SortingMap component!");
					}
				}
				else if (sceneSetting == SceneSetting.OnLoadCutscene || sceneSetting == SceneSetting.OnStartCutscene)
				{
					if (idObject.GetComponent <Cutscene>())
					{
						cutscene = idObject.GetComponent <Cutscene>();
					}
					else 
					{
						Debug.LogWarning ("Cannot change Cutscene because referenced object has no Cutscene component!");
					}
				}
			}
		}

		SceneSettings sceneSettings = GameObject.FindWithTag (Tags.gameEngine).GetComponent <SceneSettings>();

		if (sceneSetting == SceneSetting.DefaultNavMesh && newNavMesh)
		{
			NavigationMesh oldNavMesh = sceneSettings.navMesh;
			oldNavMesh.TurnOff ();
			newNavMesh.TurnOn ();
			sceneSettings.navMesh = newNavMesh;

			if (newNavMesh.GetComponent <ConstantID>() == null)
			{
				Debug.LogWarning ("Warning: Changing to new NavMesh with no ConstantID - change will not be recognised by saved games.");
			}
		}
		else if (sceneSetting == SceneSetting.DefaultPlayerStart && playerStart)
		{
			sceneSettings.defaultPlayerStart = playerStart;

			if (playerStart.GetComponent <ConstantID>() == null)
			{
				Debug.LogWarning ("Warning: Changing to new default PlayerStart with no ConstantID - change will not be recognised by saved games.");
			}
		}
		else if (sceneSetting == SceneSetting.SortingMap && sortingMap)
		{
			sceneSettings.sortingMap = sortingMap;

			// Reset all FollowSortingMap components
			FollowSortingMap[] followSortingMaps = FindObjectsOfType (typeof (FollowSortingMap)) as FollowSortingMap[];
			foreach (FollowSortingMap followSortingMap in followSortingMaps)
			{
				followSortingMap.UpdateSortingMap ();
			}

			if (sortingMap.GetComponent <ConstantID>() == null)
			{
				Debug.LogWarning ("Warning: Changing to new SortingMap with no ConstantID - change will not be recognised by saved games.");
			}
		}
		else if (sceneSetting == SceneSetting.OnLoadCutscene)
		{
			sceneSettings.cutsceneOnLoad = cutscene;

			if (cutscene.GetComponent <ConstantID>() == null)
			{
				Debug.LogWarning ("Warning: Changing to Cutscene On Load with no ConstantID - change will not be recognised by saved games.");
			}
		}
		else if (sceneSetting == SceneSetting.OnStartCutscene)
		{
			sceneSettings.cutsceneOnStart = cutscene;

			if (cutscene.GetComponent <ConstantID>() == null)
			{
				Debug.LogWarning ("Warning: Changing to Cutscene On Start with no ConstantID - change will not be recognised by saved games.");
			}
		}
		
		return 0f;
	}
	

	#if UNITY_EDITOR

	override public void ShowGUI ()
	{
		SceneSettings sceneSettings = null;
		if (GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent <SceneSettings>())
		{
			sceneSettings = GameObject.FindWithTag (Tags.gameEngine).GetComponent <SceneSettings>();
		}

		sceneSetting = (SceneSetting) EditorGUILayout.EnumPopup ("Scene setting to change:", sceneSetting);

		if (sceneSettings == null)
		{
			return;
		}

		if (sceneSetting == SceneSetting.DefaultNavMesh)
		{
			if (sceneSettings.navigationMethod == AC_NavigationMethod.meshCollider)
			{
				if (isAssetFile)
				{
					constantID = EditorGUILayout.IntField ("New NavMesh (ID):", constantID);
				}
				else
				{
					newNavMesh = (NavigationMesh) EditorGUILayout.ObjectField ("New NavMesh:", newNavMesh, typeof (NavigationMesh), true);
				}
			}
			else
			{
				EditorGUILayout.HelpBox ("This action is only compatible with the Mesh Collider\nNavigation method, as set in the Scene Manager.", MessageType.Warning);
			}
		}
		else if (sceneSetting == SceneSetting.DefaultPlayerStart)
		{
			if (isAssetFile)
			{
				constantID = EditorGUILayout.IntField ("New default PlayerStart (ID):", constantID);
			}
			else
			{
				playerStart = (PlayerStart) EditorGUILayout.ObjectField ("New default PlayerStart:", playerStart, typeof (PlayerStart), true);
			}
		}
		else if (sceneSetting == SceneSetting.SortingMap)
		{
			if (isAssetFile)
			{
				constantID = EditorGUILayout.IntField ("New SortingMap (ID):", constantID);
			}
			else
			{
				sortingMap = (SortingMap) EditorGUILayout.ObjectField ("New SortingMap:", sortingMap, typeof (SortingMap), true);
			}
		}
		else if (sceneSetting == SceneSetting.OnLoadCutscene)
		{
			if (isAssetFile)
			{
				constantID = EditorGUILayout.IntField ("New OnLoad cutscene (ID):", constantID);
			}
			else
			{
				cutscene = (Cutscene) EditorGUILayout.ObjectField ("New OnLoad custscne:", cutscene, typeof (Cutscene), true);
			}
		}
		else if (sceneSetting == SceneSetting.OnStartCutscene)
		{
			if (isAssetFile)
			{
				constantID = EditorGUILayout.IntField ("New OnStart cutscene (ID):", constantID);
			}
			else
			{
				cutscene = (Cutscene) EditorGUILayout.ObjectField ("New OnStart cutscene:", cutscene, typeof (Cutscene), true);
			}
		}
		
		AfterRunningOption ();
	}
	
	
	override public string SetLabel ()
	{
		string labelAdd = "";
		
		labelAdd = " (" + sceneSetting.ToString () + ")";

		return labelAdd;
	}

	#endif
	
}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/Actions/ActionNavMesh.cs

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