| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | namespace DCL.Tutorial |
| | 4 | | { |
| | 5 | | /// <summary> |
| | 6 | | /// This class coordinates the step animations with the animations of any action object that can exist as child. |
| | 7 | | /// </summary> |
| | 8 | | public class TutorialStepAction : MonoBehaviour |
| | 9 | | { |
| 1 | 10 | | protected static int KEY_LOOP_ANIMATOR_BOOL = Animator.StringToHash("KeyLoop"); |
| | 11 | |
|
| | 12 | | [SerializeField] internal TutorialStep step; |
| | 13 | |
|
| | 14 | | private Animator actionAnimator; |
| | 15 | |
|
| | 16 | | private void Start() |
| | 17 | | { |
| 3 | 18 | | actionAnimator = GetComponent<Animator>(); |
| | 19 | |
|
| 3 | 20 | | if (actionAnimator != null) |
| 3 | 21 | | actionAnimator.SetBool(KEY_LOOP_ANIMATOR_BOOL, false); |
| | 22 | |
|
| 3 | 23 | | if (step != null) |
| | 24 | | { |
| 3 | 25 | | step.OnShowAnimationFinished += Step_OnShowAnimationFinished; |
| 3 | 26 | | step.OnJustAfterStepExecuted += Step_OnJustAfterStepExecuted; |
| | 27 | | } |
| 3 | 28 | | } |
| | 29 | |
|
| | 30 | | private void OnDestroy() |
| | 31 | | { |
| 3 | 32 | | if (step != null) |
| | 33 | | { |
| 3 | 34 | | step.OnShowAnimationFinished -= Step_OnShowAnimationFinished; |
| 3 | 35 | | step.OnJustAfterStepExecuted -= Step_OnJustAfterStepExecuted; |
| | 36 | | } |
| 3 | 37 | | } |
| | 38 | |
|
| | 39 | | private void Step_OnShowAnimationFinished() |
| | 40 | | { |
| 0 | 41 | | if (actionAnimator != null) |
| 0 | 42 | | actionAnimator.SetBool(KEY_LOOP_ANIMATOR_BOOL, true); |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | private void Step_OnJustAfterStepExecuted() |
| | 46 | | { |
| 3 | 47 | | if (actionAnimator != null) |
| 3 | 48 | | actionAnimator.SetBool(KEY_LOOP_ANIMATOR_BOOL, false); |
| 3 | 49 | | } |
| | 50 | | } |
| | 51 | | } |