Skip to content

Commit

Permalink
Fixed issues with Time.timeScale = 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
valyard committed Jul 29, 2017
1 parent 283e2b6 commit 89e846e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 79 deletions.
4 changes: 2 additions & 2 deletions Source/Assets/TouchScript/Examples/Portal/Scripts/Planet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void Update()
{
case PlanetStatus.Free:
transform.RotateAround(transform.parent.position, Vector3.up,
Speed*Time.deltaTime/transform.localPosition.sqrMagnitude);
Speed * Time.unscaledDeltaTime / transform.localPosition.sqrMagnitude);
break;
case PlanetStatus.Manual:
break;
Expand All @@ -60,7 +60,7 @@ private void Update()
break;
}

transform.Rotate(0, 0, Time.deltaTime*RotationSpeed);
transform.Rotate(0, 0, Time.unscaledDeltaTime * RotationSpeed);
}

void pressedhandler(object sender, System.EventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Rotator : MonoBehaviour

void Update()
{
transform.localRotation *= Quaternion.Euler(0, 0, Time.deltaTime*RotationSpeed);
transform.localRotation *= Quaternion.Euler(0, 0, Time.unscaledDeltaTime * RotationSpeed);
}
}
}
5 changes: 2 additions & 3 deletions Source/Assets/TouchScript/Scripts/Debugging/GL/GLDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Based on http://pastebin.com/69QP1s45
*/


#if TOUCHSCRIPT_DEBUG
#if TOUCHSCRIPT_DEBUG

using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -603,7 +602,7 @@ public float Draw()
{
Lines[i].Draw();
}
return Duration - Time.deltaTime;
return Duration - Time.unscaledDeltaTime;
}
}

Expand Down
14 changes: 7 additions & 7 deletions Source/Assets/TouchScript/Scripts/Gestures/FlickGesture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ protected void LateUpdate()
deltaSequence.Add(ScreenPosition - PreviousScreenPosition);
}

[ContextMenu("Basic Editor")]
private void switchToBasicEditor()
{
basicEditor = true;
}
[ContextMenu("Basic Editor")]
private void switchToBasicEditor()
{
basicEditor = true;
}

#endregion

Expand Down Expand Up @@ -209,7 +209,7 @@ protected override void pointersReleased(IList<Pointer> pointers)
deltaSequence.Add(ScreenPosition - PreviousScreenPosition);

float lastTime;
var deltas = deltaSequence.FindElementsLaterThan(Time.time - FlickTime, out lastTime);
var deltas = deltaSequence.FindElementsLaterThan(Time.unscaledTime - FlickTime, out lastTime);
var totalMovement = Vector2.zero;
var count = deltas.Count;
for (var i = 0; i < count; i++) totalMovement += deltas[i];
Expand All @@ -231,7 +231,7 @@ protected override void pointersReleased(IList<Pointer> pointers)
else
{
ScreenFlickVector = totalMovement;
ScreenFlickTime = Time.time - lastTime;
ScreenFlickTime = Time.unscaledTime - lastTime;
setState(GestureState.Recognized);
}
}
Expand Down
130 changes: 65 additions & 65 deletions Source/Assets/TouchScript/Scripts/Gestures/TapGesture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public event EventHandler<EventArgs> Tapped
/// <summary>
/// Unity event, occurs when gesture is recognized.
/// </summary>
public GestureEvent OnTap = new GestureEvent();
public GestureEvent OnTap = new GestureEvent();

#endregion

Expand Down Expand Up @@ -97,20 +97,20 @@ public float DistanceLimit
/// At the end of a gesture when pointers are lifted off due to the fact that computers are faster than humans the very last pointer's position will be gesture's <see cref="Gesture.ScreenPosition"/> after that. This flag is used to combine several pointers which from the point of a user were lifted off simultaneously and set their centroid as gesture's <see cref="Gesture.ScreenPosition"/>.
/// </remarks>
public bool CombinePointers
{
get { return combinePointers; }
set { combinePointers = value; }
}
{
get { return combinePointers; }
set { combinePointers = value; }
}

/// <summary>
/// Gets or sets time interval before gesture is recognized to combine all lifted pointers into a cluster to use its center as <see cref="Gesture.ScreenPosition"/>.
/// </summary>
/// <value> Time in seconds to treat pointers lifted off during this interval as a single gesture. </value>
public float CombinePointersInterval
{
get { return combinePointersInterval; }
set { combinePointersInterval = value; }
}
{
get { return combinePointersInterval; }
set { combinePointersInterval = value; }
}

#endregion

Expand All @@ -127,12 +127,12 @@ public float CombinePointersInterval
[NullToggle(NullFloatValue = float.PositiveInfinity)]
private float distanceLimit = float.PositiveInfinity;

[SerializeField]
[ToggleLeft]
private bool combinePointers = false;
[SerializeField]
[ToggleLeft]
private bool combinePointers = false;

[SerializeField]
private float combinePointersInterval = .3f;
[SerializeField]
private float combinePointersInterval = .3f;

private float distanceLimitInPixelsSquared;

Expand All @@ -146,18 +146,18 @@ public float CombinePointersInterval

#endregion

#region Public methods
#region Public methods

/// <inheritdoc />
public override bool ShouldReceivePointer(Pointer pointer)
{
if (!base.ShouldReceivePointer(pointer)) return false;
// Ignore redispatched pointers — they come from 2+ pointer gestures when one is left with 1 pointer.
// In this state it means that the user doesn't have an intention to tap the object.
return (pointer.Flags & Pointer.FLAG_RETURNED) == 0;
}
/// <inheritdoc />
public override bool ShouldReceivePointer(Pointer pointer)
{
if (!base.ShouldReceivePointer(pointer)) return false;
// Ignore redispatched pointers — they come from 2+ pointer gestures when one is left with 1 pointer.
// In this state it means that the user doesn't have an intention to tap the object.
return (pointer.Flags & Pointer.FLAG_RETURNED) == 0;
}

#endregion
#endregion

#region Unity methods

Expand All @@ -170,10 +170,10 @@ protected override void OnEnable()
}

[ContextMenu("Basic Editor")]
private void switchToBasicEditor()
{
basicEditor = true;
}
private void switchToBasicEditor()
{
basicEditor = true;
}

#endregion

Expand Down Expand Up @@ -246,43 +246,43 @@ protected override void pointersReleased(IList<Pointer> pointers)
{
base.pointersReleased(pointers);

if (combinePointers)
{
if (combinePointers)
{
var count = pointers.Count;
for (var i = 0; i < count; i++) pointerSequence.Add(pointers[i]);

if (NumPointers == 0)
{
// Checking which points were removed in clusterExistenceTime seconds to set their centroid as cached screen position
var cluster = pointerSequence.FindElementsLaterThan(Time.time - combinePointersInterval, shouldCachePointerPosition);
cachedScreenPosition = ClusterUtils.Get2DCenterPosition(cluster);
cachedPreviousScreenPosition = ClusterUtils.GetPrevious2DCenterPosition(cluster);
}
}
else
{
if (NumPointers == 0)
{
if (!isActive)
{
setState(GestureState.Failed);
return;
}

// pointers outside of gesture target are ignored in shouldCachePointerPosition()
// if all pointers are outside ScreenPosition will be invalid
if (TouchManager.IsInvalidPosition(ScreenPosition))
{
setState(GestureState.Failed);
}
else
{
tapsDone++;
isActive = false;
if (tapsDone >= numberOfTapsRequired) setState(GestureState.Recognized);
}
}
}
for (var i = 0; i < count; i++) pointerSequence.Add(pointers[i]);

if (NumPointers == 0)
{
// Checking which points were removed in clusterExistenceTime seconds to set their centroid as cached screen position
var cluster = pointerSequence.FindElementsLaterThan(Time.unscaledTime - combinePointersInterval, shouldCachePointerPosition);
cachedScreenPosition = ClusterUtils.Get2DCenterPosition(cluster);
cachedPreviousScreenPosition = ClusterUtils.GetPrevious2DCenterPosition(cluster);
}
}
else
{
if (NumPointers == 0)
{
if (!isActive)
{
setState(GestureState.Failed);
return;
}

// pointers outside of gesture target are ignored in shouldCachePointerPosition()
// if all pointers are outside ScreenPosition will be invalid
if (TouchManager.IsInvalidPosition(ScreenPosition))
{
setState(GestureState.Failed);
}
else
{
tapsDone++;
isActive = false;
if (tapsDone >= numberOfTapsRequired) setState(GestureState.Recognized);
}
}
}
}

/// <inheritdoc />
Expand All @@ -293,7 +293,7 @@ protected override void onRecognized()
StopCoroutine("wait");
if (tappedInvoker != null) tappedInvoker.InvokeHandleExceptions(this, EventArgs.Empty);
if (UseSendMessage && SendMessageTarget != null) SendMessageTarget.SendMessage(TAP_MESSAGE, this, SendMessageOptions.DontRequireReceiver);
if (UseUnityEvents) OnTap.Invoke(this);
if (UseUnityEvents) OnTap.Invoke(this);
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion Source/Assets/TouchScript/Scripts/Utils/TimedSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal sealed class TimedSequence<T>

public void Add(T element)
{
Add(element, Time.time);
Add(element, Time.unscaledTime);
}

public void Add(T element, float time)
Expand Down

0 comments on commit 89e846e

Please sign in to comment.