Skip to content

Commit cc11136

Browse files
authored
Merge pull request #84 from watson-developer-cloud/feature-fix-watsoncamera6
Feature fix watsoncamera6
2 parents 2983441 + 5d2a7b1 commit cc11136

File tree

4 files changed

+145
-20
lines changed

4 files changed

+145
-20
lines changed

Config.json.enc

0 Bytes
Binary file not shown.

Scripts/Camera/CameraTarget.cs

Lines changed: 115 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,61 @@ public class CameraTarget : MonoBehaviour
3333
private static UnityEngine.Camera mp_CameraAttached = null;
3434
[SerializeField]
3535
private bool m_UseCustomPosition = false;
36+
[SerializeField]
3637
private Vector3 m_CustomPosition = Vector3.zero;
3738
[SerializeField]
39+
private Vector3 m_OffsetPosition = Vector3.zero;
40+
private Quaternion m_OffsetPositionRotation = Quaternion.identity;
41+
[SerializeField]
3842
private bool m_UseCustomRotation = false;
3943
private Quaternion m_CustomRotation = Quaternion.identity;
4044
private bool m_UseTargetObjectToRotate = false;
45+
[SerializeField]
4146
private GameObject m_CustomTargetObjectToLookAt = null;
4247

48+
[SerializeField]
49+
private bool m_TextEnableCamera = false;
50+
[SerializeField]
51+
private bool m_TestToMakeItCurrent = false;
52+
4353
#endregion
4454

4555
#region Public Members
4656

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+
4791
/// <summary>
4892
/// Gets or sets the target position.
4993
/// </summary>
@@ -57,9 +101,13 @@ public Vector3 TargetPosition
57101
{
58102
return m_CustomPosition;
59103
}
104+
else if (m_OffsetPosition != Vector3.zero)
105+
{
106+
return transform.position + ( Quaternion.Euler(transform.rotation.eulerAngles - m_OffsetPositionRotation.eulerAngles) * m_OffsetPosition);
107+
}
60108
else
61109
{
62-
return transform.position;
110+
return transform.position ;
63111
}
64112
}
65113
set
@@ -77,11 +125,7 @@ public Quaternion TargetRotation
77125
{
78126
get
79127
{
80-
if (m_UseCustomRotation)
81-
{
82-
return m_CustomRotation;
83-
}
84-
else if (m_UseTargetObjectToRotate)
128+
if (m_UseTargetObjectToRotate)
85129
{
86130
if (TargetObject != null)
87131
{
@@ -102,6 +146,10 @@ public Quaternion TargetRotation
102146
return Quaternion.identity;
103147
}
104148
}
149+
else if (m_UseCustomRotation)
150+
{
151+
return m_CustomRotation;
152+
}
105153
else
106154
{
107155
return transform.rotation;
@@ -114,20 +162,36 @@ public Quaternion TargetRotation
114162
}
115163
}
116164

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
118170
{
119171
get
120172
{
121173
return m_CustomTargetObjectToLookAt;
122174
}
123175
set
124176
{
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+
}
127187
}
128188
}
129189

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
131195
{
132196
get
133197
{
@@ -140,7 +204,11 @@ protected UnityEngine.Camera CameraAttached
140204
}
141205
}
142206

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
144212
{
145213
get
146214
{
@@ -156,7 +224,11 @@ protected WatsonCamera WatsonCameraAttached
156224

157225
#region Set Target on Camera
158226

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)
160232
{
161233
if (WatsonCamera.Instance != null)
162234
{
@@ -167,15 +239,21 @@ protected void SetCurrentTargetOnCamera(bool enable)
167239
}
168240
}
169241

170-
protected void SetTargetPositionDefault()
242+
/// <summary>
243+
/// Sets the target position default.
244+
/// </summary>
245+
public void SetTargetPositionDefault()
171246
{
172247
if (WatsonCamera.Instance != null && WatsonCamera.Instance.DefaultCameraTarget != null)
173248
{
174249
TargetPosition = WatsonCamera.Instance.DefaultCameraTarget.TargetPosition;
175250
}
176251
}
177252

178-
protected void SetTargetRotationDefault()
253+
/// <summary>
254+
/// Sets the target rotation default.
255+
/// </summary>
256+
public void SetTargetRotationDefault()
179257
{
180258
if (WatsonCamera.Instance != null && WatsonCamera.Instance.DefaultCameraTarget != null)
181259
{
@@ -184,6 +262,29 @@ protected void SetTargetRotationDefault()
184262
}
185263

186264
#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
187288
}
188289

189290
}

Scripts/Camera/WatsonCamera.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected virtual void CameraPositionOnUpdate()
163163
if (CurrentCameraTarget != null)
164164
{
165165
transform.localPosition = Vector3.Lerp(transform.localPosition, CurrentCameraTarget.TargetPosition, Time.deltaTime * m_SpeedForCameraAnimation);
166-
transform.rotation = Quaternion.Lerp(transform.localRotation, CurrentCameraTarget.TargetRotation, Time.deltaTime * m_SpeedForCameraAnimation);
166+
transform.rotation = Quaternion.Slerp(transform.localRotation, CurrentCameraTarget.TargetRotation, Time.deltaTime * m_SpeedForCameraAnimation);
167167
}
168168
}
169169

@@ -172,9 +172,17 @@ protected virtual void InitializeCameraTargetList()
172172
if (m_ListCameraTarget == null)
173173
m_ListCameraTarget = new List<CameraTarget>();
174174

175+
for (int i = 0; m_ListCameraTarget != null && i < m_ListCameraTarget.Count; i++)
176+
{
177+
Destroy(m_ListCameraTarget[i]);
178+
}
179+
175180
m_ListCameraTarget.Clear();
176181

177-
CameraTarget defaultCameraTarget = this.gameObject.AddComponent<CameraTarget>();
182+
CameraTarget defaultCameraTarget = this.gameObject.GetComponent<CameraTarget>();
183+
if(defaultCameraTarget == null)
184+
defaultCameraTarget = this.gameObject.AddComponent<CameraTarget>();
185+
178186
defaultCameraTarget.TargetPosition = m_CameraInitialLocation;
179187
defaultCameraTarget.TargetRotation = m_CameraInitialRotation;
180188
m_ListCameraTarget.Add(defaultCameraTarget);
@@ -260,6 +268,18 @@ protected virtual void OnCameraSetTwoFingerDrag(System.Object[] args)
260268
}
261269

262270

271+
/// <summary>
272+
/// Event handler reseting the camera. Deleting all camera target and set the initial as default.
273+
/// </summary>
274+
/// <param name="args">Arguments.</param>
275+
protected virtual void ResetCamera(System.Object[] args)
276+
{
277+
if (m_DisableInteractivity)
278+
return;
279+
280+
InitializeCameraTargetList();
281+
}
282+
263283
/// <summary>
264284
/// Event handler reseting the camera position.
265285
/// </summary>
@@ -269,10 +289,11 @@ protected virtual void ResetCameraPosition(System.Object[] args)
269289
if (m_DisableInteractivity)
270290
return;
271291
//Log.Status("WatsonCamera", "Reset Camera Position");
272-
DefaultCameraTarget.TargetPosition = m_CameraInitialLocation;
273-
DefaultCameraTarget.TargetRotation = m_CameraInitialRotation;
292+
CurrentCameraTarget.TargetPosition = m_CameraInitialLocation;
293+
CurrentCameraTarget.TargetRotation = m_CameraInitialRotation;
274294
}
275295

296+
276297
/// <summary>
277298
/// Event handler moving the camera up.
278299
/// </summary>

ThirdParty/WebSocketSharp/WebSocket.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,11 @@ private void fatal (string message, Exception exception)
11251125
var code = exception is WebSocketException
11261126
? ((WebSocketException) exception).Code
11271127
: CloseStatusCode.Abnormal;
1128-
1129-
fatal (message, code);
1128+
1129+
if(exception != null)
1130+
fatal (message + exception.Message + exception.StackTrace, code);
1131+
else
1132+
fatal (message, code);
11301133
}
11311134

11321135
private void fatal (string message, CloseStatusCode code)

0 commit comments

Comments
 (0)