Skip to content

Commit

Permalink
Merge pull request #11 from brunomikoski/feature/fix-loop-in-editors
Browse files Browse the repository at this point in the history
Feature/fix loop in editors
  • Loading branch information
brunomikoski authored Jun 1, 2021
2 parents 66b89f2 + cd07abf commit 998fdc3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.5]
### Changed
- Fixed one issue that prevent you from playing the same animation twice on editor
- Limited the `-1 (Infinity lopps)` on editor playback, this was causing some issues so will show a Warning and limit to 3 loops if was set to -1
- Fixed issue when trying to complete the Sequence on editor, now only Stop is available, and will complete all the sequence.


## [0.1.4]
### Added
- Added the `Invoke Callback Step` that uses `Unity Events` to trigger callbacks inside one sequence! Thanks @VladmirCSouza
Expand Down Expand Up @@ -37,7 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### [Unreleased]


[0.1.5]: https://github.com/brunomikoski/Animation-Sequencer/releases/tag/v0.1.5
[0.1.4]: https://github.com/brunomikoski/Animation-Sequencer/releases/tag/v0.1.4
[0.1.3]: https://github.com/brunomikoski/Animation-Sequencer/releases/tag/v0.1.3
[0.1.2]: https://github.com/brunomikoski/Animation-Sequencer/releases/tag/v0.1.2
Expand Down
24 changes: 8 additions & 16 deletions Scripts/Editor/Core/AnimationSequencerControllerCustomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,13 @@ private void DrawPreviewControls()
}
else
{
if (GUILayout.Button("Complete"))
{
Complete();
}

if (GUILayout.Button("Stop"))
{
StopPreview();
}
}
}

private void Complete()
{
sequencerController.Complete();
}

private void Play()
{
if (!Application.isPlaying)
Expand Down Expand Up @@ -218,12 +208,6 @@ private void FindRelatedAnimationControllers()

private void StopPreview()
{
if (!Application.isPlaying)
{
EditorApplication.update -= EditorUpdate;
DOTweenEditorPreview.Stop(true);
}

sequencerController.OnSequenceFinishedPlayingEvent -= StopPreview;
for (int i = 0; i < activeSequencers.Length; i++)
{
Expand All @@ -232,9 +216,17 @@ private void StopPreview()
continue;

animationSequencerController.Stop();
animationSequencerController.Complete();
}

isPreviewPlaying = false;

if (!Application.isPlaying)
{
EditorApplication.update -= EditorUpdate;
DOTweenEditorPreview.Stop(true);
}

Repaint();
}

Expand Down
3 changes: 3 additions & 0 deletions Scripts/Runtime/Core/AnimationSequencerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public void PrepareForPlay(bool force = false)
if (!force && preparedToPlay)
return;

stepsQueue.Clear();
stepsToBePlayed.Clear();

for (int i = 0; i < animationSteps.Length; i++)
animationSteps[i].PrepareForPlay();

Expand Down
26 changes: 21 additions & 5 deletions Scripts/Runtime/Core/Steps/DOTweenAnimationStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ namespace BrunoMikoski.AnimationSequencer
[Serializable]
public sealed class DOTweenAnimationStep : GameObjectAnimationStep
{
private const int EDITOR_MAX_LOOPS = 3;
public override string DisplayName => "Tween Target";
[SerializeField]
private int loopCount;
public int LoopCount
{
get
{
if (Application.isPlaying)
return loopCount;
return loopCount == -1 ? EDITOR_MAX_LOOPS : loopCount;
}
}
[SerializeField]
private LoopType loopType;
[SerializeReference]
Expand All @@ -21,11 +31,11 @@ public override float Duration
{
get
{
if (loopCount == 0)
if (LoopCount == 0)
return duration;
if (loopCount == -1)
if (LoopCount == -1)
return float.MaxValue;
return duration * loopCount;
return duration * LoopCount;
}
}

Expand Down Expand Up @@ -60,13 +70,19 @@ public override void PrepareForPlay()
base.PrepareForPlay();
if (target == null)
{
Debug.LogError($"{target} is null on {typeof(DOTweenAnimationStep)}");
Debug.LogError($"Null target on {typeof(DOTweenAnimationStep)}, ignoring it.");
return;
}

if (!Application.isPlaying)
{
if (loopCount == -1)
Debug.LogWarning($"Infinity Loops are not editor friendly, changing loops into {EDITOR_MAX_LOOPS} for Editor Mode only. Target:{target}");
}

for (int i = 0; i < actions.Length; i++)
{
actions[i].CreateTween(target, duration, loopCount, loopType);
actions[i].CreateTween(target, duration, LoopCount, loopType);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.brunomikoski.animationsequencer",
"displayName": "Animation Sequencer",
"version": "0.1.3",
"version": "0.1.5",
"unity": "2018.4",
"description": "Animation sequencer is a way to create complex animations of sequence of events by a friendly user interface",
"keywords": [
Expand Down

0 comments on commit 998fdc3

Please sign in to comment.