Door.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
  3. using UnityEngine;
  4. namespace Animancer.Samples.FineControl
  5. {
  6. /// <summary>
  7. /// An <see cref="IInteractable"/> door which toggles between open and closed when something interacts with it.
  8. /// </summary>
  9. ///
  10. /// <remarks>
  11. /// <strong>Sample:</strong>
  12. /// <see href="https://kybernetik.com.au/animancer/docs/samples/fine-control/doors">
  13. /// Doors</see>
  14. /// </remarks>
  15. ///
  16. /// https://kybernetik.com.au/animancer/api/Animancer.Samples.FineControl/Door
  17. ///
  18. [AddComponentMenu(Strings.SamplesMenuPrefix + "Fine Control - Door")]
  19. [AnimancerHelpUrl(typeof(Door))]
  20. [SelectionBase]
  21. public class Door : MonoBehaviour, IInteractable
  22. {
  23. /************************************************************************************************************************/
  24. [SerializeField] private SoloAnimation _SoloAnimation;
  25. /************************************************************************************************************************/
  26. /// <summary>[<see cref="IInteractable"/>] Toggles this door between open and closed.</summary>
  27. public void Interact()
  28. {
  29. if (_SoloAnimation.Speed == 0)
  30. {
  31. bool playForwards = _SoloAnimation.NormalizedTime < 0.5f;
  32. _SoloAnimation.Speed = playForwards ? 1 : -1;
  33. }
  34. else
  35. {
  36. _SoloAnimation.Speed = -_SoloAnimation.Speed;
  37. }
  38. _SoloAnimation.IsPlaying = true;
  39. }
  40. /************************************************************************************************************************/
  41. }
  42. }