@@ -33,17 +33,61 @@ public class CameraTarget : MonoBehaviour
33
33
private static UnityEngine . Camera mp_CameraAttached = null ;
34
34
[ SerializeField ]
35
35
private bool m_UseCustomPosition = false ;
36
+ [ SerializeField ]
36
37
private Vector3 m_CustomPosition = Vector3 . zero ;
37
38
[ SerializeField ]
39
+ private Vector3 m_OffsetPosition = Vector3 . zero ;
40
+ private Quaternion m_OffsetPositionRotation = Quaternion . identity ;
41
+ [ SerializeField ]
38
42
private bool m_UseCustomRotation = false ;
39
43
private Quaternion m_CustomRotation = Quaternion . identity ;
40
44
private bool m_UseTargetObjectToRotate = false ;
45
+ [ SerializeField ]
41
46
private GameObject m_CustomTargetObjectToLookAt = null ;
42
47
48
+ [ SerializeField ]
49
+ private bool m_TextEnableCamera = false ;
50
+ [ SerializeField ]
51
+ private bool m_TestToMakeItCurrent = false ;
52
+
43
53
#endregion
44
54
45
55
#region Public Members
46
56
57
+ /// <summary>
58
+ /// Gets or sets a value indicating whether this <see cref="IBM.Watson.DeveloperCloud.Camera.CameraTarget"/> use
59
+ /// custom position.
60
+ /// </summary>
61
+ /// <value><c>true</c> if use custom position; otherwise, <c>false</c>.</value>
62
+ public bool UseCustomPosition
63
+ {
64
+ get
65
+ {
66
+ return m_UseCustomPosition ;
67
+ }
68
+ set
69
+ {
70
+ m_UseCustomPosition = value ;
71
+ }
72
+ }
73
+
74
+ /// <summary>
75
+ /// Gets or sets a value indicating whether this <see cref="IBM.Watson.DeveloperCloud.Camera.CameraTarget"/> use
76
+ /// custom rotation.
77
+ /// </summary>
78
+ /// <value><c>true</c> if use custom rotation; otherwise, <c>false</c>.</value>
79
+ public bool UseCustomRotation
80
+ {
81
+ get
82
+ {
83
+ return m_UseCustomRotation ;
84
+ }
85
+ set
86
+ {
87
+ m_UseCustomRotation = value ;
88
+ }
89
+ }
90
+
47
91
/// <summary>
48
92
/// Gets or sets the target position.
49
93
/// </summary>
@@ -57,9 +101,13 @@ public Vector3 TargetPosition
57
101
{
58
102
return m_CustomPosition ;
59
103
}
104
+ else if ( m_OffsetPosition != Vector3 . zero )
105
+ {
106
+ return transform . position + ( Quaternion . Euler ( transform . rotation . eulerAngles - m_OffsetPositionRotation . eulerAngles ) * m_OffsetPosition ) ;
107
+ }
60
108
else
61
109
{
62
- return transform . position ;
110
+ return transform . position ;
63
111
}
64
112
}
65
113
set
@@ -77,11 +125,7 @@ public Quaternion TargetRotation
77
125
{
78
126
get
79
127
{
80
- if ( m_UseCustomRotation )
81
- {
82
- return m_CustomRotation ;
83
- }
84
- else if ( m_UseTargetObjectToRotate )
128
+ if ( m_UseTargetObjectToRotate )
85
129
{
86
130
if ( TargetObject != null )
87
131
{
@@ -102,6 +146,10 @@ public Quaternion TargetRotation
102
146
return Quaternion . identity ;
103
147
}
104
148
}
149
+ else if ( m_UseCustomRotation )
150
+ {
151
+ return m_CustomRotation ;
152
+ }
105
153
else
106
154
{
107
155
return transform . rotation ;
@@ -114,20 +162,36 @@ public Quaternion TargetRotation
114
162
}
115
163
}
116
164
117
- protected GameObject TargetObject
165
+ /// <summary>
166
+ /// Gets or sets the target object.
167
+ /// </summary>
168
+ /// <value>The target object.</value>
169
+ public GameObject TargetObject
118
170
{
119
171
get
120
172
{
121
173
return m_CustomTargetObjectToLookAt ;
122
174
}
123
175
set
124
176
{
125
- m_UseTargetObjectToRotate = true ;
126
- m_CustomTargetObjectToLookAt = value ;
177
+ if ( value != null )
178
+ {
179
+ m_UseTargetObjectToRotate = true ;
180
+ m_CustomTargetObjectToLookAt = value ;
181
+ }
182
+ else
183
+ {
184
+ m_UseTargetObjectToRotate = false ;
185
+ m_CustomTargetObjectToLookAt = null ;
186
+ }
127
187
}
128
188
}
129
189
130
- protected UnityEngine . Camera CameraAttached
190
+ /// <summary>
191
+ /// Gets the camera attached.
192
+ /// </summary>
193
+ /// <value>The camera attached.</value>
194
+ public UnityEngine . Camera CameraAttached
131
195
{
132
196
get
133
197
{
@@ -140,7 +204,11 @@ protected UnityEngine.Camera CameraAttached
140
204
}
141
205
}
142
206
143
- protected WatsonCamera WatsonCameraAttached
207
+ /// <summary>
208
+ /// Gets the watson camera attached.
209
+ /// </summary>
210
+ /// <value>The watson camera attached.</value>
211
+ public WatsonCamera WatsonCameraAttached
144
212
{
145
213
get
146
214
{
@@ -156,7 +224,11 @@ protected WatsonCamera WatsonCameraAttached
156
224
157
225
#region Set Target on Camera
158
226
159
- protected void SetCurrentTargetOnCamera ( bool enable )
227
+ /// <summary>
228
+ /// Sets the current target on camera.
229
+ /// </summary>
230
+ /// <param name="enable">If set to <c>true</c> enable.</param>
231
+ public void SetCurrentTargetOnCamera ( bool enable )
160
232
{
161
233
if ( WatsonCamera . Instance != null )
162
234
{
@@ -167,15 +239,21 @@ protected void SetCurrentTargetOnCamera(bool enable)
167
239
}
168
240
}
169
241
170
- protected void SetTargetPositionDefault ( )
242
+ /// <summary>
243
+ /// Sets the target position default.
244
+ /// </summary>
245
+ public void SetTargetPositionDefault ( )
171
246
{
172
247
if ( WatsonCamera . Instance != null && WatsonCamera . Instance . DefaultCameraTarget != null )
173
248
{
174
249
TargetPosition = WatsonCamera . Instance . DefaultCameraTarget . TargetPosition ;
175
250
}
176
251
}
177
252
178
- protected void SetTargetRotationDefault ( )
253
+ /// <summary>
254
+ /// Sets the target rotation default.
255
+ /// </summary>
256
+ public void SetTargetRotationDefault ( )
179
257
{
180
258
if ( WatsonCamera . Instance != null && WatsonCamera . Instance . DefaultCameraTarget != null )
181
259
{
@@ -184,6 +262,29 @@ protected void SetTargetRotationDefault()
184
262
}
185
263
186
264
#endregion
265
+
266
+ #region Update
267
+
268
+ void Update ( )
269
+ {
270
+ if ( m_TestToMakeItCurrent )
271
+ {
272
+ m_TestToMakeItCurrent = false ;
273
+ SetCurrentTargetOnCamera ( m_TextEnableCamera ) ;
274
+ }
275
+ }
276
+
277
+ #endregion
278
+
279
+ #region public Functions
280
+
281
+ public void SetTargetPositionWithOffset ( Vector3 offsetPosition )
282
+ {
283
+ m_OffsetPosition = offsetPosition ;
284
+ m_OffsetPositionRotation = this . transform . rotation ;
285
+ }
286
+
287
+ #endregion
187
288
}
188
289
189
290
}
0 commit comments