diff --git a/MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/UnityMVVM.dll b/MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/UnityMVVM.dll index 2a24d99..4d509ef 100644 Binary files a/MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/UnityMVVM.dll and b/MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/UnityMVVM.dll differ diff --git a/MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/package.json b/MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/package.json index e7d0ba2..74dc0ed 100644 --- a/MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/package.json +++ b/MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/package.json @@ -1,7 +1,7 @@ { "name": "com.kekchpek.umvvm", "displayName": "UnityMvvm", - "version": "0.16.0", + "version": "0.16.1", "description": "The MVVM pattern core implemented for Unity3d", "unity": "2022.3", "documentationUrl": "https://github.com/kekchpek/UnityMVVM", diff --git a/MvvmUnityProj/QuickStartUnityMVVM/Assets/Libs/UnityMVVM.dll b/MvvmUnityProj/QuickStartUnityMVVM/Assets/Libs/UnityMVVM.dll index 2a24d99..4d509ef 100644 Binary files a/MvvmUnityProj/QuickStartUnityMVVM/Assets/Libs/UnityMVVM.dll and b/MvvmUnityProj/QuickStartUnityMVVM/Assets/Libs/UnityMVVM.dll differ diff --git a/src/UnityMVVM/DI/DiContainerExtensions.cs b/src/UnityMVVM/DI/DiContainerExtensions.cs index 2021b18..3718257 100644 --- a/src/UnityMVVM/DI/DiContainerExtensions.cs +++ b/src/UnityMVVM/DI/DiContainerExtensions.cs @@ -7,7 +7,6 @@ using UnityMVVM.ViewModelCore.ViewModelsFactory; using System; using System.Linq; -using System.Threading.Tasks; using ModestTree; using UnityMVVM.DI.Config; using UnityMVVM.DI.Environment; @@ -119,24 +118,7 @@ public static void InstallView(this DiContain where TViewModelImpl : class, TViewModel { if (viewPrefabGetter == null) throw new ArgumentNullException(nameof(viewPrefabGetter)); - InstallViewInternal(container, viewName, () => Task.FromResult(viewPrefabGetter()), null); - } - - /// - /// Installs for specified View-ViewModel pair. - /// - /// MVVM container to configure. - /// View identificator for opening. - /// The async method to obtain view prefab. View should contains component inside. - /// The type of a view - /// The type of a view model. - /// The type, that implements a view model. - public static void InstallView(this DiContainer container, string viewName, Func> asyncViewPrefabGetter) - where TView : ViewBehaviour - where TViewModel : class, IViewModel - where TViewModelImpl : class, TViewModel - { - InstallViewInternal(container, viewName, asyncViewPrefabGetter, null); + InstallViewInternal(container, viewName, viewPrefabGetter, null); } /// @@ -157,31 +139,10 @@ public static void InstallPoolableView InstallViewInternal( container, viewName, - () => Task.FromResult(viewPrefabGetter()), + viewPrefabGetter, viewPool ?? new ViewPool()); } - - /// - /// The pool for views. Uses default object if null specified. - public static void InstallPoolableView - -#pragma warning disable CS1573 - (this DiContainer container, - string viewName, - Func> asyncViewPrefabGetter, -#pragma warning restore CS1573 - IViewPool? viewPool = null) - where TView : ViewBehaviour, IPoolableView - where TViewModel : class, IViewModel - where TViewModelImpl : class, TViewModel - { - InstallViewInternal( - container, - viewName, - asyncViewPrefabGetter, - viewPool ?? new ViewPool()); - } - + /// /// The pool for views. Uses default object if null specified. public static void InstallPoolableView @@ -199,13 +160,13 @@ public static void InstallPoolableView InstallViewInternal( container, viewName, - () => Task.FromResult(viewPrefab), + () => viewPrefab, viewPool ?? new ViewPool()); } private static void InstallViewInternal( DiContainer container, string viewName, - Func> viewPrefabGetter, IViewPool? viewPool) + Func viewPrefabGetter, IViewPool? viewPool) where TView : ViewBehaviour where TViewModel : class, IViewModel where TViewModelImpl : class, TViewModel @@ -223,7 +184,7 @@ private static void InstallViewInternal( .AsTransient() .WithArgumentsExplicit(new [] { - new TypeValuePair(typeof(Func>), viewPrefabGetter), + new TypeValuePair(typeof(Func), viewPrefabGetter), new TypeValuePair(typeof(IViewPool), viewPool), }); env.Mapper.Map(); diff --git a/src/UnityMVVM/ViewManager/IViewManager.cs b/src/UnityMVVM/ViewManager/IViewManager.cs index 874d190..774a71e 100644 --- a/src/UnityMVVM/ViewManager/IViewManager.cs +++ b/src/UnityMVVM/ViewManager/IViewManager.cs @@ -45,7 +45,7 @@ public interface IViewManager /// The container to instantiate the view to. /// View model payload. /// Returns created view model. - public Task Create(IViewModel parent, string viewName, Transform container, IPayload? payload = null); + public IViewModel Create(IViewModel parent, string viewName, Transform container, IPayload? payload = null); /// /// Creates view model and corresponding view. Closes all views on layers above specified. diff --git a/src/UnityMVVM/ViewManager/ViewManagerImpl.cs b/src/UnityMVVM/ViewManager/ViewManagerImpl.cs index 5921580..2e88def 100644 --- a/src/UnityMVVM/ViewManager/ViewManagerImpl.cs +++ b/src/UnityMVVM/ViewManager/ViewManagerImpl.cs @@ -1,7 +1,6 @@ using AsyncReactAwait.Promises; using System; using System.Collections.Generic; -using System.Threading.Tasks; using AsyncReactAwait.Bindable; using UnityEngine; using UnityEngine.Scripting; @@ -83,7 +82,7 @@ public async IPromise OpenExact(string viewLayerId, string viewName, IPayload? p var layer = GetLayer(viewLayerId); await layer.Clear(); - await CreateViewOnLayer(viewName, layer, payload); + CreateViewOnLayer(viewName, layer, payload); } /// @@ -145,9 +144,9 @@ public IReadOnlyList GetLayerIds() return _layerIds; } - public async Task Create(IViewModel parent, string viewName, Transform container, IPayload? payload = null) + public IViewModel Create(IViewModel parent, string viewName, Transform container, IPayload? payload = null) { - return await _viewsContainer.ResolveViewFactory(viewName).Create(parent.Layer, parent, container, payload); + return _viewsContainer.ResolveViewFactory(viewName).Create(parent.Layer, parent, container, payload); } /// @@ -175,7 +174,7 @@ public async Task Create(IViewModel parent, string viewName, Transfo // open required view if (_layers[i].Id == viewLayerId) { - var viewModel = await CreateViewOnLayer(viewName, _layers[i], payload); + var viewModel = CreateViewOnLayer(viewName, _layers[i], payload); return viewModel; } } @@ -187,9 +186,9 @@ public async Task Create(IViewModel parent, string viewName, Transfo } } - private async Task CreateViewOnLayer(string viewName, IViewLayer layer, IPayload? payload) + private IViewModel CreateViewOnLayer(string viewName, IViewLayer layer, IPayload? payload) { - var viewModel = await _viewsContainer.ResolveViewFactory(viewName).Create(layer, null, layer.Container, payload); + var viewModel = _viewsContainer.ResolveViewFactory(viewName).Create(layer, null, layer.Container, payload); _createdViewsNames.Add(viewModel, viewName); viewModel.Destroyed += OnViewModelDestroyed; layer.Set(viewModel); diff --git a/src/UnityMVVM/ViewModelCore/ViewModel.cs b/src/UnityMVVM/ViewModelCore/ViewModel.cs index 9e2c7d0..c6272d1 100644 --- a/src/UnityMVVM/ViewModelCore/ViewModel.cs +++ b/src/UnityMVVM/ViewModelCore/ViewModel.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using UnityEngine; using UnityMVVM.ViewManager; using UnityMVVM.ViewManager.ViewLayer; @@ -72,36 +71,37 @@ protected T CreateSubView(string viewName, IPayload? payload = null) where T { return CreateSubView(viewName, _layer.Container, payload); } - + /// /// Creates a child view and view model. /// /// The view identifier to open. /// The view model payload. /// Created view model. - protected async Task CreateSubView(string viewName, IPayload? payload = null) + protected IViewModel CreateSubView(string viewName, IPayload? payload = null) { - return await CreateSubView(viewName, _layer.Container, payload); + return CreateSubView(viewName, _layer.Container, payload); } - /// + /// /// The container to instantiate view to. - protected async Task CreateSubView( + protected T CreateSubView( #pragma warning disable CS1573 string viewName, #pragma warning restore CS1573 Transform container, #pragma warning disable CS1573 - IPayload? payload = null) + IPayload? payload = null) #pragma warning restore CS1573 + where T : class, IViewModel { - var viewModel = await _viewManager.Create(this, viewName, container, payload); + var viewModel = _viewManager.Create(this, viewName, container, payload); return viewModel; } - + /// /// The container to instantiate view to. - protected T CreateSubView( + protected IViewModel CreateSubView( #pragma warning disable CS1573 string viewName, #pragma warning restore CS1573 @@ -109,9 +109,8 @@ protected T CreateSubView( #pragma warning disable CS1573 IPayload? payload = null) #pragma warning restore CS1573 - where T : class, IViewModel { - var viewModel = _viewManager.Create(this, viewName, container, payload); + var viewModel = _viewManager.Create(this, viewName, container, payload); return viewModel; } diff --git a/src/UnityMVVM/ViewModelCore/ViewModelsFactory/IViewModelsFactory.cs b/src/UnityMVVM/ViewModelCore/ViewModelsFactory/IViewModelsFactory.cs index b7c4efc..873dacf 100644 --- a/src/UnityMVVM/ViewModelCore/ViewModelsFactory/IViewModelsFactory.cs +++ b/src/UnityMVVM/ViewModelCore/ViewModelsFactory/IViewModelsFactory.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using UnityEngine; +using UnityEngine; using UnityMVVM.ViewManager.ViewLayer; namespace UnityMVVM.ViewModelCore.ViewModelsFactory @@ -18,7 +17,7 @@ internal interface IViewModelsFactory /// The transform to instantiate the view to. /// View model payload. /// Returns created view model to control the view. - Task Create(IViewLayer viewLayer, + IViewModel Create(IViewLayer viewLayer, IViewModel? parent, Transform parentTransform, IPayload? payload = null); diff --git a/src/UnityMVVM/ViewModelCore/ViewModelsFactory/ViewModelsFactory.cs b/src/UnityMVVM/ViewModelCore/ViewModelsFactory/ViewModelsFactory.cs index f4a881c..3e676bb 100644 --- a/src/UnityMVVM/ViewModelCore/ViewModelsFactory/ViewModelsFactory.cs +++ b/src/UnityMVVM/ViewModelCore/ViewModelsFactory/ViewModelsFactory.cs @@ -20,7 +20,7 @@ internal class ViewModelsFactory : IViewModelsFactory private readonly IInstantiator _instantiator; private readonly IViewToViewModelMapper _viewToViewModelMapper; private readonly IViewFactory _viewFactory; - private readonly Func> _viewPrefabGetter; + private readonly Func _viewPrefabGetter; private readonly IViewPool? _viewPool; /// @@ -33,7 +33,7 @@ internal class ViewModelsFactory : IViewModelsFactory /// The pool for views(if presented) [Preserve] public ViewModelsFactory( - Func> viewPrefabGetter, + Func viewPrefabGetter, IInstantiator instantiator, IViewToViewModelMapper viewToViewModelMapper, IViewFactory viewFactory, @@ -47,12 +47,12 @@ public ViewModelsFactory( } /// - public async Task Create(IViewLayer viewLayer, + public IViewModel Create(IViewLayer viewLayer, IViewModel? parent, Transform transform, IPayload? payload = null) { - var view = _viewFactory.Instantiate(await _viewPrefabGetter.Invoke(), transform, _viewPool); + var view = _viewFactory.Instantiate(_viewPrefabGetter.Invoke(), transform, _viewPool); if (view is not Component c) throw new Exception("View should be a Component");