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
|
/*
*
* Adventure Creator
* by Chris Burton, 2013-2014
*
* "ActionCharFace.cs"
*
* This action is used to make characters turn to face GameObjects.
*
*/
using UnityEngine;
using System.Collections;
using AC;
#if UNITY_EDITOR
using UnityEditor;
#endif
[System.Serializable]
public class ActionCharFace : Action
{
public int charToMoveID = 0;
public int faceObjectID = 0;
public bool isInstant;
public Char charToMove;
public GameObject faceObject;
public bool copyRotation;
public bool facePlayer;
public bool isPlayer;
public bool lookUpDown;
public ActionCharFace ()
{
this.isDisplayed = true;
title = "Character: Face object";
}
override public float Run ()
{
if (!isRunning)
{
isRunning = true;
if (isPlayer)
{
charToMove = GameObject.FindWithTag (Tags.player).GetComponent <Player>();
}
else if (facePlayer)
{
faceObject = GameObject.FindWithTag (Tags.player);
}
if (isAssetFile)
{
if (!isPlayer && 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 (!facePlayer && faceObjectID != 0)
{
// Attempt to find the correct scene object
ConstantID idObject = Serializer.returnComponent <ConstantID> (faceObjectID);
if (idObject != null)
{
faceObject = idObject.gameObject;
}
}
}
if (charToMove && faceObject)
{
FirstPersonCamera firstPersonCamera = null;
if (GameObject.FindWithTag (Tags.firstPersonCamera) && GameObject.FindWithTag (Tags.firstPersonCamera).GetComponent <FirstPersonCamera>())
{
firstPersonCamera = GameObject.FindWithTag (Tags.firstPersonCamera).GetComponent <FirstPersonCamera>();
}
SettingsManager settingsManager = AdvGame.GetReferences ().settingsManager;
Vector3 lookVector = faceObject.transform.position - charToMove.transform.position;
if (copyRotation)
{
lookVector = faceObject.transform.forward;
}
else if (settingsManager.ActInScreenSpace ())
{
lookVector = AdvGame.GetScreenDirection (charToMove.transform.position, faceObject.transform.position);
}
lookVector.y = 0;
if (settingsManager && settingsManager.movementMethod == MovementMethod.FirstPerson && lookUpDown)
{
if (firstPersonCamera)
{
firstPersonCamera.SetTilt (faceObject.transform.position, isInstant);
}
else
{
Debug.LogWarning ("Cannot tilt player, since no FirstPersonCamera script was found");
}
}
if (isInstant)
{
charToMove.SetLookDirection (lookVector, true);
return 0f;
}
else
{
charToMove.Halt ();
charToMove.SetLookDirection (lookVector, false);
if (willWait)
{
return (defaultPauseTime);
}
else
{
return 0f;
}
}
}
return 0f;
}
else
{
if (!charToMove.IsTurning ())
{
isRunning = false;
return 0f;
}
else
{
return (defaultPauseTime);
}
}
}
#if UNITY_EDITOR
override public void ShowGUI ()
{
isPlayer = EditorGUILayout.Toggle ("Affect Player?", isPlayer);
if (!isPlayer)
{
charToMove = (Char) EditorGUILayout.ObjectField ("Character to turn:", charToMove, typeof(Char), true);
facePlayer = EditorGUILayout.Toggle ("Face player?", facePlayer);
if (charToMove && charToMove.GetComponent <ConstantID>())
{
charToMoveID = charToMove.GetComponent <ConstantID>().constantID;
}
}
else
{
facePlayer = false;
SettingsManager settingsManager = AdvGame.GetReferences ().settingsManager;
if (settingsManager && settingsManager.movementMethod == MovementMethod.FirstPerson)
{
lookUpDown = EditorGUILayout.Toggle ("1st-person head tilt?", lookUpDown);
}
}
if (!facePlayer)
{
if (isAssetFile)
{
faceObjectID = EditorGUILayout.IntField ("Object to face (ID):", faceObjectID);
}
else
{
faceObject = (GameObject) EditorGUILayout.ObjectField ("Object to face:", faceObject, typeof(GameObject), true);
}
}
copyRotation = EditorGUILayout.Toggle ("Use object's rotation?", copyRotation);
isInstant = EditorGUILayout.Toggle ("Is instant?", isInstant);
if (!isInstant)
{
willWait = EditorGUILayout.Toggle ("Pause until finish?", willWait);
}
AfterRunningOption ();
}
override public string SetLabel ()
{
string labelAdd = "";
if (charToMove && faceObject)
{
labelAdd = " (" + charToMove.name + " to " + faceObject.name + ")";
}
else if (isPlayer && faceObject)
{
labelAdd = " (Player to " + faceObject.name + ")";
}
return labelAdd;
}
#endif
}
|
Revision |
Author |
Commited |
Message |
83
|
FMMortaroli
|
Tue 13 May, 2014 11:32:51 +0000 |
|