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
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"ActionInteraction.cs"
 * 
 *	This Action can enable and disable
 *	a Hotspot's individual Interactions.
 * 
 */

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

#if UNITY_EDITOR
using UnityEditor;
#endif

[System.Serializable]
public class ActionInteraction : Action
{
	
	public Hotspot hotspot;
	public InteractionType interactionType;
	public enum ChangeType { Enable, Disable };
	public ChangeType changeType = ChangeType.Enable;
	public int number = 0;

	
	public ActionInteraction ()
	{
		this.isDisplayed = true;
		title = "Hotspot: Change interaction";
	}
	
	
	override public float Run ()
	{
		if (hotspot == null)
		{
			return 0f;
		}

		if (interactionType == InteractionType.Use)
		{
			if (AdvGame.GetReferences ().settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive)
			{
				ChangeButton (hotspot.useButton);
			}
			else
			{
				// Multiple use interactions
				if (hotspot.useButtons.Count > number)
				{
					ChangeButton (hotspot.useButtons [number]);
				}
			}
		}
		else if (interactionType == InteractionType.Examine)
		{
			ChangeButton (hotspot.lookButton);
		}
		else if (interactionType == InteractionType.Inventory)
		{
			if (hotspot.invButtons.Count > number)
			{
				ChangeButton (hotspot.invButtons [number]);
			}
		}

		return 0f;
	}


	private void ChangeButton (AC.Button button)
	{
		if (button == null)
		{
			return;
		}

		if (changeType == ChangeType.Enable)
		{
			button.isDisabled = false;
		}
		else if (changeType == ChangeType.Disable)
		{
			button.isDisabled = true;
		}
	}
	
	
	#if UNITY_EDITOR
	
	override public void ShowGUI ()
	{
		if (AdvGame.GetReferences () && AdvGame.GetReferences ().settingsManager)
		{
			hotspot = (Hotspot) EditorGUILayout.ObjectField ("Hotspot to change:", hotspot, typeof (Hotspot), true);
			interactionType = (InteractionType) EditorGUILayout.EnumPopup ("Interaction to change:", interactionType);

			if (hotspot != null)
			{
				if (AdvGame.GetReferences ().settingsManager.interactionMethod != AC_InteractionMethod.ContextSensitive && interactionType == InteractionType.Use)
				{
					if (AdvGame.GetReferences ().cursorManager)
					{
						// Multiple use interactions
						List<string> labelList = new List<string>();
						
						foreach (AC.Button button in hotspot.useButtons)
						{
							labelList.Add (hotspot.useButtons.IndexOf (button) + ": " + AdvGame.GetReferences ().cursorManager.GetLabelFromID (button.iconID));
						}
						
						number = EditorGUILayout.Popup ("Use interaction:", number, labelList.ToArray ());
					}
					else
					{
						EditorGUILayout.HelpBox ("A Cursor Manager is required.", MessageType.Warning);
					}
				}
				else if (interactionType == InteractionType.Inventory)
				{
					if (AdvGame.GetReferences ().inventoryManager)
					{
						List<string> labelList = new List<string>();

						foreach (AC.Button button in hotspot.invButtons)
						{
							labelList.Add (hotspot.invButtons.IndexOf (button) + ": " + AdvGame.GetReferences ().inventoryManager.GetLabel (button.invID));
						}

						number = EditorGUILayout.Popup ("Inventory interaction:", number, labelList.ToArray ());
					}
					else
					{
						EditorGUILayout.HelpBox ("An Inventory Manager is required.", MessageType.Warning);
					}
				}
			}

			changeType = (ChangeType) EditorGUILayout.EnumPopup ("Change to make:", changeType);
		}
		else
		{
			EditorGUILayout.HelpBox ("A Settings Manager is required for this Action.", MessageType.Warning);
		}

		AfterRunningOption ();
	}
	
	
	public override string SetLabel ()
	{
		string labelAdd = "";
		if (hotspot != null)
		{
			labelAdd = " (" + hotspot.name + " - " + changeType + " " + interactionType;
			labelAdd += ")";
		}
		return labelAdd;
	}
	
	#endif
	
}

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

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