diff --git a/Assets/Scripts/Framework/GameAddressableContext.cs b/Assets/Scripts/Framework/GameAddressableContext.cs index 648803f..e6678aa 100644 --- a/Assets/Scripts/Framework/GameAddressableContext.cs +++ b/Assets/Scripts/Framework/GameAddressableContext.cs @@ -7,16 +7,29 @@ namespace Framework { + /// + /// Manages the loading and releasing of addressable assets in the game. + /// public class GameAddressableContext { #region Variables + /// + /// List of async operation handles for tracking asset requests. + /// private List _requestHandles = new (); #endregion #region Public Methods + /// + /// Asynchronously loads a list of assets by their keys. + /// + /// The type of the assets to load. + /// The keys of the assets to load. + /// Whether to instantiate the loaded assets. + /// A task that represents the asynchronous operation. The task result contains the list of loaded assets. public async Task> LoadAssetsAsync(List keys, bool instantiate = true) where TObject : Object { var request = _LoadAssetsAsync(keys); @@ -24,13 +37,27 @@ public async Task> LoadAssetsAsync(List keys, boo var result = await request.Task; return instantiate ? result.Select(Object.Instantiate).ToList() : result.ToList(); } - + + /// + /// Asynchronously loads a single asset by its key. + /// + /// The type of the asset to load. + /// The key of the asset to load. + /// Whether to instantiate the loaded asset. + /// A task that represents the asynchronous operation. The task result contains the loaded asset. public async Task LoadAssetAsync(string key, bool instantiate = true) where TObject : Object { var result = await LoadAssetsAsync(new List { key }, instantiate); return result.FirstOrDefault(); } - + + /// + /// Synchronously loads a list of assets by their keys. + /// + /// The type of the assets to load. + /// The keys of the assets to load. + /// Whether to instantiate the loaded assets. + /// The list of loaded assets. public List LoadAssets(List keys, bool instantiate = true) where TObject : Object { var request = _LoadAssetsAsync(keys); @@ -38,12 +65,22 @@ public List LoadAssets(List keys, bool instantiate = t var result = request.WaitForCompletion(); return instantiate ? result.Select(Object.Instantiate).ToList() : result.ToList(); } - + + /// + /// Synchronously loads a single asset by its key. + /// + /// The type of the asset to load. + /// The key of the asset to load. + /// Whether to instantiate the loaded asset. + /// The loaded asset. public TObject LoadAsset(string key, bool instantiate = true) where TObject : Object { return LoadAssets(new List { key }, instantiate).First(); } - + + /// + /// Releases all tracked asset requests. + /// public void Release() { _requestHandles.Clear(); @@ -53,6 +90,12 @@ public void Release() #region Private Methods + /// + /// Creates an async operation handle for loading a list of assets by their keys. + /// + /// The type of the assets to load. + /// The keys of the assets to load. + /// The async operation handle for the asset loading request. private AsyncOperationHandle> _LoadAssetsAsync(List keys) where TObject : Object { return Addressables.LoadAssetsAsync(keys, null, Addressables.MergeMode.Union, false); diff --git a/Assets/Scripts/Framework/GameController.cs b/Assets/Scripts/Framework/GameController.cs index 91c9f59..fc10198 100644 --- a/Assets/Scripts/Framework/GameController.cs +++ b/Assets/Scripts/Framework/GameController.cs @@ -6,25 +6,44 @@ namespace Framework { - + /// + /// Abstract base class for game controllers, providing common functionality for managing views and models. + /// + /// The type of the view associated with the controller. public abstract class GameController where TView : GameView { #region Properties - + + /// + /// The view associated with the controller. + /// private TView _view = null; + + /// + /// Dictionary to store models associated with the controller. + /// private Dictionary _models; + /// + /// Gets or sets the transform of the view. + /// protected Transform transform { get => _view.transform; set => _view.transform.SetPositionAndRotation(value.position, value.rotation); } + /// + /// Gets the game object of the view. + /// protected GameObject gameObject { get => _view.gameObject; } - + + /// + /// Gets the RectTransform component of the view. + /// protected RectTransform rectTransform { get => _view.GetComponent(); @@ -33,46 +52,90 @@ protected RectTransform rectTransform #endregion #region Getters and Setters - - + /// + /// Starts a coroutine on the view. + /// + /// The coroutine to start. + /// The started coroutine. protected Coroutine StartCoroutine(IEnumerator coroutine) { return _view.StartCoroutine(coroutine); } - + + /// + /// Instantiates a game object. + /// + /// The game object to instantiate. + /// The instantiated game object. protected GameObject Instantiate(GameObject value) { return GameObject.Instantiate(value); } - + + /// + /// Instantiates a game object at a specified position and rotation. + /// + /// The game object to instantiate. + /// The position to instantiate the game object at. + /// The rotation to instantiate the game object with. + /// The instantiated game object. protected GameObject Instantiate(GameObject value, Vector3 position, Quaternion rotation) { return GameObject.Instantiate(value, position, rotation); } - + + /// + /// Instantiates a game object at a specified position, rotation, and parent transform. + /// + /// The game object to instantiate. + /// The position to instantiate the game object at. + /// The rotation to instantiate the game object with. + /// The parent transform to instantiate the game object under. + /// The instantiated game object. protected GameObject Instantiate(GameObject value, Vector3 position, Quaternion rotation, Transform parent) { return GameObject.Instantiate(value, position, rotation, parent); } - + + /// + /// Instantiates a game object under a specified parent transform. + /// + /// The game object to instantiate. + /// The parent transform to instantiate the game object under. + /// The instantiated game object. protected GameObject Instantiate(GameObject value, Transform parent) { return GameObject.Instantiate(value, parent); } - - + + /// + /// Gets a component of a specified type from the view. + /// + /// The type of the component to get. + /// The component of the specified type. protected T GetComponent() { return _view.GetComponent(); } - + + /// + /// Sets the view for the controller. + /// + /// The view to set. + /// Thrown if the view is already set. public void SetView(TView view) { if (_view != null) throw new Exception("View already exist, can't set new view"); _view = view; } + /// + /// Sets a model for the controller. + /// + /// The type of the model to set. + /// The model to set. + /// Thrown if a model of the specified type already exists. public void SetModel(object model) { var type = typeof(T); @@ -85,14 +148,31 @@ public void SetModel(object model) throw new Exception("Model already exist, can't set new model with this type"); } + /// + /// Gets a model of a specified type from the controller. + /// + /// The type of the model to get. + /// The model of the specified type. + /// Thrown if a model of the specified type is not found. protected T GetModel() { var type = typeof(T); return _models.ContainsKey(type) ? (T) _models[type] : throw new Exception("Model not found"); } - + + /// + /// Gets the view associated with the controller. + /// + /// The view associated with the controller. public TView GetView() => _view; + /// + /// Gets a model of a specified type from another game object. + /// + /// The type of the model to get. + /// The game object to get the model from. + /// The model of the specified type. + /// Thrown if the game object does not have a GameView component. protected TControllerType GetModelFromOtherObject(GameObject value) where TControllerType : GameModel { var componentExist = value.TryGetComponent(out GameView viewComponent); @@ -100,10 +180,23 @@ protected TControllerType GetModelFromOtherObject(GameObject va return viewComponent.GetModel(); } + /// + /// Gets a controller of a specified type. + /// + /// The type of the controller to get. + /// The controller of the specified type. protected ControllerType GetController() { return GetControllerFromOtherObject(gameObject); } + + /// + /// Gets a controller of a specified type from another game object. + /// + /// The type of the controller to get. + /// The game object to get the controller from. + /// The controller of the specified type. + /// Thrown if the game object does not have a GameView component. protected TControllerType GetControllerFromOtherObject(GameObject value) { var componentExist = value.TryGetComponent(out GameView viewComponent); @@ -111,6 +204,11 @@ protected TControllerType GetControllerFromOtherObject(GameObje return viewComponent.GetController(); } + /// + /// Gets a list of child controllers of a specified type. + /// + /// The type of the child controllers to get. + /// A list of child controllers of the specified type. protected List GetChildControllers() { var controllers = new List(); @@ -132,6 +230,11 @@ protected List GetChildControllers() return controllers; } + /// + /// Gets a list of child models of a specified type. + /// + /// The type of the child models to get. + /// A list of child models of the specified type. protected List GetChildModels() where TModelType : GameModel { var models = new List(); @@ -144,21 +247,37 @@ protected List GetChildModels() where TModelType : GameM } return models; } - + + /// + /// Gets a controller of a specified type from the parent game object. + /// + /// The type of the controller to get. + /// The controller of the specified type. + /// Thrown if the parent game object does not have a GameView component. protected TControllerType GetControllerFromParent() { var componentExist = GetView().transform.parent.TryGetComponent(out GameView viewComponent); if(!componentExist) throw new Exception("GameView component not found"); return viewComponent.GetController(); } - + + /// + /// Gets a model of a specified type from the parent game object. + /// + /// The type of the model to get. + /// The model of the specified type. + /// Thrown if the parent game object does not have a GameView component. protected TModelType GetModelFromParent() where TModelType : GameModel { var componentExist = GetView().transform.parent.TryGetComponent(out GameView viewComponent); if(!componentExist) throw new Exception("GameView component not found"); return viewComponent.GetModel(); } - + + /// + /// Destroys the specified object or the view if no object is specified. + /// + /// The object to destroy. If null, the view is destroyed. protected void Destroy(Object value = null) { if (value == null) @@ -169,14 +288,6 @@ protected void Destroy(Object value = null) Object.Destroy(value); } - /* - protected void SendEventToParent(string functionName, params object[] data) - { - var componentExist = GetView().transform.parent.TryGetComponent(out GameView gameView); - if(!componentExist) throw new Exception("GameView component not found"); - gameView.ReceiveEventFromChild(functionName, data); - }*/ - #endregion } } \ No newline at end of file diff --git a/Assets/Scripts/Framework/GameDependency.cs b/Assets/Scripts/Framework/GameDependency.cs index d159e4d..eaa28a4 100644 --- a/Assets/Scripts/Framework/GameDependency.cs +++ b/Assets/Scripts/Framework/GameDependency.cs @@ -2,10 +2,17 @@ namespace Framework { + /// + /// Manages the dependency injection for the game using VContainer. + /// public class GameDependency : LifetimeScope { #region Methods + /// + /// Injects dependencies into the specified instance. + /// + /// The instance to inject dependencies into. public void Inject(object instance) { Container.Inject(instance); diff --git a/Assets/Scripts/Framework/GameFieldAttributes.cs b/Assets/Scripts/Framework/GameFieldAttributes.cs index 4568cb5..89d82ed 100644 --- a/Assets/Scripts/Framework/GameFieldAttributes.cs +++ b/Assets/Scripts/Framework/GameFieldAttributes.cs @@ -2,11 +2,20 @@ namespace Framework { + /// + /// Contains custom attributes for game fields. + /// public class GameFieldAttributes { + /// + /// Attribute to mark a field as a controller field. + /// [AttributeUsage(AttributeTargets.Field)] public class ControllerFieldAttribute : System.Attribute {} - + + /// + /// Attribute to mark a field as a model field. + /// [AttributeUsage(AttributeTargets.Field)] public class ModelFieldAttribute : System.Attribute {} } diff --git a/Assets/Scripts/Framework/GameModel.cs b/Assets/Scripts/Framework/GameModel.cs index e873c8d..65f4b79 100644 --- a/Assets/Scripts/Framework/GameModel.cs +++ b/Assets/Scripts/Framework/GameModel.cs @@ -2,6 +2,9 @@ namespace Framework { + /// + /// Represents the base class for game models, providing lifecycle management and cloning capabilities. + /// public abstract class GameModel : ICloneable { #region Lifecycle diff --git a/Assets/Scripts/Framework/GameView.cs b/Assets/Scripts/Framework/GameView.cs index e677bfd..d1c4147 100644 --- a/Assets/Scripts/Framework/GameView.cs +++ b/Assets/Scripts/Framework/GameView.cs @@ -8,6 +8,9 @@ namespace Framework { + /// + /// Represents the view component in the MVC pattern, managing the lifecycle and interactions of models and controllers. + /// public class GameView : MonoBehaviour { #region Variables diff --git a/Assets/Scripts/Framework/GameViewUI.cs b/Assets/Scripts/Framework/GameViewUI.cs index 391e779..56bb0fb 100644 --- a/Assets/Scripts/Framework/GameViewUI.cs +++ b/Assets/Scripts/Framework/GameViewUI.cs @@ -2,6 +2,9 @@ namespace Framework { + /// + /// Represents the UI view component in the MVC pattern, handling various pointer and drag events. + /// public class GameViewUI : GameView, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler, IPointerExitHandler, IPointerUpHandler, IPointerMoveHandler, IPointerEnterHandler { #region Unity Methods diff --git a/Assets/Scripts/Framework/IGameEventBus.cs b/Assets/Scripts/Framework/IGameEventBus.cs index bcbb6be..2081a66 100644 --- a/Assets/Scripts/Framework/IGameEventBus.cs +++ b/Assets/Scripts/Framework/IGameEventBus.cs @@ -3,22 +3,103 @@ namespace Framework { + /// + /// Interface for the game event bus, providing methods for adding, removing, and raising events. + /// public interface IGameEventBus { + /// + /// Adds a listener for the specified event type. + /// + /// The type of the event. + /// The listener to add. + /// The owner of the listener. void AddListener(Action listener, GameController owner = null); + + /// + /// Adds a listener for the specified event type. + /// + /// The type of the event. + /// The listener to add. + /// The owner of the listener. void AddListener(Action listener, GameController owner = null); + + /// + /// Adds a listener for the specified event type. + /// + /// The listener to add. + /// The type of the event. void AddListener(Action listener, Type type); + + /// + /// Adds a listener for the specified event type. + /// + /// The listener to add. + /// The type of the event. void AddListener(Action listener, Type type); + + /// + /// Adds a listener for the specified event type. + /// + /// The type of the event. + /// The listener to add. + /// The owner of the listener. void AddListener(Func listener, GameController owner = null); - void AddListener(Func listener, GameController owner = null); - + + /// + /// Adds a listener for the specified event type. + /// + /// The type of the event. + /// The listener to add. + /// The owner of the listener. + void AddListener(Func listener, GameController owner = null); + + /// + /// Removes a listener for the specified event type. + /// + /// The type of the event. + /// The listener to remove. void RemoveListener(Action listener); + + /// + /// Removes a listener for the specified event type. + /// + /// The type of the event. + /// The listener to remove. void RemoveListener(Action listener); + + /// + /// Removes all listeners for the specified event type. + /// + /// The type of the event. void RemoveListeners(); + + /// + /// Removes a listener for the specified event type. + /// + /// The listener to remove. + /// The type of the event. void RemoveListener(Action listener, Type type); + + /// + /// Removes a listener for the specified event type. + /// + /// The type of the event. + /// The listener to remove. void RemoveListener(Func listener); + + /// + /// Removes a listener for the specified event type. + /// + /// The type of the event. + /// The listener to remove. void RemoveListener(Func listener); + /// + /// Raises an event of the specified type. + /// + /// The type of the event. + /// The event arguments. void RaiseEvent(T args = null) where T : class; } } \ No newline at end of file