Skip to content

Feature 144 fix touch #145

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 6 commits into from
Sep 1, 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.
149 changes: 148 additions & 1 deletion Scripts/Camera/CameraTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using UnityEngine;
using IBM.Watson.DeveloperCloud.Logging;
using System.Collections.Generic;

namespace IBM.Watson.DeveloperCloud.Camera
{
Expand All @@ -44,6 +45,15 @@ public class CameraTarget : MonoBehaviour
private bool m_UseTargetObjectToRotate = false;
[SerializeField]
private GameObject m_CustomTargetObjectToLookAt = null;
[SerializeField]
private GameObject m_CameraPathRootObject = null;
[SerializeField]
private float m_RatioAtCameraPath = 0.0f;
[SerializeField]
private Vector3 m_DistanceFromCamera = Vector3.zero;
[SerializeField]
private SplineInterpolator m_SplineInterpolator;
private Transform[] m_PathTransforms;

[SerializeField]
private bool m_TextEnableCamera = false;
Expand Down Expand Up @@ -88,6 +98,74 @@ public bool UseCustomRotation
}
}

/// <summary>
/// Gets or sets the ratio at camera path. It is used if there is path root object assigned to the system
/// </summary>
/// <value>The ratio at camera path.</value>
public float RatioAtCameraPath
{
get
{
return m_RatioAtCameraPath;
}
set
{
m_RatioAtCameraPath = Mathf.Repeat(value, 1.0f);
}
}

/// <summary>
/// Gets or sets the camera path root object.
/// </summary>
/// <value>The camera path root object.</value>
public GameObject CameraPathRootObject
{
get
{
return m_CameraPathRootObject;
}
set
{
m_CameraPathRootObject = value;
}
}

public Vector3 OffsetPosition
{
get
{
return m_OffsetPosition;
}
set
{
m_OffsetPosition = value;
}
}

public Vector3 DistanceFromCamera
{
get
{
return m_DistanceFromCamera;
}
set
{
m_DistanceFromCamera = value;
}
}

public Quaternion OffsetPositionRotation
{
get
{
return m_OffsetPositionRotation;
}
set
{
m_OffsetPositionRotation = value;
}
}

/// <summary>
/// Gets or sets the target position.
/// </summary>
Expand All @@ -96,8 +174,41 @@ public Vector3 TargetPosition
{
get
{
if (m_CameraPathRootObject != null)
{
if (m_PathTransforms == null)
{
List<Transform> childrenTransforms = new List<Transform>(m_CameraPathRootObject.GetComponentsInChildren<Transform>());

childrenTransforms.Remove(m_CameraPathRootObject.transform);
childrenTransforms.Sort(delegate(Transform t1, Transform t2)
{
return t1.name.CompareTo(t2.name);
});

m_PathTransforms = childrenTransforms.ToArray();

if (m_SplineInterpolator == null)
{
m_SplineInterpolator = this.gameObject.GetComponent<SplineInterpolator>();
if (m_SplineInterpolator == null)
m_SplineInterpolator = this.gameObject.AddComponent<SplineInterpolator>();
}

m_SplineInterpolator.SetupSplineInterpolator(m_PathTransforms);
}

if (m_OffsetPosition != Vector3.zero)
{
return m_SplineInterpolator.GetHermiteAtTime(m_RatioAtCameraPath) + (TargetRotation * m_OffsetPosition) + DistanceFromCamera;
}
else
{
return m_SplineInterpolator.GetHermiteAtTime(m_RatioAtCameraPath) + DistanceFromCamera;
}

if (m_UseCustomPosition)
}
else if (m_UseCustomPosition)
{
return m_CustomPosition;
}
Expand Down Expand Up @@ -298,6 +409,42 @@ public void SetTargetPositionWithOffset(Vector3 offsetPosition)
}

#endregion

void OnDrawGizmos()
{
if (m_CameraPathRootObject != null)
{
List<Transform> childrenTransforms = new List<Transform>(m_CameraPathRootObject.GetComponentsInChildren<Transform>());

childrenTransforms.Remove(m_CameraPathRootObject.transform);
childrenTransforms.Sort(delegate(Transform t1, Transform t2)
{
return t1.name.CompareTo(t2.name);
});

m_PathTransforms = childrenTransforms.ToArray();

if (m_SplineInterpolator == null)
{
m_SplineInterpolator = this.gameObject.GetComponent<SplineInterpolator>();
if (m_SplineInterpolator == null)
m_SplineInterpolator = this.gameObject.AddComponent<SplineInterpolator>();
}

m_SplineInterpolator.SetupSplineInterpolator(m_PathTransforms);

Vector3 prevPos = m_PathTransforms[0].position;
for (int c = 1; c <= 100; c++)
{
float currTime = c * 1.0f / 100;
Vector3 currPos = m_SplineInterpolator.GetHermiteAtTime(currTime);
float mag = (currPos - prevPos).magnitude * 2;
Gizmos.color = new Color(mag, 0, 0, 1);
Gizmos.DrawLine(prevPos, currPos);
prevPos = currPos;
}
}
}
}

}
68 changes: 55 additions & 13 deletions Scripts/Utilities/TouchEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ public override int GetHashCode()
return base.GetHashCode();
}

/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="IBM.Watson.DeveloperCloud.Utilities.TouchEventManager+TouchEventData"/>.
/// </summary>
/// <returns>A <see cref="System.String"/> that represents the current <see cref="IBM.Watson.DeveloperCloud.Utilities.TouchEventManager+TouchEventData"/>.</returns>
public override string ToString()
{
return string.Format("[TouchEventData: GameObjectAttached={0}, Collider={1}, Collider2D={2}, RectTransform={3}, ColliderList={4}, ColliderList2D={5}, RectTransformList={6}, IsInside={7}, TapCallback={8}, DragCallback={9}, SortingLayer={10}, CanDragObject={11}]", GameObjectAttached, Collider, Collider2D, RectTransform, ColliderList, ColliderList2D, RectTransformList, IsInside, TapCallback, DragCallback, SortingLayer, CanDragObject);
}

}

#region Private Data
Expand Down Expand Up @@ -383,7 +392,7 @@ public UnityEngine.Camera MainCamera
{
get
{
if (m_mainCamera == null)
if (m_mainCamera == null || !m_mainCamera.transform.CompareTag("MainCamera"))
m_mainCamera = UnityEngine.Camera.main;

return m_mainCamera;
Expand Down Expand Up @@ -1154,7 +1163,9 @@ private void TwoFingerTransformedHandler(object sender, System.EventArgs e)
}
else
{
Log.Warning("TouchEventManager", "There is no 3D collider of given gameobjectToTouch");
#if ENABLE_DEBUGGING
Log.Debug("TouchEventManager", "There is no 3D collider of given gameobjectToTouch");
#endif
}

if (!success)
Expand Down Expand Up @@ -1182,7 +1193,9 @@ private void TwoFingerTransformedHandler(object sender, System.EventArgs e)
success = true;
} else
{
Log.Warning ("TouchEventManager", "There is no 2D collider of given gameobjectToTouch");
#if ENABLE_DEBUGGING
Log.Debug ("TouchEventManager", "There is no 2D collider of given gameobjectToTouch");
#endif
}
}
#if UNITY_4_6 || UNITY_5 || UNITY_5_3_OR_NEWER
Expand Down Expand Up @@ -1211,7 +1224,9 @@ private void TwoFingerTransformedHandler(object sender, System.EventArgs e)
success = true;
} else
{
Log.Warning ("TouchEventManager", "There is no Rect Transform of given gameobjectToTouch");
#if ENABLE_DEBUGGING
Log.Debug ("TouchEventManager", "There is no Rect Transform of given gameobjectToTouch");
#endif
}
}
#endif
Expand Down Expand Up @@ -1258,15 +1273,19 @@ private void TwoFingerTransformedHandler(object sender, System.EventArgs e)
foreach (Collider itemCollider in colliderList)
{
int numberOfRemovedCallbacks = m_TapEvents[layerMaskAsKey].RemoveAll(
e =>
e.Collider == itemCollider &&
e.TapCallback == callback &&
e.SortingLayer == SortingLayer &&
e.IsInside == isTapInside);
e =>
e.Collider == itemCollider &&
e.TapCallback == callback &&
e.SortingLayer == SortingLayer &&
e.IsInside == isTapInside);

success &= (numberOfRemovedCallbacks > 0);
}
}
else
{
success = false;
}

if (!success)
{
Expand All @@ -1286,7 +1305,13 @@ private void TwoFingerTransformedHandler(object sender, System.EventArgs e)
success &= (numberOfRemovedCallbacks > 0);
}
}
else
{
success = false;
}
}


#if UNITY_4_6 || UNITY_5 || UNITY_5_3_OR_NEWER
if (!success)
{
Expand All @@ -1306,6 +1331,10 @@ private void TwoFingerTransformedHandler(object sender, System.EventArgs e)
success &= (numberOfRemovedCallbacks > 0);
}
}
else
{
success = false;
}
}
#endif
}
Expand Down Expand Up @@ -1392,16 +1421,16 @@ private void TapGesture_Tapped(object sender, System.EventArgs e)
{
TouchEventData tapEventData = kp.Value[i];

if (kp.Value[i].Collider == null && kp.Value[i].Collider2D == null && kp.Value[i].RectTransform == null )
if (kp.Value[i].Collider == null && kp.Value[i].Collider2D == null && kp.Value[i].RectTransform == null && kp.Value[i].RectTransformList == null )
{
Log.Warning("TouchEventManager", "Removing invalid collider event receiver from TapEventList");
Log.Warning("TouchEventManager", "Removing invalid collider event receiver from TapEventList from {0}", kp.Value[i].ToString());
kp.Value.RemoveAt(i--);
continue;
}

if (string.IsNullOrEmpty(tapEventData.TapCallback))
{
Log.Warning("TouchEventManager", "Removing invalid event receiver from TapEventList");
Log.Warning("TouchEventManager", "Removing invalid event receiver from TapEventList {0}", kp.Value[i]);
kp.Value.RemoveAt(i--);
continue;
}
Expand Down Expand Up @@ -1801,6 +1830,10 @@ private void TapGesture_Tapped(object sender, System.EventArgs e)
success &= (numberOfRemovedCallbacks > 0);
}
}
else
{
success = false;
}

if (!success)
{
Expand All @@ -1820,6 +1853,11 @@ private void TapGesture_Tapped(object sender, System.EventArgs e)
success &= (numberOfRemovedCallbacks > 0);
}
}
else
{
success = false;
}

}
#if UNITY_4_6 || UNITY_5 || UNITY_5_3_OR_NEWER
if (!success)
Expand All @@ -1840,6 +1878,10 @@ private void TapGesture_Tapped(object sender, System.EventArgs e)
success &= (numberOfRemovedCallbacks > 0);
}
}
else
{
success = false;
}
}
#endif
}
Expand Down Expand Up @@ -1927,7 +1969,7 @@ private void DoubleTapGesture_Tapped(object sender, System.EventArgs e)
{
TouchEventData tapEventData = kp.Value[i];

if (kp.Value[i].Collider == null && kp.Value[i].Collider2D == null && kp.Value[i].RectTransform == null )
if (kp.Value[i].Collider == null && kp.Value[i].Collider2D == null && kp.Value[i].RectTransform == null && kp.Value[i].RectTransformList == null)
{
Log.Warning("TouchEventManager", "Removing invalid collider event receiver from DoubleTapEventList");
kp.Value.RemoveAt(i--);
Expand Down
23 changes: 21 additions & 2 deletions Scripts/Utilities/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,22 @@ public static string StripString(string s)
/// Gets the EPOCH time in UTC time zome
/// </summary>
/// <returns>Double EPOCH in UTC</returns>
public static double GetEpochUTC()
public static double GetEpochUTCMilliseconds()
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return (DateTime.UtcNow - epoch).TotalMilliseconds;
}

/// <summary>
/// Gets the epoch UTC seconds.
/// </summary>
/// <returns>The epoch UTC seconds.</returns>
public static double GetEpochUTCSeconds()
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return (DateTime.UtcNow - epoch).TotalSeconds;
}

/// <summary>
/// Gets the date time from epoch.
/// </summary>
Expand All @@ -293,7 +303,16 @@ public static double GetEpochUTC()
public static DateTime GetLocalDateTimeFromEpoch(double epochTime)
{
DateTime dateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
dateTime = dateTime.AddMilliseconds(epochTime).ToLocalTime();
try
{
dateTime = dateTime.AddSeconds(epochTime).ToLocalTime();
}
catch (ArgumentOutOfRangeException ex)
{
Log.Debug("Utility", "Time conversion assuming time is in Milliseconds: {0}, {1}", epochTime, ex.Message);
dateTime = dateTime.AddMilliseconds(epochTime).ToLocalTime();
}

return dateTime;
}

Expand Down