Skip to content

Commit

Permalink
bugfix: erroneous float manipulation cancellations
Browse files Browse the repository at this point in the history
no overlap, but still preventing multiple manipulations on a single transform.
more explicite with manipulation types by introducing ManipulationType enum.
  • Loading branch information
williamrjackson committed May 13, 2021
1 parent b0281fb commit 279f8e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
9 changes: 6 additions & 3 deletions ScreenBorders.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;

namespace Wrj
{
Expand All @@ -11,8 +11,11 @@ public class ScreenBorders : MonoBehaviour
[SerializeField] private ScreenBorder ceiling;

void Start()
{
Wrj.ScreenSizeNotifier.Instance.OnScreenChange += SetBorders;
{
if (Application.isPlaying)
{
Wrj.ScreenSizeNotifier.Instance.OnScreenChange += SetBorders;
}
}
#if UNITY_EDITOR
void Update()
Expand Down
Binary file modified UnityScriptingUtilities.unitypackage
Binary file not shown.
29 changes: 15 additions & 14 deletions WrjUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,19 @@ public class Manipulation
public Coroutine coroutine;
public Transform transform;
public int iterationCount = 0;
private string type;
public enum ManipulationType {Scale, Move, Rotate, Audio, Color, Alpha, NotApplicable}
private ManipulationType type;
public bool IsRunning => coroutine != null;

public Manipulation(string _type, Transform _transform)
public Manipulation(ManipulationType _type, Transform _transform)
{
type = _type;
transform = _transform;
if (wrjInstance == null)
return;
foreach(Manipulation mcp in wrjInstance.m_ManipulationList)
{
if (mcp.transform == transform && mcp.type == type && type != "")
if (mcp.transform == transform && mcp.type == type && type != ManipulationType.NotApplicable)
{
mcp.Stop();
}
Expand Down Expand Up @@ -349,7 +350,7 @@ public static float MirrorLerp(AnimationCurve c, float a, float b, float time)
// Period-based Manipulation Coroutines...
public Manipulation Scale(Transform tform, Vector3 to, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Scale", tform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Scale, tform);
mcp.coroutine = UtilObject().StartCoroutine(ScaleLocal(mcp, tform, to, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, onDone));
UtilObject().AddToCoroList(mcp);
return mcp;
Expand Down Expand Up @@ -400,7 +401,7 @@ private IEnumerator ScaleLocal(Manipulation mcp, Transform tform, Vector3 to, fl

public Manipulation Move(Transform tform, Vector3 to, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, bool pendulum = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Move", tform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Move, tform);
mcp.coroutine = UtilObject().StartCoroutine(MoveLocal(mcp, tform, to, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, pendulum, onDone));
UtilObject().AddToCoroList(mcp);
return mcp;
Expand Down Expand Up @@ -456,7 +457,7 @@ private IEnumerator MoveLocal(Manipulation mcp, Transform tform, Vector3 to, flo

public Manipulation MoveWorld(Transform tform, Vector3 to, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, bool pendulum = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Move", tform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Move, tform);
mcp.coroutine = UtilObject().StartCoroutine(MoveWorldspace(mcp, tform, to, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, pendulum, onDone));
UtilObject().AddToCoroList(mcp);
return mcp;
Expand Down Expand Up @@ -513,15 +514,15 @@ private IEnumerator MoveWorldspace(Manipulation mcp, Transform tform, Vector3 to

public Manipulation MoveAlongPath(Transform tform, BezierPath path, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, bool inverse = false, bool align = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Move", tform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Move, tform);
mcp.coroutine = UtilObject().StartCoroutine(MovePath(mcp, tform, path.Curve, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, inverse, align, onDone));
UtilObject().AddToCoroList(mcp);
return mcp;
}

public Manipulation MoveAlongPath(Transform tform, Vector3[] path, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, bool inverse = false, bool align = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Move", tform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Move, tform);
mcp.coroutine = UtilObject().StartCoroutine(MovePath(mcp, tform, path, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, inverse, align, onDone));
UtilObject().AddToCoroList(mcp);
return mcp;
Expand Down Expand Up @@ -571,7 +572,7 @@ private IEnumerator MovePath(Manipulation mcp, Transform tform, Vector3[] path,
}
public Manipulation Rotate(Transform tform, Vector3 eulerTo, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, bool shortestPath = true, bool pendulum = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Rotate", tform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Rotate, tform);
if (shortestPath)
{
mcp.coroutine = UtilObject().StartCoroutine(RotateLocalQuaternionLerp(mcp, tform, tform.rotation, Quaternion.Euler(eulerTo.x, eulerTo.y, eulerTo.z), duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, pendulum, onDone));
Expand Down Expand Up @@ -685,7 +686,7 @@ private IEnumerator RotateLocal(Manipulation mcp, Transform tform, Vector3 from,
/// </summary>
public Manipulation ManipulateFloat(System.Action<float> receiver, float init, float target, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Float", UtilObject().transform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.NotApplicable, UtilObject().transform);
mcp.coroutine = UtilObject().StartCoroutine(FloatManip(mcp, receiver, init, target, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, onDone));
UtilObject().AddToCoroList(mcp);
return mcp;
Expand Down Expand Up @@ -731,7 +732,7 @@ private IEnumerator FloatManip(Manipulation mcp, System.Action<float> receiver,

public Manipulation FadeAudio(AudioSource audioSource, float targetVol, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Fade", audioSource.transform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Audio, audioSource.transform);
mcp.coroutine = UtilObject().StartCoroutine(Fade(mcp, audioSource, targetVol, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, onDone));
UtilObject().AddToCoroList(mcp);
return mcp;
Expand Down Expand Up @@ -781,7 +782,7 @@ private IEnumerator Fade(Manipulation mcp, AudioSource audioSource, float target

public Manipulation CrossFadeAudio(AudioSource from, AudioSource to, float targetVol, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Fade", from.transform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Audio, from.transform);
mcp.coroutine = UtilObject().StartCoroutine(CrossFade(mcp, from, to, targetVol, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, onDone));
UtilObject().AddToCoroList(mcp);
return mcp;
Expand Down Expand Up @@ -836,7 +837,7 @@ private IEnumerator CrossFade(Manipulation mcp, AudioSource from, AudioSource to

public Manipulation FadeAlpha(Transform tform, float to, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Alpha", tform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Alpha, tform);
if (tform.GetComponent<UnityEngine.UI.Image>())
{
mcp.coroutine = UtilObject().StartCoroutine(LerpImageAlpha(mcp, tform.GetComponent<UnityEngine.UI.Image>(), to, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, onDone));
Expand Down Expand Up @@ -959,7 +960,7 @@ private IEnumerator LerpImageAlpha(Manipulation mcp, UnityEngine.UI.Image image,

public Manipulation ChangeColor(Transform tform, Color to, float duration, bool mirrorCurve = false, int loop = 0, int pingPong = 0, int mirrorPingPong = 0, bool useTimeScale = false, OnDone onDone = null)
{
Manipulation mcp = new Manipulation("Color", tform);
Manipulation mcp = new Manipulation(Manipulation.ManipulationType.Color, tform);
if (tform.GetComponent<UnityEngine.UI.Image>())
{
mcp.coroutine = UtilObject().StartCoroutine(LerpImageColor(mcp, tform.GetComponent<UnityEngine.UI.Image>(), to, duration, mirrorCurve, loop, pingPong, mirrorPingPong, useTimeScale, onDone));
Expand Down

0 comments on commit 279f8e3

Please sign in to comment.