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
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"ActionCharMove.cs"
 * 
 *	This action moves characters by assinging them a Paths object.
 *	If a player is moved, the game will automatically pause.
 * 
*/

using UnityEngine;
using System.Collections;
using AC;

#if UNITY_EDITOR
using UnityEditor;
#endif

[System.Serializable]
public class ActionCharMove : Action
{

	public int charToMoveID = 0;
	public int movePathID = 0;
	
	public Paths movePath;
	public bool isPlayer;
	public Char charToMove;
	public bool doTeleport;
	public bool doStop;
	
	
	public ActionCharMove ()
	{
		this.isDisplayed = true;
		title = "Character: Move along path";
	}
	
	
	override public float Run ()
	{
		if (movePath && movePath.GetComponent <Char>())
		{
			Debug.LogWarning ("Can't follow a Path attached to a Character!");
			return 0f;
		}

		if (!isRunning)
		{
			isRunning = true;
			
			if (isPlayer)
			{
				charToMove = GameObject.FindWithTag (Tags.player).GetComponent <Player>();
			}
			else if (isAssetFile && charToMoveID != 0)
			{
				// Attempt to find the correct scene object
				ConstantID idObject = Serializer.returnComponent <ConstantID> (charToMoveID);
				if (idObject != null && idObject.GetComponent <Char>())
				{
					charToMove = idObject.GetComponent <Char>();
				}
			}

			if (isAssetFile && movePathID != 0)
			{
				// Attempt to find the correct scene object
				ConstantID idObject = Serializer.returnComponent <ConstantID> (movePathID);
				if (idObject != null && idObject.GetComponent <Paths>())
				{
					movePath = idObject.GetComponent <Paths>();
				}
				else
				{
					movePath = null;
				}
			}
			
			if (charToMove)
			{
				if (charToMove is NPC)
				{
					NPC npcToMove = (NPC) charToMove;
					npcToMove.FollowReset ();
				}

				if (doStop)
				{
					charToMove.EndPath ();
				}
				else if (movePath)
				{
					if (doTeleport)
					{
						charToMove.transform.position = movePath.transform.position;
						
						// Set rotation if there is more than one node
						if (movePath.nodes.Count > 1)
						{
							charToMove.SetLookDirection (movePath.nodes[1] - movePath.nodes[0], true);
						}
					}
					
					if (isPlayer && movePath.pathType != AC_PathType.ForwardOnly)
					{
						Debug.LogWarning ("Cannot move player along a non-forward only path, as this will create an indefinite cutscene.");
					}
					else
					{
						if (willWait && movePath.pathType != AC_PathType.ForwardOnly)
						{
							willWait = false;
							Debug.LogWarning ("Cannot pause while character moves along a non-forward only path, as this will create an indefinite cutscene.");
						}
						
						charToMove.SetPath (movePath);
					
						if (willWait)
						{
							return defaultPauseTime;
						}
					}
				}
			}

			return 0f;
		}
		else
		{
			if (charToMove.GetPath () != movePath)
			{
				isRunning = false;
				return 0f;
			}
			else
			{
				return (defaultPauseTime);
			}
		}
	}

	
	#if UNITY_EDITOR

	override public void ShowGUI ()
	{
		isPlayer = EditorGUILayout.Toggle ("Is Player?", isPlayer);

		if (!isPlayer)
		{
			charToMove = (Char) EditorGUILayout.ObjectField ("Character to move:", charToMove, typeof(Char), true);

			if (charToMove && charToMove.GetComponent <ConstantID>())
			{
				charToMoveID = charToMove.GetComponent <ConstantID>().constantID;
			}
		}

		doStop = EditorGUILayout.Toggle ("Stop moving?", doStop);
		if (!doStop)
		{
			if (isAssetFile)
			{
				movePathID = EditorGUILayout.IntField ("Path to follow (ID):", movePathID);
			}
			else
			{
				movePath = (Paths) EditorGUILayout.ObjectField ("Path to follow:", movePath, typeof(Paths), true);
			}

			doTeleport = EditorGUILayout.Toggle ("Teleport to start?", doTeleport);
			willWait = EditorGUILayout.Toggle ("Pause until finish?", willWait);

			if (movePath != null && movePath.GetComponent <Char>())
			{
				EditorGUILayout.HelpBox ("Can't follow a Path attached to a Character!", MessageType.Warning);
			}
		}
		
		AfterRunningOption ();
	}
	
	
	override public string SetLabel ()
	{
		string labelAdd = "";
		
		if (charToMove && movePath)
		{
			labelAdd = " (" + charToMove.name + " to " + movePath.name + ")";
		}
		else if (isPlayer && movePath)
		{
			labelAdd = " (Player to " + movePath.name + ")";
		}
		
		return labelAdd;
	}

	#endif
	
}

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

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