Layer.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. namespace MonoGame.Extended.Collisions.Layers;
  3. /// <summary>
  4. /// Layer is a group of collision's actors.
  5. /// </summary>
  6. public class Layer
  7. {
  8. /// <summary>
  9. /// If this property equals true, layer always will reset collision space.
  10. /// </summary>
  11. public bool IsDynamic { get; set; } = true;
  12. /// <summary>
  13. /// The space, which contain actors.
  14. /// </summary>
  15. public readonly ISpaceAlgorithm Space;
  16. /// <summary>
  17. /// Constructor for layer
  18. /// </summary>
  19. /// <param name="spaceAlgorithm">A space algorithm for actors</param>
  20. /// <exception cref="ArgumentNullException"><paramref name="spaceAlgorithm"/> is null</exception>
  21. public Layer(ISpaceAlgorithm spaceAlgorithm)
  22. {
  23. Space = spaceAlgorithm ?? throw new ArgumentNullException(nameof(spaceAlgorithm));
  24. }
  25. /// <summary>
  26. /// Restructure a inner collection, if layer is dynamic, because actors can change own position
  27. /// </summary>
  28. public virtual void Reset()
  29. {
  30. if (IsDynamic)
  31. Space.Reset();
  32. }
  33. }