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
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"Action.cs"
 * 
 *	This is the base class from which all Actions derive.
 *	We need blank functions Run, ShowGUI and SetLabel,
 *	which will be over-ridden by the subclasses.
 * 
 */

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{
	
	[System.Serializable]
	abstract public class Action : ScriptableObject
	{

		public int numSockets = 1;
		public bool willWait;
		public float defaultPauseTime = 0.1f;
		
		public bool isRunning;
		public int id;
		
		public bool isDisplayed;
		public string title;
		
		public ResultAction endAction = ResultAction.Continue;
		public int skipAction = -1;
		public AC.Action skipActionActual;
		public Cutscene linkedCutscene;

		public bool isMarked = false;
		public bool isEnabled = true;
		public bool isAssetFile = false;

		public Rect nodeRect = new Rect (0,0,300,60);
		
		
		public Action ()
		{
			this.isDisplayed = true;
		}
		
		
		public virtual float Run ()
		{
			return defaultPauseTime;
		}
		
		
		public virtual void ShowGUI () {}
		
		
		public virtual int End (List<Action> actions)
		{
			if (endAction == ResultAction.Stop)
			{
				return -1;
			}
			else if (endAction == ResultAction.Skip)
			{
				int skip = skipAction;
				if (skipActionActual && actions.Contains (skipActionActual))
				{
					skip = actions.IndexOf (skipActionActual);
				}
				else if (skip == -1)
				{
					skip = 0;
				}

				return (skip);
			}
			else if (endAction == ResultAction.RunCutscene && linkedCutscene)
			{	
				return -1;
			}
			
			// Continue as normal
			return 0;
		}
		
		
		#if UNITY_EDITOR
		
		protected void AfterRunningOption ()
		{		
			endAction = (ResultAction) EditorGUILayout.EnumPopup ("After running:", (ResultAction) endAction);
			
			if (endAction == ResultAction.RunCutscene)
			{
				linkedCutscene = (Cutscene) EditorGUILayout.ObjectField ("Cutscene to run", linkedCutscene, typeof (Cutscene), true);
			}
		}
		
		
		public virtual void SkipActionGUI (List<Action> actions, bool showGUI)
		{
			if (skipAction == -1)
			{
				// Set default
				int i = actions.IndexOf (this);
				if (actions.Count > i+1)
				{
					skipAction = i+1;
				}
				else
				{
					skipAction = i;
				}
			}

			int tempSkipAction = skipAction;
			List<string> labelList = new List<string>();

			if (skipActionActual)
			{
				bool found = false;

				for (int i = 0; i < actions.Count; i++)
				{
					labelList.Add (i.ToString () + ": " + actions [i].title);

					if (skipActionActual == actions [i])
					{
						skipAction = i;
						found = true;
					}
				}
				
				if (!found)
				{
					skipAction = tempSkipAction;
				}
			}

			if (skipAction >= actions.Count)
			{
				skipAction = actions.Count - 1;
			}

			if (showGUI)
			{
				if (actions.Count > 1)
				{
					EditorGUILayout.BeginHorizontal();
					EditorGUILayout.LabelField ("  Action to skip to:");
					tempSkipAction = EditorGUILayout.Popup (skipAction, labelList.ToArray());
					EditorGUILayout.EndHorizontal();
					skipAction = tempSkipAction;
				}
				else
				{
					EditorGUILayout.HelpBox ("Cannot skip action - no further Actions available", MessageType.Warning);
					return;
				}
			}

			skipActionActual = actions [skipAction];
		}


		public virtual string SetLabel ()
		{
			return ("");
		}


		public virtual void DrawOutWires (List<Action> actions, int i, int offset)
		{
			if (endAction == ResultAction.Continue || (endAction == ResultAction.Skip && skipAction == i+1))
			{
				if (actions.Count > i+1)
				{
					AdvGame.DrawNodeCurve (nodeRect, actions[i+1].nodeRect, Color.blue, 10);
				}
			}
			else if (endAction == ResultAction.Skip)
			{
				if (actions.Contains (skipActionActual))
				{
					AdvGame.DrawNodeCurve (nodeRect, skipActionActual.nodeRect, Color.blue, 10);
				}
			}
		}

		#endif
		
	}
	
}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/ActionList/Action.cs

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