2023-11-23 22:07:49 +03:00
using System.Collections.Generic ;
using System.Diagnostics.CodeAnalysis ;
namespace Syntriax.Engine.Core.Abstract ;
/// <summary>
2024-02-01 12:14:53 +03:00
/// Represents a controller for managing <see cref="IBehaviour"/>s and notify them accordingly about the engine's updates. Connected to an <see cref="IGameObject"/>.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-11-10 20:21:53 +03:00
public interface IBehaviourController : IInitialize , IAssignableGameObject , IEnumerable < IBehaviour >
2023-11-23 22:07:49 +03:00
{
/// <summary>
2024-02-01 12:14:53 +03:00
/// Event triggered before the update of <see cref="IBehaviour"/>s.
2023-11-30 10:39:40 +03:00
/// </summary>
2024-07-15 01:13:39 +03:00
event OnPreUpdateDelegate ? OnPreUpdate ;
2024-02-01 12:14:53 +03:00
2023-11-30 10:39:40 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Event triggered during the update of <see cref="IBehaviour"/>s.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-07-15 01:13:39 +03:00
event OnUpdateDelegate ? OnUpdate ;
2023-11-23 22:07:49 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Event triggered before the drawing phase.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-07-15 01:13:39 +03:00
event OnPreDrawDelegate ? OnPreDraw ;
2023-11-23 22:07:49 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Event triggered when a <see cref="IBehaviour"/> is added to the <see cref="IBehaviourController"/>.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-07-15 01:13:39 +03:00
event OnBehaviourAddedDelegate ? OnBehaviourAdded ;
2023-11-23 22:07:49 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Event triggered when a <see cref="IBehaviour"/> is removed from the <see cref="IBehaviourController"/>.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-07-15 01:13:39 +03:00
event OnBehaviourRemovedDelegate ? OnBehaviourRemoved ;
2023-11-23 22:07:49 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Adds a <see cref="IBehaviour"/> to the <see cref="IBehaviourController"/>.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-02-01 12:14:53 +03:00
/// <typeparam name="T">The type of <see cref="IBehaviour"/> to add.</typeparam>
/// <param name="behaviour">The <see cref="IBehaviour"/> to add.</param>
/// <returns>The added <see cref="IBehaviour"/>.</returns>
2023-11-23 22:07:49 +03:00
T AddBehaviour < T > ( T behaviour ) where T : class , IBehaviour ;
/// <summary>
2024-02-01 12:14:53 +03:00
/// Adds a <see cref="IBehaviour"/> of the specified type to the <see cref="IBehaviourController"/>.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-02-01 12:14:53 +03:00
/// <typeparam name="T">The type of <see cref="IBehaviour"/> to add.</typeparam>
/// <param name="args">Construction parameters for the <see cref="IBehaviour"/>.</param>
/// <returns>The added <see cref="IBehaviour"/>.</returns>
2023-11-23 22:07:49 +03:00
T AddBehaviour < T > ( params object? [ ] ? args ) where T : class , IBehaviour ;
2024-01-31 18:32:53 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Gets a <see cref="IBehaviour"/> of the specified type.
2024-01-31 18:32:53 +03:00
/// </summary>
2024-02-01 12:14:53 +03:00
/// <typeparam name="T">The type of <see cref="IBehaviour"/> to get.</typeparam>
/// <returns>The <see cref="IBehaviour"/> of the specified type if found; otherwise, <see cref="null"/>.</returns>
2024-01-31 18:32:53 +03:00
T ? GetBehaviour < T > ( ) ;
2023-11-23 22:07:49 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Tries to get a <see cref="IBehaviour"/> of the specified type.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-02-01 12:14:53 +03:00
/// <typeparam name="T">The type of <see cref="IBehaviour"/> to get.</typeparam>
/// <param name="behaviour">When this method returns, contains the <see cref="IBehaviour"/> of the specified type, if found; otherwise, see.</param>
/// <returns><see cref="true"/> if a <see cref="IBehaviour"/> of the specified type was found; otherwise, <see cref="false"/>.</returns>
2023-11-23 22:07:49 +03:00
bool TryGetBehaviour < T > ( [ NotNullWhen ( returnValue : true ) ] out T ? behaviour ) ;
2024-02-01 12:14:53 +03:00
/// <summary>
/// Gets all <see cref="IBehaviour"/>s of the specified type.
/// </summary>
/// <typeparam name="T">The type of <see cref="IBehaviour"/>s to get.</typeparam>
/// <returns>A list of <see cref="IBehaviour"/>s of the specified type.</returns>
2023-11-30 17:54:32 +03:00
IList < T > GetBehaviours < T > ( ) ;
2023-11-23 22:07:49 +03:00
2024-02-01 12:14:53 +03:00
/// <summary>
/// Gets all <see cref="IBehaviour"/>s of the specified type and stores them in the provided list.
/// </summary>
/// <typeparam name="T">The type of <see cref="IBehaviour"/>s to get.</typeparam>
/// <param name="behaviours">The list to store the <see cref="IBehaviour"/>s.</param>
2024-01-30 12:31:51 +03:00
void GetBehaviours < T > ( List < T > behaviours ) ;
2023-11-23 22:07:49 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Removes <see cref="IBehaviour"/>s of the specified type from the <see cref="IBehaviourController"/>.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-02-01 12:14:53 +03:00
/// <typeparam name="T">The type of <see cref="IBehaviour"/>s to remove.</typeparam>
/// <param name="removeAll">A flag indicating whether to remove all <see cref="IBehaviour"/>s of the specified type.</param>
2023-11-30 17:54:32 +03:00
void RemoveBehaviour < T > ( bool removeAll = false ) where T : class , IBehaviour ;
2023-11-23 22:07:49 +03:00
2023-11-30 17:54:32 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Removes the specified <see cref="IBehaviour"/> from the <see cref="IBehaviourController"/>.
2023-11-30 17:54:32 +03:00
/// </summary>
2024-02-01 12:14:53 +03:00
/// <typeparam name="T">The type of <see cref="IBehaviour"/> to remove.</typeparam>
/// <param name="behaviour">The <see cref="IBehaviour"/> to remove.</param>
2023-11-30 17:54:32 +03:00
void RemoveBehaviour < T > ( T behaviour ) where T : class , IBehaviour ;
2023-11-23 22:07:49 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Updates all <see cref="IBehaviour"/>s in the <see cref="IBehaviourController"/>.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-01-22 22:45:40 +03:00
void Update ( ) ;
2023-11-23 22:07:49 +03:00
/// <summary>
2024-02-01 12:14:53 +03:00
/// Performs pre-draw operations.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-01-22 22:45:40 +03:00
void UpdatePreDraw ( ) ;
2024-07-15 01:13:39 +03:00
delegate void OnPreUpdateDelegate ( IBehaviourController sender ) ;
delegate void OnUpdateDelegate ( IBehaviourController sender ) ;
delegate void OnPreDrawDelegate ( IBehaviourController sender ) ;
delegate void OnBehaviourAddedDelegate ( IBehaviourController sender , IBehaviour behaviourAdded ) ;
delegate void OnBehaviourRemovedDelegate ( IBehaviourController sender , IBehaviour behaviourRemoved ) ;
2023-11-23 22:07:49 +03:00
}