TimeScale.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik //
  2. using UnityEngine;
  3. namespace Animancer.Examples
  4. {
  5. /// <summary>A simple Inspector slider to control <see cref="Time.timeScale"/>.</summary>
  6. /// <remarks>
  7. /// Documentation: <see href="https://kybernetik.com.au/animancer/docs/examples/basics/scene-setup#time-scale">Time Scale</see>
  8. /// </remarks>
  9. /// https://kybernetik.com.au/animancer/api/Animancer.Examples/TimeScale
  10. ///
  11. [AddComponentMenu(Strings.ExamplesMenuPrefix + "Time Scale")]
  12. [HelpURL(Strings.DocsURLs.APIDocumentation + "." + nameof(Examples) + "/" + nameof(TimeScale))]
  13. public sealed class TimeScale : MonoBehaviour
  14. {
  15. /************************************************************************************************************************/
  16. [SerializeField, Range(0, 1)]
  17. private float _Value = 0.5f;
  18. public float Value
  19. {
  20. get => _Value;
  21. set
  22. {
  23. _Value = value;
  24. #if UNITY_EDITOR
  25. if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
  26. return;
  27. #endif
  28. Time.timeScale = _Value;
  29. }
  30. }
  31. /************************************************************************************************************************/
  32. private void Awake()
  33. {
  34. Value = _Value;
  35. }
  36. /************************************************************************************************************************/
  37. private void OnValidate()
  38. {
  39. Value = _Value;
  40. }
  41. /************************************************************************************************************************/
  42. }
  43. }