Skip to content

Feature fix watsoncamera6 #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Config.json.enc
Binary file not shown.
129 changes: 115 additions & 14 deletions Scripts/Camera/CameraTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,61 @@ public class CameraTarget : MonoBehaviour
private static UnityEngine.Camera mp_CameraAttached = null;
[SerializeField]
private bool m_UseCustomPosition = false;
[SerializeField]
private Vector3 m_CustomPosition = Vector3.zero;
[SerializeField]
private Vector3 m_OffsetPosition = Vector3.zero;
private Quaternion m_OffsetPositionRotation = Quaternion.identity;
[SerializeField]
private bool m_UseCustomRotation = false;
private Quaternion m_CustomRotation = Quaternion.identity;
private bool m_UseTargetObjectToRotate = false;
[SerializeField]
private GameObject m_CustomTargetObjectToLookAt = null;

[SerializeField]
private bool m_TextEnableCamera = false;
[SerializeField]
private bool m_TestToMakeItCurrent = false;

#endregion

#region Public Members

/// <summary>
/// Gets or sets a value indicating whether this <see cref="IBM.Watson.DeveloperCloud.Camera.CameraTarget"/> use
/// custom position.
/// </summary>
/// <value><c>true</c> if use custom position; otherwise, <c>false</c>.</value>
public bool UseCustomPosition
{
get
{
return m_UseCustomPosition;
}
set
{
m_UseCustomPosition = value;
}
}

/// <summary>
/// Gets or sets a value indicating whether this <see cref="IBM.Watson.DeveloperCloud.Camera.CameraTarget"/> use
/// custom rotation.
/// </summary>
/// <value><c>true</c> if use custom rotation; otherwise, <c>false</c>.</value>
public bool UseCustomRotation
{
get
{
return m_UseCustomRotation;
}
set
{
m_UseCustomRotation = value;
}
}

/// <summary>
/// Gets or sets the target position.
/// </summary>
Expand All @@ -57,9 +101,13 @@ public Vector3 TargetPosition
{
return m_CustomPosition;
}
else if (m_OffsetPosition != Vector3.zero)
{
return transform.position + ( Quaternion.Euler(transform.rotation.eulerAngles - m_OffsetPositionRotation.eulerAngles) * m_OffsetPosition);
}
else
{
return transform.position;
return transform.position ;
}
}
set
Expand All @@ -77,11 +125,7 @@ public Quaternion TargetRotation
{
get
{
if (m_UseCustomRotation)
{
return m_CustomRotation;
}
else if (m_UseTargetObjectToRotate)
if (m_UseTargetObjectToRotate)
{
if (TargetObject != null)
{
Expand All @@ -102,6 +146,10 @@ public Quaternion TargetRotation
return Quaternion.identity;
}
}
else if (m_UseCustomRotation)
{
return m_CustomRotation;
}
else
{
return transform.rotation;
Expand All @@ -114,20 +162,36 @@ public Quaternion TargetRotation
}
}

protected GameObject TargetObject
/// <summary>
/// Gets or sets the target object.
/// </summary>
/// <value>The target object.</value>
public GameObject TargetObject
{
get
{
return m_CustomTargetObjectToLookAt;
}
set
{
m_UseTargetObjectToRotate = true;
m_CustomTargetObjectToLookAt = value;
if (value != null)
{
m_UseTargetObjectToRotate = true;
m_CustomTargetObjectToLookAt = value;
}
else
{
m_UseTargetObjectToRotate = false;
m_CustomTargetObjectToLookAt = null;
}
}
}

protected UnityEngine.Camera CameraAttached
/// <summary>
/// Gets the camera attached.
/// </summary>
/// <value>The camera attached.</value>
public UnityEngine.Camera CameraAttached
{
get
{
Expand All @@ -140,7 +204,11 @@ protected UnityEngine.Camera CameraAttached
}
}

protected WatsonCamera WatsonCameraAttached
/// <summary>
/// Gets the watson camera attached.
/// </summary>
/// <value>The watson camera attached.</value>
public WatsonCamera WatsonCameraAttached
{
get
{
Expand All @@ -156,7 +224,11 @@ protected WatsonCamera WatsonCameraAttached

#region Set Target on Camera

protected void SetCurrentTargetOnCamera(bool enable)
/// <summary>
/// Sets the current target on camera.
/// </summary>
/// <param name="enable">If set to <c>true</c> enable.</param>
public void SetCurrentTargetOnCamera(bool enable)
{
if (WatsonCamera.Instance != null)
{
Expand All @@ -167,15 +239,21 @@ protected void SetCurrentTargetOnCamera(bool enable)
}
}

protected void SetTargetPositionDefault()
/// <summary>
/// Sets the target position default.
/// </summary>
public void SetTargetPositionDefault()
{
if (WatsonCamera.Instance != null && WatsonCamera.Instance.DefaultCameraTarget != null)
{
TargetPosition = WatsonCamera.Instance.DefaultCameraTarget.TargetPosition;
}
}

protected void SetTargetRotationDefault()
/// <summary>
/// Sets the target rotation default.
/// </summary>
public void SetTargetRotationDefault()
{
if (WatsonCamera.Instance != null && WatsonCamera.Instance.DefaultCameraTarget != null)
{
Expand All @@ -184,6 +262,29 @@ protected void SetTargetRotationDefault()
}

#endregion

#region Update

void Update()
{
if (m_TestToMakeItCurrent)
{
m_TestToMakeItCurrent = false;
SetCurrentTargetOnCamera(m_TextEnableCamera);
}
}

#endregion

#region public Functions

public void SetTargetPositionWithOffset(Vector3 offsetPosition)
{
m_OffsetPosition = offsetPosition;
m_OffsetPositionRotation = this.transform.rotation;
}

#endregion
}

}
29 changes: 25 additions & 4 deletions Scripts/Camera/WatsonCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected virtual void CameraPositionOnUpdate()
if (CurrentCameraTarget != null)
{
transform.localPosition = Vector3.Lerp(transform.localPosition, CurrentCameraTarget.TargetPosition, Time.deltaTime * m_SpeedForCameraAnimation);
transform.rotation = Quaternion.Lerp(transform.localRotation, CurrentCameraTarget.TargetRotation, Time.deltaTime * m_SpeedForCameraAnimation);
transform.rotation = Quaternion.Slerp(transform.localRotation, CurrentCameraTarget.TargetRotation, Time.deltaTime * m_SpeedForCameraAnimation);
}
}

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

for (int i = 0; m_ListCameraTarget != null && i < m_ListCameraTarget.Count; i++)
{
Destroy(m_ListCameraTarget[i]);
}

m_ListCameraTarget.Clear();

CameraTarget defaultCameraTarget = this.gameObject.AddComponent<CameraTarget>();
CameraTarget defaultCameraTarget = this.gameObject.GetComponent<CameraTarget>();
if(defaultCameraTarget == null)
defaultCameraTarget = this.gameObject.AddComponent<CameraTarget>();

defaultCameraTarget.TargetPosition = m_CameraInitialLocation;
defaultCameraTarget.TargetRotation = m_CameraInitialRotation;
m_ListCameraTarget.Add(defaultCameraTarget);
Expand Down Expand Up @@ -260,6 +268,18 @@ protected virtual void OnCameraSetTwoFingerDrag(System.Object[] args)
}


/// <summary>
/// Event handler reseting the camera. Deleting all camera target and set the initial as default.
/// </summary>
/// <param name="args">Arguments.</param>
protected virtual void ResetCamera(System.Object[] args)
{
if (m_DisableInteractivity)
return;

InitializeCameraTargetList();
}

/// <summary>
/// Event handler reseting the camera position.
/// </summary>
Expand All @@ -269,10 +289,11 @@ protected virtual void ResetCameraPosition(System.Object[] args)
if (m_DisableInteractivity)
return;
//Log.Status("WatsonCamera", "Reset Camera Position");
DefaultCameraTarget.TargetPosition = m_CameraInitialLocation;
DefaultCameraTarget.TargetRotation = m_CameraInitialRotation;
CurrentCameraTarget.TargetPosition = m_CameraInitialLocation;
CurrentCameraTarget.TargetRotation = m_CameraInitialRotation;
}


/// <summary>
/// Event handler moving the camera up.
/// </summary>
Expand Down
7 changes: 5 additions & 2 deletions ThirdParty/WebSocketSharp/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,11 @@ private void fatal (string message, Exception exception)
var code = exception is WebSocketException
? ((WebSocketException) exception).Code
: CloseStatusCode.Abnormal;

fatal (message, code);

if(exception != null)
fatal (message + exception.Message + exception.StackTrace, code);
else
fatal (message, code);
}

private void fatal (string message, CloseStatusCode code)
Expand Down