From e0cc3391d7ec09513e010fc07acc9504920a825e Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Fri, 29 Nov 2019 18:59:55 +0200 Subject: [PATCH 01/34] Added support for view layers --- .../Attributes/ViewControllerAttribute.cs | 5 + .../Views/ViewFactory.ViewCollection.cs | 125 ++++++++---------- .../Implementation/Views/ViewFactory.cs | 96 ++++++-------- .../Tests/Editor/Scripts/ViewFactoryTests.cs | 1 - 4 files changed, 100 insertions(+), 127 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs index 6dcec26..da8873d 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs @@ -22,6 +22,11 @@ public sealed class ViewControllerAttribute : Attribute /// public string ViewPrefabName { get; set; } + /// + /// Gets or sets index of the view layer. + /// + public int ViewLayer { get; set; } + /// /// Gets or sets present options. /// diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs index 4999541..61ace97 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs @@ -14,7 +14,7 @@ partial class ViewFactory { #region interface - public class ViewCollection : IList, IReadOnlyList + public class ViewCollection : ICollection, IReadOnlyCollection { #region data @@ -31,76 +31,37 @@ internal ViewCollection(ViewFactory factory) public IView[] ToArray() { - var viewRoot = _factory.ViewRootTransform; - var result = new IView[viewRoot.childCount]; - - for (var i = 0; i < result.Length; ++i) - { - result[i] = viewRoot.GetChild(i).GetComponent()?.Component as IView; - } - + var result = new IView[Count]; + CopyTo(result, 0); return result; } #endregion - #region IList + #region ICollection - public IView this[int index] + public int Count { get { - var viewRoot = _factory.ViewRootTransform; + var viewRoots = _factory.ViewRoots; - if (index < 0 || index >= viewRoot.childCount) + if (viewRoots != null) { - throw new ArgumentOutOfRangeException(nameof(index)); - } + var result = 0; - return viewRoot.GetChild(index).GetComponent()?.Component as IView; - } - set - { - throw new NotSupportedException(); - } - } - - public int IndexOf(IView view) - { - if (view != null) - { - var viewRoot = _factory.ViewRootTransform; - - for (var i = 0; i < viewRoot.childCount; ++i) - { - var proxy = viewRoot.GetChild(i).GetComponent(); - - if (proxy && proxy.Component == view) + foreach (var viewRoot in viewRoots) { - return i; + result += viewRoot.childCount; } - } - } - - return -1; - } - public void Insert(int index, IView item) - { - throw new NotSupportedException(); - } + return result; + } - public void RemoveAt(int index) - { - throw new NotSupportedException(); + return 0; + } } - #endregion - - #region ICollection - - public int Count => _factory.ViewRootTransform.childCount; - public bool IsReadOnly => true; public void Add(IView view) @@ -122,15 +83,21 @@ public bool Contains(IView view) { if (view != null) { - var viewRoot = _factory.ViewRootTransform; + var viewRoots = _factory.ViewRoots; - for (var i = 0; i < viewRoot.childCount; ++i) + if (viewRoots != null) { - var proxy = viewRoot.GetChild(i).GetComponent(); - - if (proxy && proxy.Component == view) + foreach (var viewRoot in viewRoots) { - return true; + for (var i = 0; i < viewRoot.childCount; ++i) + { + var proxy = viewRoot.GetChild(i).GetComponent(); + + if (proxy && proxy.Component == view) + { + return true; + } + } } } } @@ -140,11 +107,17 @@ public bool Contains(IView view) public void CopyTo(IView[] array, int arrayIndex) { - var viewRoot = _factory.ViewRootTransform; + var viewRoots = _factory.ViewRoots; - for (var i = 0; i < viewRoot.childCount; ++i) + if (viewRoots != null) { - array[arrayIndex + i] = viewRoot.GetChild(i).GetComponent()?.Component as IView; + foreach (var viewRoot in viewRoots) + { + for (var i = 0; i < viewRoot.childCount; ++i) + { + array[arrayIndex + i] = viewRoot.GetChild(i).GetComponent()?.Component as IView; + } + } } } @@ -154,23 +127,35 @@ public void CopyTo(IView[] array, int arrayIndex) public IEnumerator GetEnumerator() { - var viewRoot = _factory.ViewRootTransform; + var viewRoots = _factory.ViewRoots; - for (var i = 0; i < viewRoot.childCount; ++i) + if (viewRoots != null) { - var proxy = viewRoot.GetChild(i).GetComponent(); - yield return proxy?.Component as IView; + foreach (var viewRoot in viewRoots) + { + for (var i = 0; i < viewRoot.childCount; ++i) + { + var proxy = viewRoot.GetChild(i).GetComponent(); + yield return proxy?.Component as IView; + } + } } } IEnumerator IEnumerable.GetEnumerator() { - var viewRoot = _factory.ViewRootTransform; + var viewRoots = _factory.ViewRoots; - for (var i = 0; i < viewRoot.childCount; ++i) + if (viewRoots != null) { - var proxy = viewRoot.GetChild(i).GetComponent(); - yield return proxy?.Component; + foreach (var viewRoot in viewRoots) + { + for (var i = 0; i < viewRoot.childCount; ++i) + { + var proxy = viewRoot.GetChild(i).GetComponent(); + yield return proxy?.Component; + } + } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs index 06c311d..95bbb2d 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs @@ -17,11 +17,11 @@ public partial class ViewFactory : MonoBehaviour, IViewFactory, IContainer { #region data - [SerializeField] - private Transform _viewRootTransform; [SerializeField] private Color _popupBgColor = new Color(0, 0, 0, 0.5f); [SerializeField] + private Transform[] _viewRoots; + [SerializeField] private GameObject[] _viewPrefabs; private Dictionary _viewPrefabCache = new Dictionary(); @@ -34,37 +34,6 @@ public partial class ViewFactory : MonoBehaviour, IViewFactory, IContainer #region interface - /// - /// Gets root transform for the created views. - /// - public Transform ViewRootTransform - { - get - { - if (_viewRootTransform is null) - { - _viewRootTransform = transform; - } - - return _viewRootTransform; - } - set - { - ThrowIfDisposed(); - - if (value is null) - { - value = transform; - } - - if (_viewRootTransform != value) - { - DestroyAllViews(); - _viewRootTransform = value; - } - } - } - /// /// Gets background color of the popup views. /// @@ -75,6 +44,11 @@ public Transform ViewRootTransform /// public GameObject[] ViewPrefabs { get => _viewPrefabs; set => _viewPrefabs = value; } + /// + /// Gets or sets list of preloaded view prefabs. + /// + public Transform[] ViewRoots { get => _viewRoots; set => _viewRoots = value; } + /// /// Gets a read-only collection of views. /// @@ -104,6 +78,19 @@ protected void ClearPrefabCache() _viewPrefabCache?.Clear(); } + /// + /// Gets root for a view of the specified controller. + /// + protected virtual Transform GetViewRoot(Type controllerType, ViewControllerAttribute attr) + { + if (_viewRoots is null) + { + return transform; + } + + return _viewRoots[attr.ViewLayer]; + } + /// /// Loads view prefab with the specified name. Default implementation searches the prefab in array, returns on any error. /// Overide to implement own mechanism of loading views. @@ -148,6 +135,22 @@ protected virtual void OnDispose() #region MonoBehaviour +#if UNITY_EDITOR + + protected virtual void Reset() + { + var cs = GetComponentsInChildren(); + + _viewRoots = new Transform[cs.Length]; + + for (var i = 0; i < cs.Length; i++) + { + _viewRoots[i] = cs[i].transform; + } + } + +#endif + private void OnDestroy() { Dispose(); @@ -175,8 +178,9 @@ public async Task CreateViewAsync(Type controllerType, int zIndex, Presen var exclusive = (options & PresentOptions.Exclusive) != 0; var modal = (options & PresentOptions.Modal) != 0; var prefabName = GetPrefabName(controllerType, attr); + var viewRoot = GetViewRoot(controllerType, attr); - viewProxy = CreateViewProxy(prefabName, zIndex, exclusive, modal); + viewProxy = CreateViewProxy(viewRoot, prefabName, zIndex, exclusive, modal); if (_viewPrefabCache.TryGetValue(prefabName, out var viewPrefab)) { @@ -304,7 +308,6 @@ public void Dispose() _components = null; _viewPrefabCache = null; - DestroyAllViews(); OnDispose(); } } @@ -329,7 +332,7 @@ private void AddInternal(IComponent component, string name) name = "View"; } - var viewProxy = CreateViewProxy(name, ViewRootTransform.childCount, false, false); + var viewProxy = CreateViewProxy(null, name, transform.childCount, false, false); viewProxy.Component = component; } @@ -383,13 +386,12 @@ private IView CreateView(GameObject viewPrefab, ViewProxy viewProxy, Transform p return view; } - private ViewProxy CreateViewProxy(string viewName, int zIndex, bool exclusive, bool modal) + private ViewProxy CreateViewProxy(Transform viewRoot, string viewName, int zIndex, bool exclusive, bool modal) { Debug.Assert(viewName != null); var go = new GameObject(viewName); var viewProxy = go.AddComponent(); - var viewRoot = ViewRootTransform; go.transform.SetParent(viewRoot, false); @@ -456,24 +458,6 @@ private void UpdatePopupBackgrounds() } } - private void DestroyAllViews() - { - var viewRoot = ViewRootTransform; - - if (viewRoot) - { - for (var i = 0; i < viewRoot.childCount; ++i) - { - var p = viewRoot.GetChild(i).GetComponent(); - - if (p) - { - p.DestroyInternal(); - } - } - } - } - private void ThrowIfInvalidPrefab(GameObject prefabGo) { if (!prefabGo) diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/ViewFactoryTests.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/ViewFactoryTests.cs index ca7ba76..73e87e0 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/ViewFactoryTests.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/ViewFactoryTests.cs @@ -35,7 +35,6 @@ public void InitialStateIsValid() { Assert.NotNull(_viewFactory.Views); Assert.IsEmpty(_viewFactory.Views); - Assert.AreEqual(_viewFactory.transform, _viewFactory.ViewRootTransform); } } } From 0c5ec9c2cfec89c2a20f476716a4ffdc299790b2 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Tue, 24 Dec 2019 16:47:20 +0200 Subject: [PATCH 02/34] tt --- .editorconfig | 6 +++--- .../Editor/Scripts/Windows/CreateViewControllerWindow.cs | 6 +++--- .../Scripts/Implementation/Presenters/Presenter{T}.cs | 2 +- .../Runtime/Scripts/Implementation/ViewController.cs | 7 +++++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9933dd0..c5ec6d0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,9 +5,10 @@ root = true # Use tabs for indentation. [*] -indent_style = tab -trim_trailing_whitespace = true +charset = utf-8 +end_of_line = crlf insert_final_newline = true +indent_style = tab # (Please don't specify an indent_size here; that has too many unintended consequences.) # Code files @@ -35,7 +36,6 @@ indent_size = 2 [*.{cs,vb}] # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true - # Avoid "this." and "Me." if not necessary dotnet_style_qualification_for_field = false:suggestion dotnet_style_qualification_for_property = false:suggestion diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows/CreateViewControllerWindow.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows/CreateViewControllerWindow.cs index 4180bf7..d857e47 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows/CreateViewControllerWindow.cs +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows/CreateViewControllerWindow.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. +// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. // See the LICENSE.md file in the project root for more information. using System; @@ -258,7 +258,7 @@ private static string GetPresentOptions(bool exclusive, bool popup, bool modal) { if (!string.IsNullOrEmpty(text)) { - text += " || "; + text += " | "; } text += nameof(PresentOptions) + '.' + nameof(PresentOptions.Popup); @@ -268,7 +268,7 @@ private static string GetPresentOptions(bool exclusive, bool popup, bool modal) { if (!string.IsNullOrEmpty(text)) { - text += " || "; + text += " | "; } text += nameof(PresentOptions) + '.' + nameof(PresentOptions.Modal); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs index 0c3d5c4..d31ed43 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs index f5dc32f..0e44457 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs @@ -193,6 +193,7 @@ public abstract class Commands protected ViewController(IPresentContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); + _context.View.Command += OnCommand; } /// @@ -339,6 +340,12 @@ public bool InvokeCommand(string commandName, object args) #endregion #region implementation + + private void OnCommand(object sender, CommandEventArgs e) + { + OnCommand(e.CommandName, e.CommandArguments); + } + #endregion } } From a1a2ef45a55675c1ca356ec94ec35ac7143fd4e6 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sat, 28 Dec 2019 16:31:54 +0200 Subject: [PATCH 03/34] Renamed IPresenter.PresentAsync to present and added PresentAsync extension methods --- .../Abstractions/Presenters/IPresentResult.cs | 5 +- .../Presenters/IPresentResultExtensions.cs | 66 ---- .../IPresentResultExtensions.cs.meta | 11 - .../Abstractions/Presenters/IPresenter.cs | 4 +- .../Presenters/IPresenterExtensions.cs | 356 ++++++++++++++++-- .../PresentResult{TController,TResult}.cs | 2 +- .../Implementation/Presenters/Presenter{T}.cs | 2 +- .../Implementation/Views/ViewFactory.cs | 4 +- .../Tests/Editor/Scripts/PresenterTests.cs | 12 +- Assets/Scenes/Test.unity | 3 +- Assets/Scripts/AppRoot.cs | 3 +- 11 files changed, 336 insertions(+), 132 deletions(-) delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultExtensions.cs delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultExtensions.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs index 0591082..f4d7557 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs @@ -1,9 +1,8 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; using System.ComponentModel; -using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace UnityFx.Mvc @@ -33,7 +32,7 @@ public interface IPresentResult : IViewControllerInfo, ICommandTarget, IDisposab Task DismissTask { get; } /// - /// Gets a instance that can be used to await the operation completion (i.e. until the is presented). + /// Gets a instance that can be used to await the operation completion (i.e. until the is presented/visible). /// Task PresentTask { get; } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultExtensions.cs deleted file mode 100644 index 0e96e20..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultExtensions.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Alexander Bogarsukov. -// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using UnityEngine; - -namespace UnityFx.Mvc -{ - /// - /// Extensions of . - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static class IPresentResultExtensions - { - public struct PresentResultAwaitable - { - private readonly IPresentResult _presentResult; - private readonly bool _awaitPresent; - - internal PresentResultAwaitable(IPresentResult presentResult, bool awaitPresent) - { - _presentResult = presentResult; - _awaitPresent = awaitPresent; - } - - public TaskAwaiter GetAwaiter() - { - if (_awaitPresent) - { - return _presentResult.PresentTask.GetAwaiter(); - } - else - { - return _presentResult.DismissTask.GetAwaiter(); - } - } - } - - /// - /// Gets an awaiter used to await this . - /// - public static PresentResultAwaitable ConfigureAwait(this IPresentResult presentResult, bool awaitPresent) - { - return new PresentResultAwaitable(presentResult, awaitPresent); - } - - /// - /// Gets an awaiter used to await this . - /// - public static TaskAwaiter GetAwaiter(this IPresentResult presentResult) - { - return presentResult.DismissTask.GetAwaiter(); - } - - /// - /// Gets an awaiter used to await this . - /// - public static TaskAwaiter GetAwaiter(this IPresentResult presentResult) where TController : IViewController - { - return presentResult.DismissTask.GetAwaiter(); - } - } -} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultExtensions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultExtensions.cs.meta deleted file mode 100644 index 5de826b..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultExtensions.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1ac16b74db6ade24fbe85382bb51058a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs index 6a8aaf8..82c53cb 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -25,6 +25,6 @@ public interface IPresenter /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance, it is abstract type). /// Thrown if the presenter is disposed. - IPresentResult PresentAsync(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args); + IPresentResult Present(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs index c2af9d6..b3b40d0 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs @@ -1,8 +1,9 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; using System.ComponentModel; +using System.Threading.Tasks; using UnityEngine; namespace UnityFx.Mvc @@ -23,9 +24,24 @@ public static class IPresenterExtensions /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult PresentAsync(this IPresenter presenter, Type controllerType) + public static IPresentResult Present(this IPresenter presenter, Type controllerType) { - return presenter.PresentAsync(controllerType, PresentOptions.None, null, null); + return presenter.Present(controllerType, PresentOptions.None, null, null); + } + + /// + /// Presents a controller of the specified type. + /// + /// The presenter. + /// Type of the view controller to present. + /// An object that can be used to track the operation progress. + /// Thrown if is . + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + /// + public static Task PresentAsync(this IPresenter presenter, Type controllerType) + { + return presenter.Present(controllerType, PresentOptions.None, null, null).DismissTask; } /// @@ -39,9 +55,41 @@ public static IPresentResult PresentAsync(this IPresenter presenter, Type contro /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult PresentAsync(this IPresenter presenter, Type controllerType, Transform transform) + public static IPresentResult Present(this IPresenter presenter, Type controllerType, Transform transform) + { + return presenter.Present(controllerType, PresentOptions.Popup, transform, null); + } + + /// + /// Presents a controller of the specified type. + /// + /// The presenter. + /// Type of the view controller to present. + /// Parent transform of the controller view. + /// An object that can be used to track the operation progress. + /// Thrown if is . + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + /// + public static Task PresentAsync(this IPresenter presenter, Type controllerType, Transform transform) + { + return presenter.Present(controllerType, PresentOptions.Popup, transform, null).DismissTask; + } + + /// + /// Presents a controller of the specified type. + /// + /// The presenter. + /// Type of the view controller to present. + /// Present options. + /// An object that can be used to track the operation progress. + /// Thrown if is . + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + /// + public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentOptions options) { - return presenter.PresentAsync(controllerType, PresentOptions.Popup, transform, null); + return presenter.Present(controllerType, options, null, null); } /// @@ -55,9 +103,9 @@ public static IPresentResult PresentAsync(this IPresenter presenter, Type contro /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options) + public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options) { - return presenter.PresentAsync(controllerType, options, null, null); + return presenter.Present(controllerType, options, null, null).DismissTask; } /// @@ -72,9 +120,9 @@ public static IPresentResult PresentAsync(this IPresenter presenter, Type contro /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options, PresentArgs args) + public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentOptions options, PresentArgs args) { - return presenter.PresentAsync(controllerType, options, null, args); + return presenter.Present(controllerType, options, null, args); } /// @@ -82,15 +130,48 @@ public static IPresentResult PresentAsync(this IPresenter presenter, Type contro /// /// The presenter. /// Type of the view controller to present. + /// Present options. /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args) + public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options, PresentArgs args) { - return presenter.PresentAsync(controllerType, PresentOptions.None, null, args); + return presenter.Present(controllerType, options, null, args).DismissTask; + } + + /// + /// Presents a controller of the specified type. + /// + /// The presenter. + /// Type of the view controller to present. + /// Controller arguments. + /// An object that can be used to track the operation progress. + /// Thrown if is . + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + /// + public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentArgs args) + { + return presenter.Present(controllerType, PresentOptions.None, null, args); + } + + /// + /// Presents a controller of the specified type. + /// + /// The presenter. + /// Type of the view controller to present. + /// Controller arguments. + /// An object that can be used to track the operation progress. + /// Thrown if is . + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + /// + public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args) + { + return presenter.Present(controllerType, PresentOptions.None, null, args).DismissTask; } /// @@ -101,9 +182,36 @@ public static IPresentResult PresentAsync(this IPresenter presenter, Type contro /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter) where TController : IViewController + { + return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, null); + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// The presenter. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + public static Task PresentAsync(this IPresenter presenter) where TController : IViewController + { + return presenter.Present(typeof(TController), PresentOptions.None, null, null).DismissTask; + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// The presenter. + /// Parent transform of the controller view. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + public static IPresentResult Present(this IPresenter presenter, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), PresentOptions.None, null, null); + return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, null); } /// @@ -115,9 +223,9 @@ public static IPresentResult PresentAsync(this IPresen /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, Transform transform) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), PresentOptions.Popup, transform, null); + return presenter.Present(typeof(TController), PresentOptions.Popup, transform, null).DismissTask; } /// @@ -130,9 +238,38 @@ public static IPresentResult PresentAsync(this IPresen /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), options, transform, null); + return (IPresentResult)presenter.Present(typeof(TController), options, transform, null); + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// The presenter. + /// Present options. + /// Parent transform of the controller view. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + { + return presenter.Present(typeof(TController), options, transform, null).DismissTask; + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// The presenter. + /// Controller arguments. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + public static IPresentResult Present(this IPresenter presenter, PresentArgs args) where TController : IViewController + { + return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, args); } /// @@ -144,9 +281,9 @@ public static IPresentResult PresentAsync(this IPresen /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), PresentOptions.None, null, args); + return presenter.Present(typeof(TController), PresentOptions.None, null, args).DismissTask; } /// @@ -159,9 +296,24 @@ public static IPresentResult PresentAsync(this IPresen /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, PresentOptions options, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentOptions options, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), options, null, args); + return (IPresentResult)presenter.Present(typeof(TController), options, null, args); + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// The presenter. + /// Present options. + /// Controller arguments. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + public static Task PresentAsync(this IPresenter presenter, PresentOptions options, PresentArgs args) where TController : IViewController + { + return presenter.Present(typeof(TController), options, null, args).DismissTask; } /// @@ -174,9 +326,24 @@ public static IPresentResult PresentAsync(this IPresen /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), PresentOptions.Popup, transform, args); + return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, args); + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// The presenter. + /// Parent transform of the controller view. + /// Controller arguments. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + public static Task PresentAsync(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + { + return presenter.Present(typeof(TController), PresentOptions.Popup, transform, args).DismissTask; } /// @@ -190,9 +357,55 @@ public static IPresentResult PresentAsync(this IPresen /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController + { + return (IPresentResult)presenter.Present(typeof(TController), options, transform, args); + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// The presenter. + /// Present options. + /// Parent transform of the controller view. + /// Controller arguments. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the presenter is disposed. + public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController + { + return presenter.Present(typeof(TController), options, transform, args).DismissTask; + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// Type of the controller result value. + /// The presenter. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the does not match result type of the . + /// Thrown if the presenter is disposed. + public static IPresentResult Present(this IPresenter presenter) where TController : IViewController + { + return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, null); + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// Type of the controller result value. + /// The presenter. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the does not match result type of the . + /// Thrown if the presenter is disposed. + public static Task PresentAsync(this IPresenter presenter) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), options, transform, args); + return ((IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, null)).DismissTask; } /// @@ -201,13 +414,14 @@ public static IPresentResult PresentAsync(this IPresen /// Type of the controller to instantiate. /// Type of the controller result value. /// The presenter. + /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), PresentOptions.None, null, null); + return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, args); } /// @@ -221,9 +435,25 @@ public static IPresentResult PresentAsyncThrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController + { + return ((IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, args)).DismissTask; + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// Type of the controller result value. + /// The presenter. + /// Parent transform of the controller view. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the does not match result type of the . + /// Thrown if the presenter is disposed. + public static IPresentResult Present(this IPresenter presenter, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), PresentOptions.None, null, args); + return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, null); } /// @@ -237,9 +467,9 @@ public static IPresentResult PresentAsyncThrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, Transform transform) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), PresentOptions.Popup, transform, null); + return ((IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, null)).DismissTask; } /// @@ -254,9 +484,9 @@ public static IPresentResult PresentAsyncThrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), options, transform, null); + return (IPresentResult)presenter.Present(typeof(TController), options, transform, null); } /// @@ -265,15 +495,67 @@ public static IPresentResult PresentAsyncType of the controller to instantiate. /// Type of the controller result value. /// The presenter. + /// Present options. + /// Parent transform of the controller view. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the does not match result type of the . + /// Thrown if the presenter is disposed. + public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + { + return ((IPresentResult)presenter.Present(typeof(TController), options, transform, null)).DismissTask; + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// Type of the controller result value. + /// The presenter. + /// Parent transform of the controller view. + /// Controller arguments. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the does not match result type of the . + /// Thrown if the presenter is disposed. + public static IPresentResult Present(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + { + return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, args); + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// Type of the controller result value. + /// The presenter. + /// Parent transform of the controller view. + /// Controller arguments. + /// An object that can be used to track the operation progress. + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if the does not match result type of the . + /// Thrown if the presenter is disposed. + public static Task PresentAsync(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + { + return ((IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, args)).DismissTask; + } + + /// + /// Presents a controller of the specified type. + /// + /// Type of the controller to instantiate. + /// Type of the controller result value. + /// The presenter. + /// Present options. /// Parent transform of the controller view. /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), PresentOptions.Popup, transform, args); + return (IPresentResult)presenter.Present(typeof(TController), options, transform, args); } /// @@ -289,9 +571,9 @@ public static IPresentResult PresentAsyncThrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.PresentAsync(typeof(TController), options, transform, args); + return ((IPresentResult)presenter.Present(typeof(TController), options, transform, args)).DismissTask; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs index 1d26437..b53cbc4 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs @@ -284,7 +284,7 @@ public void Dismiss() #region IPresenter - public IPresentResult PresentAsync(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) + public IPresentResult Present(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) { ThrowIfDisposed(); return _presenter.PresentAsync(this, controllerType, presentOptions, parent, args); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs index d31ed43..991f12f 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs @@ -342,7 +342,7 @@ int IPresenterInternal.GetNextId() #region IPresenter - public IPresentResult PresentAsync(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) + public IPresentResult Present(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) { return PresentInternal(null, controllerType, presentOptions, parent, args); } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs index 95bbb2d..e534805 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -83,7 +83,7 @@ protected void ClearPrefabCache() /// protected virtual Transform GetViewRoot(Type controllerType, ViewControllerAttribute attr) { - if (_viewRoots is null) + if (_viewRoots is null || _viewRoots.Length == 0) { return transform; } diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs index 455fbc5..341a407 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. +// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. // See the LICENSE.md file in the project root for more information. using System; @@ -46,20 +46,20 @@ public void InitialStateIsValid() [Test] public void Present_ThrownOnNullControllerType() { - Assert.Throws(() => _presenter.PresentAsync(null, PresentOptions.None, PresentArgs.Default)); + Assert.Throws(() => _presenter.Present(null, PresentOptions.None, PresentArgs.Default)); } [Test] public void Present_ThrownOnInvalidControllerType() { - Assert.Throws(() => _presenter.PresentAsync(typeof(AbstractController), PresentOptions.None, PresentArgs.Default)); - Assert.Throws(() => _presenter.PresentAsync(typeof(InvalidController), PresentOptions.None, PresentArgs.Default)); + Assert.Throws(() => _presenter.Present(typeof(AbstractController), PresentOptions.None, PresentArgs.Default)); + Assert.Throws(() => _presenter.Present(typeof(InvalidController), PresentOptions.None, PresentArgs.Default)); } [Test] public void Present_PresentsMinimalController() { - var presentResult = _presenter.PresentAsync(); + var presentResult = _presenter.Present(); Assert.NotNull(presentResult); } @@ -67,7 +67,7 @@ public void Present_PresentsMinimalController() [Test] public void PresentResult_CanBeDisposedRightAfterCreation() { - _presenter.PresentAsync().Dispose(); + _presenter.Present().Dispose(); Assert.IsNull(_presenter.ActiveController); Assert.IsEmpty(_presenter.Controllers); diff --git a/Assets/Scenes/Test.unity b/Assets/Scenes/Test.unity index 108d41e..c052107 100644 --- a/Assets/Scenes/Test.unity +++ b/Assets/Scenes/Test.unity @@ -173,8 +173,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e3542ea2f6f679240b85aab9ae98b201, type: 3} m_Name: m_EditorClassIdentifier: - _viewRootTransform: {fileID: 1605007611} _popupBgColor: {r: 0, g: 0, b: 0, a: 0.5} + _viewRoots: + - {fileID: 1605007611} _viewPrefabs: - {fileID: 240879178860548289, guid: 3091374f3c0c527468342f660648e692, type: 3} - {fileID: 7846704816992948672, guid: 7fb867d34bbeca048a50534ffe67f80d, type: 3} diff --git a/Assets/Scripts/AppRoot.cs b/Assets/Scripts/AppRoot.cs index 0d1f198..d1db154 100644 --- a/Assets/Scripts/AppRoot.cs +++ b/Assets/Scripts/AppRoot.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -31,7 +31,6 @@ private async void Start() { try { - await _presenter.PresentAsync().ConfigureAwait(true); await _presenter.PresentAsync(); await _presenter.PresentAsync(); } From da7d7a4b78b9b99fd60de444990b2079ee3dd09b Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sat, 28 Dec 2019 16:51:49 +0200 Subject: [PATCH 04/34] Changed Present/PresentAsync arguments order --- .../Abstractions/Presenters/IPresenter.cs | 4 +- .../Presenters/IPresenterExtensions.cs | 218 ++++++------------ .../PresentResult{TController,TResult}.cs | 4 +- .../Implementation/Presenters/Presenter{T}.cs | 2 +- .../Tests/Editor/Scripts/PresenterTests.cs | 6 +- 5 files changed, 82 insertions(+), 152 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs index 82c53cb..1de4f6e 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs @@ -18,13 +18,13 @@ public interface IPresenter /// Presents a controller of the specified type. /// /// Type of the view controller to present. + /// Controller arguments. /// Present flags. /// Parent transform for the view (or ). - /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance, it is abstract type). /// Thrown if the presenter is disposed. - IPresentResult Present(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args); + IPresentResult Present(Type controllerType, PresentArgs args, PresentOptions presentOptions, Transform parent); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs index b3b40d0..aece493 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs @@ -26,7 +26,7 @@ public static class IPresenterExtensions /// public static IPresentResult Present(this IPresenter presenter, Type controllerType) { - return presenter.Present(controllerType, PresentOptions.None, null, null); + return presenter.Present(controllerType, null, PresentOptions.None, null); } /// @@ -41,7 +41,7 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// public static Task PresentAsync(this IPresenter presenter, Type controllerType) { - return presenter.Present(controllerType, PresentOptions.None, null, null).DismissTask; + return presenter.Present(controllerType, null, PresentOptions.None, null).DismissTask; } /// @@ -49,15 +49,15 @@ public static Task PresentAsync(this IPresenter presenter, Type controllerType) /// /// The presenter. /// Type of the view controller to present. - /// Parent transform of the controller view. + /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult Present(this IPresenter presenter, Type controllerType, Transform transform) + public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentArgs args) { - return presenter.Present(controllerType, PresentOptions.Popup, transform, null); + return presenter.Present(controllerType, args, PresentOptions.None, null); } /// @@ -65,15 +65,15 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// /// The presenter. /// Type of the view controller to present. - /// Parent transform of the controller view. + /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static Task PresentAsync(this IPresenter presenter, Type controllerType, Transform transform) + public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args) { - return presenter.Present(controllerType, PresentOptions.Popup, transform, null).DismissTask; + return presenter.Present(controllerType, args, PresentOptions.None, null).DismissTask; } /// @@ -82,14 +82,15 @@ public static Task PresentAsync(this IPresenter presenter, Type controllerType, /// The presenter. /// Type of the view controller to present. /// Present options. + /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentOptions options) + public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentArgs args, PresentOptions options) { - return presenter.Present(controllerType, options, null, null); + return presenter.Present(controllerType, args, options, null); } /// @@ -98,14 +99,15 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// The presenter. /// Type of the view controller to present. /// Present options. + /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options) + public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args, PresentOptions options) { - return presenter.Present(controllerType, options, null, null).DismissTask; + return presenter.Present(controllerType, args, options, null).DismissTask; } /// @@ -113,16 +115,17 @@ public static Task PresentAsync(this IPresenter presenter, Type controllerType, /// /// The presenter. /// Type of the view controller to present. - /// Present options. /// Controller arguments. + /// Present options. + /// Parent transform of the controller view. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentOptions options, PresentArgs args) + public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args, PresentOptions options, Transform transform) { - return presenter.Present(controllerType, options, null, args); + return presenter.Present(controllerType, args, options, transform).DismissTask; } /// @@ -131,15 +134,14 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// The presenter. /// Type of the view controller to present. /// Present options. - /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options, PresentArgs args) + public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentOptions options) { - return presenter.Present(controllerType, options, null, args).DismissTask; + return presenter.Present(controllerType, null, options, null); } /// @@ -147,15 +149,15 @@ public static Task PresentAsync(this IPresenter presenter, Type controllerType, /// /// The presenter. /// Type of the view controller to present. - /// Controller arguments. + /// Present options. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentArgs args) + public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options) { - return presenter.Present(controllerType, PresentOptions.None, null, args); + return presenter.Present(controllerType, null, options, null).DismissTask; } /// @@ -163,69 +165,33 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// /// The presenter. /// Type of the view controller to present. - /// Controller arguments. + /// Present options. + /// Parent transform of the controller view. /// An object that can be used to track the operation progress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. /// - public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args) - { - return presenter.Present(controllerType, PresentOptions.None, null, args).DismissTask; - } - - /// - /// Presents a controller of the specified type. - /// - /// Type of the controller to instantiate. - /// The presenter. - /// An object that can be used to track the operation progress. - /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). - /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter) where TController : IViewController - { - return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, null); - } - - /// - /// Presents a controller of the specified type. - /// - /// Type of the controller to instantiate. - /// The presenter. - /// An object that can be used to track the operation progress. - /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). - /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentOptions options, Transform transform) { - return presenter.Present(typeof(TController), PresentOptions.None, null, null).DismissTask; + return presenter.Present(controllerType, null, options, transform); } /// /// Presents a controller of the specified type. /// - /// Type of the controller to instantiate. - /// The presenter. - /// Parent transform of the controller view. - /// An object that can be used to track the operation progress. - /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). - /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, Transform transform) where TController : IViewController - { - return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, null); - } - - /// - /// Presents a controller of the specified type. - /// - /// Type of the controller to instantiate. /// The presenter. + /// Type of the view controller to present. + /// Present options. /// Parent transform of the controller view. /// An object that can be used to track the operation progress. - /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). + /// Thrown if is . + /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, Transform transform) where TController : IViewController + /// + public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options, Transform transform) { - return presenter.Present(typeof(TController), PresentOptions.Popup, transform, null).DismissTask; + return presenter.Present(controllerType, null, options, transform).DismissTask; } /// @@ -233,14 +199,12 @@ public static Task PresentAsync(this IPresenter presenter, Transfor /// /// Type of the controller to instantiate. /// The presenter. - /// Present options. - /// Parent transform of the controller view. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), options, transform, null); + return (IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null); } /// @@ -248,14 +212,12 @@ public static IPresentResult Present(this IPresenter p /// /// Type of the controller to instantiate. /// The presenter. - /// Present options. - /// Parent transform of the controller view. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter) where TController : IViewController { - return presenter.Present(typeof(TController), options, transform, null).DismissTask; + return presenter.Present(typeof(TController), null, PresentOptions.None, null).DismissTask; } /// @@ -269,7 +231,7 @@ public static Task PresentAsync(this IPresenter presenter, PresentO /// Thrown if the presenter is disposed. public static IPresentResult Present(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, args); + return (IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null); } /// @@ -283,7 +245,7 @@ public static IPresentResult Present(this IPresenter p /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return presenter.Present(typeof(TController), PresentOptions.None, null, args).DismissTask; + return presenter.Present(typeof(TController), args, PresentOptions.None, null).DismissTask; } /// @@ -296,9 +258,9 @@ public static Task PresentAsync(this IPresenter presenter, PresentA /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentOptions options, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), options, null, args); + return (IPresentResult)presenter.Present(typeof(TController), args, options, null); } /// @@ -311,9 +273,9 @@ public static IPresentResult Present(this IPresenter p /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentOptions options, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController { - return presenter.Present(typeof(TController), options, null, args).DismissTask; + return presenter.Present(typeof(TController), args, options, null).DismissTask; } /// @@ -321,14 +283,15 @@ public static Task PresentAsync(this IPresenter presenter, PresentO /// /// Type of the controller to instantiate. /// The presenter. + /// Present options. /// Parent transform of the controller view. /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, args); + return (IPresentResult)presenter.Present(typeof(TController), args, options, transform); } /// @@ -336,14 +299,15 @@ public static IPresentResult Present(this IPresenter p /// /// Type of the controller to instantiate. /// The presenter. + /// Present options. /// Parent transform of the controller view. /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController { - return presenter.Present(typeof(TController), PresentOptions.Popup, transform, args).DismissTask; + return presenter.Present(typeof(TController), args, options, transform).DismissTask; } /// @@ -353,13 +317,12 @@ public static Task PresentAsync(this IPresenter presenter, Transfor /// The presenter. /// Present options. /// Parent transform of the controller view. - /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), options, transform, args); + return (IPresentResult)presenter.Present(typeof(TController), null, options, transform); } /// @@ -369,13 +332,12 @@ public static IPresentResult Present(this IPresenter p /// The presenter. /// Present options. /// Parent transform of the controller view. - /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return presenter.Present(typeof(TController), options, transform, args).DismissTask; + return presenter.Present(typeof(TController), null, options, transform).DismissTask; } /// @@ -390,7 +352,7 @@ public static Task PresentAsync(this IPresenter presenter, PresentO /// Thrown if the presenter is disposed. public static IPresentResult Present(this IPresenter presenter) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, null); + return (IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null); } /// @@ -405,7 +367,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, null)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null)).DismissTask; } /// @@ -421,7 +383,7 @@ public static Task PresentAsync(this IPresenter p /// Thrown if the presenter is disposed. public static IPresentResult Present(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, args); + return (IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null); } /// @@ -437,39 +399,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), PresentOptions.None, null, args)).DismissTask; - } - - /// - /// Presents a controller of the specified type. - /// - /// Type of the controller to instantiate. - /// Type of the controller result value. - /// The presenter. - /// Parent transform of the controller view. - /// An object that can be used to track the operation progress. - /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). - /// Thrown if the does not match result type of the . - /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, Transform transform) where TController : IViewController - { - return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, null); - } - - /// - /// Presents a controller of the specified type. - /// - /// Type of the controller to instantiate. - /// Type of the controller result value. - /// The presenter. - /// Parent transform of the controller view. - /// An object that can be used to track the operation progress. - /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). - /// Thrown if the does not match result type of the . - /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, Transform transform) where TController : IViewController - { - return ((IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, null)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null)).DismissTask; } /// @@ -478,15 +408,15 @@ public static Task PresentAsync(this IPresenter p /// Type of the controller to instantiate. /// Type of the controller result value. /// The presenter. + /// Controller arguments. /// Present options. - /// Parent transform of the controller view. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), options, transform, null); + return (IPresentResult)presenter.Present(typeof(TController), args, options, null); } /// @@ -495,15 +425,15 @@ public static IPresentResult Present /// Type of the controller to instantiate. /// Type of the controller result value. /// The presenter. + /// Controller arguments. /// Present options. - /// Parent transform of the controller view. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), options, transform, null)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), args, options, null)).DismissTask; } /// @@ -512,15 +442,16 @@ public static Task PresentAsync(this IPresenter p /// Type of the controller to instantiate. /// Type of the controller result value. /// The presenter. + /// Present options. /// Parent transform of the controller view. /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, args); + return (IPresentResult)presenter.Present(typeof(TController), args, options, transform); } /// @@ -529,15 +460,16 @@ public static IPresentResult Present /// Type of the controller to instantiate. /// Type of the controller result value. /// The presenter. + /// Present options. /// Parent transform of the controller view. /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, Transform transform, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), PresentOptions.Popup, transform, args)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), args, options, transform)).DismissTask; } /// @@ -548,14 +480,13 @@ public static Task PresentAsync(this IPresenter p /// The presenter. /// Present options. /// Parent transform of the controller view. - /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), options, transform, args); + return (IPresentResult)presenter.Present(typeof(TController), null, options, transform); } /// @@ -566,14 +497,13 @@ public static IPresentResult Present /// The presenter. /// Present options. /// Parent transform of the controller view. - /// Controller arguments. /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), options, transform, args)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), null, options, transform)).DismissTask; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs index b53cbc4..4560f2a 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -284,7 +284,7 @@ public void Dismiss() #region IPresenter - public IPresentResult Present(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) + public IPresentResult Present(Type controllerType, PresentArgs args, PresentOptions presentOptions, Transform parent) { ThrowIfDisposed(); return _presenter.PresentAsync(this, controllerType, presentOptions, parent, args); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs index 991f12f..6497c5f 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs @@ -342,7 +342,7 @@ int IPresenterInternal.GetNextId() #region IPresenter - public IPresentResult Present(Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) + public IPresentResult Present(Type controllerType, PresentArgs args, PresentOptions presentOptions, Transform parent) { return PresentInternal(null, controllerType, presentOptions, parent, args); } diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs index 341a407..bb3a305 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs @@ -46,14 +46,14 @@ public void InitialStateIsValid() [Test] public void Present_ThrownOnNullControllerType() { - Assert.Throws(() => _presenter.Present(null, PresentOptions.None, PresentArgs.Default)); + Assert.Throws(() => _presenter.Present(null)); } [Test] public void Present_ThrownOnInvalidControllerType() { - Assert.Throws(() => _presenter.Present(typeof(AbstractController), PresentOptions.None, PresentArgs.Default)); - Assert.Throws(() => _presenter.Present(typeof(InvalidController), PresentOptions.None, PresentArgs.Default)); + Assert.Throws(() => _presenter.Present(typeof(AbstractController))); + Assert.Throws(() => _presenter.Present(typeof(InvalidController))); } [Test] From ddeddd00cdc7e19c2c0f5d2bfcbd0c2906865880 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sat, 28 Dec 2019 17:03:00 +0200 Subject: [PATCH 05/34] Renamed DismissTask to Task --- .../Abstractions/Presenters/IPresentResult.cs | 8 ++--- .../IPresentResult{TController,TResult}.cs | 4 +-- .../Presenters/IPresenterExtensions.cs | 32 +++++++++---------- .../PresentResult{TController,TResult}.cs | 4 +-- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs index f4d7557..00dc1d3 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs @@ -8,7 +8,7 @@ namespace UnityFx.Mvc { /// - /// Result of a present operation. Can be used very much like . + /// Result of a present operation. Can be used very much like . /// /// /// @@ -27,12 +27,12 @@ public interface IPresentResult : IViewControllerInfo, ICommandTarget, IDisposab IView View { get; } /// - /// Gets a instance that can be used to await the operation completion (i.e. until the is dismissed). + /// Gets a instance that can be used to await the operation completion (i.e. until the is dismissed). /// - Task DismissTask { get; } + Task Task { get; } /// - /// Gets a instance that can be used to await the operation completion (i.e. until the is presented/visible). + /// Gets a instance that can be used to await the operation completion (i.e. until the is presented/visible). /// Task PresentTask { get; } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs index 898f1fb..0c40feb 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -27,6 +27,6 @@ public interface IPresentResult : IPresentResult /// Gets a instance that can be used to await the operatino completion. /// - new Task DismissTask { get; } + new Task Task { get; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs index aece493..4400bf8 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs @@ -41,7 +41,7 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// public static Task PresentAsync(this IPresenter presenter, Type controllerType) { - return presenter.Present(controllerType, null, PresentOptions.None, null).DismissTask; + return presenter.Present(controllerType, null, PresentOptions.None, null).Task; } /// @@ -73,7 +73,7 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args) { - return presenter.Present(controllerType, args, PresentOptions.None, null).DismissTask; + return presenter.Present(controllerType, args, PresentOptions.None, null).Task; } /// @@ -107,7 +107,7 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args, PresentOptions options) { - return presenter.Present(controllerType, args, options, null).DismissTask; + return presenter.Present(controllerType, args, options, null).Task; } /// @@ -125,7 +125,7 @@ public static Task PresentAsync(this IPresenter presenter, Type controllerType, /// public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args, PresentOptions options, Transform transform) { - return presenter.Present(controllerType, args, options, transform).DismissTask; + return presenter.Present(controllerType, args, options, transform).Task; } /// @@ -157,7 +157,7 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options) { - return presenter.Present(controllerType, null, options, null).DismissTask; + return presenter.Present(controllerType, null, options, null).Task; } /// @@ -191,7 +191,7 @@ public static IPresentResult Present(this IPresenter presenter, Type controllerT /// public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options, Transform transform) { - return presenter.Present(controllerType, null, options, transform).DismissTask; + return presenter.Present(controllerType, null, options, transform).Task; } /// @@ -217,7 +217,7 @@ public static IPresentResult Present(this IPresenter p /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter) where TController : IViewController { - return presenter.Present(typeof(TController), null, PresentOptions.None, null).DismissTask; + return presenter.Present(typeof(TController), null, PresentOptions.None, null).Task; } /// @@ -245,7 +245,7 @@ public static IPresentResult Present(this IPresenter p /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return presenter.Present(typeof(TController), args, PresentOptions.None, null).DismissTask; + return presenter.Present(typeof(TController), args, PresentOptions.None, null).Task; } /// @@ -275,7 +275,7 @@ public static IPresentResult Present(this IPresenter p /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController { - return presenter.Present(typeof(TController), args, options, null).DismissTask; + return presenter.Present(typeof(TController), args, options, null).Task; } /// @@ -307,7 +307,7 @@ public static IPresentResult Present(this IPresenter p /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController { - return presenter.Present(typeof(TController), args, options, transform).DismissTask; + return presenter.Present(typeof(TController), args, options, transform).Task; } /// @@ -337,7 +337,7 @@ public static IPresentResult Present(this IPresenter p /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return presenter.Present(typeof(TController), null, options, transform).DismissTask; + return presenter.Present(typeof(TController), null, options, transform).Task; } /// @@ -367,7 +367,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null)).Task; } /// @@ -399,7 +399,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null)).Task; } /// @@ -433,7 +433,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), args, options, null)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), args, options, null)).Task; } /// @@ -469,7 +469,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), args, options, transform)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), args, options, transform)).Task; } /// @@ -503,7 +503,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return ((IPresentResult)presenter.Present(typeof(TController), null, options, transform)).DismissTask; + return ((IPresentResult)presenter.Present(typeof(TController), null, options, transform)).Task; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs index 4560f2a..af43226 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs @@ -296,9 +296,7 @@ public IPresentResult Present(Type controllerType, PresentArgs args, PresentOpti IViewController IPresentResult.Controller => _controller; - Task IPresentResult.DismissTask => Task; - - Task IPresentResult.DismissTask => Task; + Task IPresentResult.Task => Task; Task IPresentResult.PresentTask { From b3a42b0198ea637d22f154e1d49c26cc38f50224 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sat, 28 Dec 2019 17:55:14 +0200 Subject: [PATCH 06/34] Added IViewControllerResult interface --- .../Attributes/ViewControllerAttribute.cs | 7 +--- .../Abstractions/Mvc/IViewController.cs | 2 +- .../Mvc/IViewControllerResult{TResult}.cs | 15 +++++++++ .../IViewControllerResult{TResult}.cs.meta | 11 +++++++ .../Presenters/IPresenterExtensions.cs | 20 ++++++------ .../Common/ActivatorUtilities.cs | 4 +-- .../Common/ActivatorUtilities.cs.meta | 0 .../Implementation/Presenters/Presenter{T}.cs | 32 ++----------------- .../ViewController{TView,TResult}.cs | 4 +-- 9 files changed, 45 insertions(+), 50 deletions(-) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta rename Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/{Abstractions => Implementation}/Common/ActivatorUtilities.cs (97%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/{Abstractions => Implementation}/Common/ActivatorUtilities.cs.meta (100%) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs index da8873d..51ea7f8 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -12,11 +12,6 @@ namespace UnityFx.Mvc [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class ViewControllerAttribute : Attribute { - /// - /// Gets or sets type of the controller result value. - /// - public Type ResultType { get; set; } - /// /// Gets or sets name of the view prefab. /// diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs index 033073f..b05b8ef 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs @@ -15,7 +15,7 @@ namespace UnityFx.Mvc /// /// /// - /// + /// /// public interface IViewController : ICommandTarget { diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs new file mode 100644 index 0000000..08f5d61 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs @@ -0,0 +1,15 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// A result value of a . + /// + /// + public interface IViewControllerResult + { + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta new file mode 100644 index 0000000..f1d2878 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a753d5d4ff1c20449aa1bea608af851c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs index 4400bf8..8f4e161 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs @@ -350,7 +350,7 @@ public static Task PresentAsync(this IPresenter presenter, PresentO /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter) where TController : IViewController, IViewControllerResult { return (IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null); } @@ -365,7 +365,7 @@ public static IPresentResult Present /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter) where TController : IViewController, IViewControllerResult { return ((IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null)).Task; } @@ -381,7 +381,7 @@ public static Task PresentAsync(this IPresenter p /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentArgs args) where TController : IViewController, IViewControllerResult { return (IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null); } @@ -397,7 +397,7 @@ public static IPresentResult Present /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController, IViewControllerResult { return ((IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null)).Task; } @@ -414,7 +414,7 @@ public static Task PresentAsync(this IPresenter p /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController, IViewControllerResult { return (IPresentResult)presenter.Present(typeof(TController), args, options, null); } @@ -431,7 +431,7 @@ public static IPresentResult Present /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController, IViewControllerResult { return ((IPresentResult)presenter.Present(typeof(TController), args, options, null)).Task; } @@ -449,7 +449,7 @@ public static Task PresentAsync(this IPresenter p /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult { return (IPresentResult)presenter.Present(typeof(TController), args, options, transform); } @@ -467,7 +467,7 @@ public static IPresentResult Present /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult { return ((IPresentResult)presenter.Present(typeof(TController), args, options, transform)).Task; } @@ -484,7 +484,7 @@ public static Task PresentAsync(this IPresenter p /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult { return (IPresentResult)presenter.Present(typeof(TController), null, options, transform); } @@ -501,7 +501,7 @@ public static IPresentResult Present /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult { return ((IPresentResult)presenter.Present(typeof(TController), null, options, transform)).Task; } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/ActivatorUtilities.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs similarity index 97% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/ActivatorUtilities.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs index e43fe81..410262a 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/ActivatorUtilities.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -12,7 +12,7 @@ namespace UnityFx.Mvc /// /// Defines -related helpers. /// - public static class ActivatorUtilities + internal static class ActivatorUtilities { #region interface diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/ActivatorUtilities.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/ActivatorUtilities.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs index 6497c5f..2243cfd 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs @@ -462,24 +462,18 @@ private IPresentable CreatePresentable(IPresentable parent, Type controllerTy Debug.Assert(!_disposed); var resultType = typeof(int); - var controllerAttr = default(ViewControllerAttribute); var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false); if (attrs != null && attrs.Length > 0) { - controllerAttr = attrs[0]; + var controllerAttr = attrs[0]; presentOptions |= controllerAttr.PresentOptions; - - if (controllerAttr.ResultType != null) - { - resultType = controllerAttr.ResultType; - } } // Types inherited from ViewController<,> do not require ViewControllerAttribute. - if (typeof(ViewController<,>).IsAssignableFrom(controllerType)) + if (typeof(IViewControllerResult<>).IsAssignableFrom(controllerType)) { - resultType = controllerType.GenericTypeArguments[1]; + resultType = controllerType.GenericTypeArguments[0]; } // Make sure args are valid. @@ -555,26 +549,6 @@ private void DisposeInternal() } } - private Type GetControllerResultType(Type controllerType) - { - // Types inherited from ViewController<> do not require ViewControllerAttribute. - if (typeof(ViewController<,>).IsAssignableFrom(controllerType)) - { - return controllerType.GenericTypeArguments[1]; - } - else - { - var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false); - - if (attrs != null && attrs.Length > 0) - { - return attrs[0].ResultType; - } - } - - return null; - } - private void SetBusy(bool busy) { if (busy) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs index d026735..a221f05 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -12,7 +12,7 @@ namespace UnityFx.Mvc /// Note that minimal controller implementation should implement . /// /// - public abstract class ViewController : ViewController where TView : class, IView + public abstract class ViewController : ViewController, IViewControllerResult where TView : class, IView { #region data #endregion From 6d19f75b28d0ba3d0af506d5cd6c1bcb1c2d895e Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 14:31:31 +0200 Subject: [PATCH 07/34] Some comments are added --- .../UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs | 7 ++++++- .../Scripts/Abstractions/Mvc/IViewControllerInfo.cs | 7 +++---- .../Scripts/Abstractions/Presenters/IPresentContext.cs | 3 +-- .../Presenters/PresentResult{TController,TResult}.cs | 2 +- .../Runtime/Scripts/Implementation/ViewController.cs | 7 +------ 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs index e09b3ac..b0d8ef4 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -10,7 +10,12 @@ namespace UnityFx.Mvc /// /// A generic view. /// + /// + /// In the Model-View-Controller (MVC) pattern, the view handles the app's data presentation and user interaction. + /// A view is a . Views are created via instance. + /// /// + /// /// public interface IView : IComponent, INotifyCommand { diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs index 7bfa060..1d57482 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs @@ -1,8 +1,7 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.Net; namespace UnityFx.Mvc { @@ -28,9 +27,9 @@ public interface IViewControllerInfo PresentOptions PresentOptions { get; } /// - /// Gets time elapsed since the controller has been created (in seconds). + /// Gets time elapsed since the controller has been presented (in seconds). /// - float Timer { get; } + float PresentTime { get; } /// /// Gets a value indicating whether the controller is active. diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs index 160aa7f..cd35977 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs @@ -1,8 +1,7 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.Net; namespace UnityFx.Mvc { diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs index af43226..02153f3 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs @@ -276,7 +276,7 @@ public void Dismiss() public PresentOptions PresentOptions => _presentOptions; - public float Timer => _timer; + public float PresentTime => _timer; public bool IsActive => _state == State.Active; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs index 0e44457..91f29a6 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -279,34 +279,29 @@ protected virtual void OnUpdate(float frameTime) #region IViewControllerEvents - /// void IViewControllerEvents.OnActivate() { Debug.Assert(!IsDismissed); OnActivate(); } - /// void IViewControllerEvents.OnDeactivate() { Debug.Assert(!IsDismissed); OnDeactivate(); } - /// void IViewControllerEvents.OnPresent() { Debug.Assert(!IsDismissed); OnPresent(); } - /// void IViewControllerEvents.OnDismiss() { OnDismiss(); } - /// void IViewControllerEvents.OnUpdate(float frameTime) { Debug.Assert(!IsDismissed); From 38f9f923d61b931a69af4071a67f73f02100337b Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 14:31:49 +0200 Subject: [PATCH 08/34] Added IConfigurable interface --- .../Abstractions/Commands/IConfigurable{T}.cs | 18 ++++++++++++++++++ .../Commands/IConfigurable{T}.cs.meta | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs new file mode 100644 index 0000000..72ee9c9 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs @@ -0,0 +1,18 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// A generic configurable entity. + /// + public interface IConfigurable + { + /// + /// Configures the instance with the passed. + /// + void Configure(T args); + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs.meta new file mode 100644 index 0000000..3f0b156 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ba9a4a8a3aedef84c9b04b076038aeeb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 848a66a519bf6cb7fea331e9389e2afb1505ce23 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 14:32:02 +0200 Subject: [PATCH 09/34] Added message box extensions --- .../Runtime/Scripts/Extensions.meta | 8 ++ .../Scripts/Extensions/MessageBox.meta | 8 ++ .../Extensions/MessageBox/MessageBoxArgs.cs | 70 +++++++++ .../MessageBox/MessageBoxArgs.cs.meta | 11 ++ .../MessageBox/MessageBoxController.cs | 80 +++++++++++ .../MessageBox/MessageBoxController.cs.meta | 11 ++ .../MessageBox/MessageBoxExtensions.cs | 41 ++++++ .../MessageBox/MessageBoxExtensions.cs.meta | 11 ++ .../MessageBox/MessageBoxOptions.cs | 54 +++++++ .../MessageBox/MessageBoxOptions.cs.meta | 11 ++ .../Extensions/MessageBox/MessageBoxResult.cs | 23 +++ .../MessageBox/MessageBoxResult.cs.meta | 11 ++ .../Extensions/MessageBox/MessageBoxView.cs | 136 ++++++++++++++++++ .../MessageBox/MessageBoxView.cs.meta | 11 ++ 14 files changed, 486 insertions(+) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions.meta new file mode 100644 index 0000000..09963b4 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 551014dd8977ac54485b2a7f110ae2f9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox.meta new file mode 100644 index 0000000..1e2ccba --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: af3cf08888b10f04094a6e8d6e732aa1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs new file mode 100644 index 0000000..c20470d --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs @@ -0,0 +1,70 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using UnityEngine; + +namespace UnityFx.Mvc.Extensions +{ + /// + /// A present arguments. + /// + public class MessageBoxArgs : PresentArgs + { + /// + /// Gets message box title text. + /// + public string Title { get; } + + /// + /// Gets message box text. + /// + public string Text { get; } + + /// + /// Gets OK button text. + /// + public string OkText { get; } + + /// + /// Gets CANCEL button text. + /// + public string CancelText { get; } + + /// + /// Gets the message box options. + /// + public MessageBoxOptions Options { get; } + + /// + /// Initializes a new instance of the class. + /// + public MessageBoxArgs(MessageBoxOptions options, string text) + { + Text = text; + Options = options; + } + + /// + /// Initializes a new instance of the class. + /// + public MessageBoxArgs(MessageBoxOptions options, string text, string title) + { + Text = text; + Title = title; + Options = options; + } + + /// + /// Initializes a new instance of the class. + /// + public MessageBoxArgs(MessageBoxOptions options, string text, string title, string okText, string cancelText) + { + Text = text; + Title = title; + OkText = okText; + CancelText = cancelText; + Options = options; + } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs.meta new file mode 100644 index 0000000..7880452 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 73f848c94918e9843aafc0606176b192 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs new file mode 100644 index 0000000..4d7eb6b --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs @@ -0,0 +1,80 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using UnityEngine; + +namespace UnityFx.Mvc.Extensions +{ + /// + /// Controller of a generic message box. + /// + /// + /// + /// + /// + [ViewController(PresentOptions = PresentOptions.Popup | PresentOptions.Modal)] + public class MessageBoxController : IViewController, IViewControllerResult + { + #region data + + private readonly IPresentContext _context; + + #endregion + + #region interface + + /// + /// Initializes a new instance of the class. + /// + public MessageBoxController(IPresentContext context) + { + _context = context; + + if (context.PresentArgs is MessageBoxArgs args && context.View is IConfigurable view) + { + view.Configure(args); + } + } + + #endregion + + #region IViewController + + /// + public IView View => _context.View; + + #endregion + + #region ICommandTarget + + /// + public bool InvokeCommand(string commandName, object args) + { + if (_context.IsDismissed || commandName is null) + { + return false; + } + + if (string.CompareOrdinal(commandName, ViewController.Commands.Ok) == 0) + { + _context.Dismiss(MessageBoxResult.Ok); + return true; + } + + if (string.CompareOrdinal(commandName, ViewController.Commands.Cancel) == 0 || + string.CompareOrdinal(commandName, ViewController.Commands.Close) == 0) + { + _context.Dismiss(MessageBoxResult.Cancel); + return true; + } + + return false; + } + + #endregion + + #region implementation + #endregion + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs.meta new file mode 100644 index 0000000..a659d4b --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 719bdbc427682774582089f4881bb1e2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs new file mode 100644 index 0000000..40f643c --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs @@ -0,0 +1,41 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using System.ComponentModel; +using System.Threading.Tasks; +using UnityEngine; + +namespace UnityFx.Mvc.Extensions +{ + /// + /// Extensions for -related entities. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static class MessageBoxExtensions + { + /// + /// Presents a message box with the specified . + /// + public static Task PresentMessageBoxAsync(this IPresenter presenter, MessageBoxOptions options, string text) + { + return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text))).Task; + } + + /// + /// Presents a message box with the specified and . + /// + public static Task PresentMessageBoxAsync(this IPresenter presenter, MessageBoxOptions options, string text, string title) + { + return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text, title))).Task; + } + + /// + /// Presents a message box with the specified and . + /// + public static Task PresentMessageBoxAsync(this IPresenter presenter, MessageBoxOptions options, string text, string title, string okText, string cancelText) + { + return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text, title, okText, cancelText))).Task; + } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs.meta new file mode 100644 index 0000000..0a9255e --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 24c53ccb8953d2444bb509f85b485748 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs new file mode 100644 index 0000000..3c55aff --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs @@ -0,0 +1,54 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc.Extensions +{ + /// + /// Enumerates results of a typical message box. + /// + [Flags] + public enum MessageBoxOptions + { + /// + /// No options. + /// + None = 0, + + /// + /// Message box with OK button. + /// + Ok = 1, + + /// + /// Message box with OK button. + /// + Cancel = 2, + + /// + /// Message box with OK and CANCEL buttons. + /// + OkCancel = Ok | Cancel, + + /// + /// Info box style. + /// + Info = 4, + + /// + /// Warning style. + /// + Warning = 8, + + /// + /// Error style. + /// + Error = 16, + + /// + /// Alert style. + /// + Alert = 32 + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs.meta new file mode 100644 index 0000000..6ffe59e --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 760ade2ec2c657348aee9cf88014e11f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs new file mode 100644 index 0000000..22912ee --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs @@ -0,0 +1,23 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc.Extensions +{ + /// + /// Enumerates results of a typical message box. + /// + public enum MessageBoxResult + { + /// + /// OK button was pressed. + /// + Ok, + + /// + /// CANCEL or CLOSE button was pressed. + /// + Cancel + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs.meta new file mode 100644 index 0000000..1978077 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 41c9397c5ef3c024a867fdadbf0226c0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs new file mode 100644 index 0000000..5428c7a --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs @@ -0,0 +1,136 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using UnityEngine; +using UnityEngine.UI; + +namespace UnityFx.Mvc.Extensions +{ + /// + /// View for the . + /// + /// + public class MessageBoxView : View, IConfigurable + { + #region data + +#pragma warning disable 0649 + + [SerializeField] + private Text _title; + [SerializeField] + private Text _text; + [SerializeField] + private Text _okText; + [SerializeField] + private Button _okButton; + [SerializeField] + private Text _cancelText; + [SerializeField] + private Button _cancelButton; + [SerializeField] + private Button _closeButton; + +#pragma warning restore 0649 + + #endregion + + #region MonoBehaviour + + private void OnEnable() + { + if (_okButton) + { + _okButton.onClick.AddListener(OnOk); + } + + if (_cancelButton) + { + _cancelButton.onClick.AddListener(OnCancel); + } + + if (_closeButton) + { + _closeButton.onClick.AddListener(OnClose); + } + } + + private void OnDisable() + { + if (_okButton) + { + _okButton.onClick.RemoveListener(OnOk); + } + + if (_cancelButton) + { + _cancelButton.onClick.RemoveListener(OnCancel); + } + + if (_closeButton) + { + _closeButton.onClick.RemoveListener(OnClose); + } + } + + #endregion + + #region IConfigurable + + /// + public void Configure(MessageBoxArgs args) + { + if (_title) + { + _title.text = args.Title; + } + + if (_text) + { + _text.text = args.Text; + } + + if (_okText && !string.IsNullOrEmpty(args.OkText)) + { + _okText.text = args.OkText; + } + + if (_cancelText && !string.IsNullOrEmpty(args.CancelText)) + { + _cancelText.text = args.CancelText; + } + + if (_okButton) + { + _okButton.gameObject.SetActive((args.Options & MessageBoxOptions.Ok) != 0); + } + + if (_cancelButton) + { + _cancelButton.gameObject.SetActive((args.Options & MessageBoxOptions.Cancel) != 0); + } + } + + #endregion + + #region implementation + + private void OnOk() + { + NotifyCommand(ViewController.Commands.Ok); + } + + private void OnCancel() + { + NotifyCommand(ViewController.Commands.Cancel); + } + + private void OnClose() + { + NotifyCommand(ViewController.Commands.Close); + } + + #endregion + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs.meta new file mode 100644 index 0000000..64282f1 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8e91b50bd57198944a85018b38baa4ef +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From f3108fd960f11cdf0942ca64fa2aefe529d07fcf Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 15:33:05 +0200 Subject: [PATCH 10/34] Refactoring or present results --- .../Mvc/IViewControllerAccess{TController}.cs | 27 ++++++++++ ...IViewControllerAccess{TController}.cs.meta | 11 ++++ .../IViewControllerResultAccess{TResult}.cs} | 15 +++--- ...iewControllerResultAccess{TResult}.cs.meta | 11 ++++ .../Abstractions/Presenters/IPresentResult.cs | 19 +------ .../IPresentResultOf{TController,TResult}.cs | 20 ++++++++ ...sentResultOf{TController,TResult}.cs.meta} | 0 ...r}.cs => IPresentResultOf{TController}.cs} | 8 +-- ... => IPresentResultOf{TController}.cs.meta} | 0 .../Presenters/IPresentResult{TResult}.cs | 20 ++++++++ .../IPresentResult{TResult}.cs.meta | 11 ++++ .../Presenters/IPresenterExtensions.cs | 50 +++++++++---------- .../MessageBox/MessageBoxExtensions.cs | 30 +++++++++-- .../Implementation/Presenters/IPresentable.cs | 4 +- .../Presenters/IPresentable{T}.cs | 2 +- .../PresentResult{TController,TResult}.cs | 38 +++++++------- .../Implementation/Presenters/Presenter{T}.cs | 2 +- 17 files changed, 185 insertions(+), 83 deletions(-) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta rename Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/{Presenters/IPresentResult{TController,TResult}.cs => Mvc/IViewControllerResultAccess{TResult}.cs} (69%) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs rename Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/{IPresentResult{TController,TResult}.cs.meta => IPresentResultOf{TController,TResult}.cs.meta} (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/{IPresentResult{TController}.cs => IPresentResultOf{TController}.cs} (53%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/{IPresentResult{TController}.cs.meta => IPresentResultOf{TController}.cs.meta} (100%) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs new file mode 100644 index 0000000..0df9a7f --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs @@ -0,0 +1,27 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using System.Threading.Tasks; + +namespace UnityFx.Mvc +{ + /// + /// Result of a present operation. Can be used very much like . + /// + /// + public interface IViewControllerAccess where TController : IViewController + { + /// + /// Gets the view controller. + /// + /// + TController Controller { get; } + + /// + /// Gets the view. + /// + /// + IView View { get; } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta new file mode 100644 index 0000000..39a5907 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86af53f35c78ef147a23e212c100faac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs similarity index 69% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs index 0c40feb..da71f32 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs @@ -2,16 +2,15 @@ // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace UnityFx.Mvc { /// - /// Result of a present operation. + /// Represents results of a present operation. /// - /// - public interface IPresentResult : IPresentResult where TController : IViewController + /// + public interface IViewControllerResultAccess { /// /// Gets the operation result value. @@ -21,12 +20,14 @@ public interface IPresentResult : IPresentResult property does not return a value. /// Instead, attempting to access the property value throws an exception. /// - /// Thrown if the property is accessed before operation is completed or the operation completed with errors. + /// Thrown if the property is accessed before operation is completed. + /// TResult Result { get; } /// - /// Gets a instance that can be used to await the operatino completion. + /// Gets a instance that can be used to await the operation completion. /// - new Task Task { get; } + /// + Task Task { get; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta new file mode 100644 index 0000000..0b56bc6 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b24e80292872d4d4d98adef579930ac3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs index 00dc1d3..516f6d9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs @@ -12,28 +12,11 @@ namespace UnityFx.Mvc /// /// /// - public interface IPresentResult : IViewControllerInfo, ICommandTarget, IDisposable + public interface IPresentResult : ICommandTarget, IDisposable { - /// - /// Gets the view controller. - /// - /// - /// - IViewController Controller { get; } - - /// - /// Gets the view. - /// - IView View { get; } - /// /// Gets a instance that can be used to await the operation completion (i.e. until the is dismissed). /// Task Task { get; } - - /// - /// Gets a instance that can be used to await the operation completion (i.e. until the is presented/visible). - /// - Task PresentTask { get; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs new file mode 100644 index 0000000..1de6ebc --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs @@ -0,0 +1,20 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using System.Threading.Tasks; + +namespace UnityFx.Mvc +{ + /// + /// Result of a present operation. + /// + /// + public interface IPresentResultOf : IPresentResult, IViewControllerResultAccess, IViewControllerAccess where TController : IViewController + { + /// + /// Gets a instance that can be used to await the operation completion. + /// + new Task Task { get; } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController,TResult}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs similarity index 53% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs index 17ac671..0d7fda9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -10,11 +10,7 @@ namespace UnityFx.Mvc /// Result of a present operation. /// /// - public interface IPresentResult : IPresentResult where TController : IViewController + public interface IPresentResultOf : IPresentResult, IViewControllerAccess where TController : IViewController { - /// - /// Gets the view controller. - /// - new TController Controller { get; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TController}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs new file mode 100644 index 0000000..e387dbe --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs @@ -0,0 +1,20 @@ +// Copyright (c) Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using System.Threading.Tasks; + +namespace UnityFx.Mvc +{ + /// + /// Result of a present operation. + /// + /// + public interface IPresentResult : IPresentResult, IViewControllerResultAccess + { + /// + /// Gets a instance that can be used to await the operation completion. + /// + new Task Task { get; } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs.meta new file mode 100644 index 0000000..f311e64 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bfc1d02456d24494d9b6ac161f18c780 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs index 8f4e161..6296dad 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs @@ -202,9 +202,9 @@ public static Task PresentAsync(this IPresenter presenter, Type controllerType, /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter) where TController : IViewController + public static IPresentResultOf Present(this IPresenter presenter) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null); + return (IPresentResultOf)presenter.Present(typeof(TController), null, PresentOptions.None, null); } /// @@ -229,9 +229,9 @@ public static Task PresentAsync(this IPresenter presenter) where TC /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args) where TController : IViewController + public static IPresentResultOf Present(this IPresenter presenter, PresentArgs args) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null); + return (IPresentResultOf)presenter.Present(typeof(TController), args, PresentOptions.None, null); } /// @@ -258,9 +258,9 @@ public static Task PresentAsync(this IPresenter presenter, PresentA /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController + public static IPresentResultOf Present(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), args, options, null); + return (IPresentResultOf)presenter.Present(typeof(TController), args, options, null); } /// @@ -289,9 +289,9 @@ public static Task PresentAsync(this IPresenter presenter, PresentA /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController + public static IPresentResultOf Present(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), args, options, transform); + return (IPresentResultOf)presenter.Present(typeof(TController), args, options, transform); } /// @@ -320,9 +320,9 @@ public static Task PresentAsync(this IPresenter presenter, PresentA /// An object that can be used to track the operation progress. /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController + public static IPresentResultOf Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController { - return (IPresentResult)presenter.Present(typeof(TController), null, options, transform); + return (IPresentResultOf)presenter.Present(typeof(TController), null, options, transform); } /// @@ -350,9 +350,9 @@ public static Task PresentAsync(this IPresenter presenter, PresentO /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter) where TController : IViewController, IViewControllerResult + public static IPresentResultOf Present(this IPresenter presenter) where TController : IViewController, IViewControllerResult { - return (IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null); + return (IPresentResultOf)presenter.Present(typeof(TController), null, PresentOptions.None, null); } /// @@ -367,7 +367,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter) where TController : IViewController, IViewControllerResult { - return ((IPresentResult)presenter.Present(typeof(TController), null, PresentOptions.None, null)).Task; + return ((IPresentResultOf)presenter.Present(typeof(TController), null, PresentOptions.None, null)).Task; } /// @@ -381,9 +381,9 @@ public static Task PresentAsync(this IPresenter p /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args) where TController : IViewController, IViewControllerResult + public static IPresentResultOf Present(this IPresenter presenter, PresentArgs args) where TController : IViewController, IViewControllerResult { - return (IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null); + return (IPresentResultOf)presenter.Present(typeof(TController), args, PresentOptions.None, null); } /// @@ -399,7 +399,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args) where TController : IViewController, IViewControllerResult { - return ((IPresentResult)presenter.Present(typeof(TController), args, PresentOptions.None, null)).Task; + return ((IPresentResultOf)presenter.Present(typeof(TController), args, PresentOptions.None, null)).Task; } /// @@ -414,9 +414,9 @@ public static Task PresentAsync(this IPresenter p /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController, IViewControllerResult + public static IPresentResultOf Present(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController, IViewControllerResult { - return (IPresentResult)presenter.Present(typeof(TController), args, options, null); + return (IPresentResultOf)presenter.Present(typeof(TController), args, options, null); } /// @@ -433,7 +433,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController, IViewControllerResult { - return ((IPresentResult)presenter.Present(typeof(TController), args, options, null)).Task; + return ((IPresentResultOf)presenter.Present(typeof(TController), args, options, null)).Task; } /// @@ -449,9 +449,9 @@ public static Task PresentAsync(this IPresenter p /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult + public static IPresentResultOf Present(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult { - return (IPresentResult)presenter.Present(typeof(TController), args, options, transform); + return (IPresentResultOf)presenter.Present(typeof(TController), args, options, transform); } /// @@ -469,7 +469,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult { - return ((IPresentResult)presenter.Present(typeof(TController), args, options, transform)).Task; + return ((IPresentResultOf)presenter.Present(typeof(TController), args, options, transform)).Task; } /// @@ -484,9 +484,9 @@ public static Task PresentAsync(this IPresenter p /// Thrown if cannot be used to instantiate the controller (for instance it is abstract type). /// Thrown if the does not match result type of the . /// Thrown if the presenter is disposed. - public static IPresentResult Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult + public static IPresentResultOf Present(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult { - return (IPresentResult)presenter.Present(typeof(TController), null, options, transform); + return (IPresentResultOf)presenter.Present(typeof(TController), null, options, transform); } /// @@ -503,7 +503,7 @@ public static IPresentResult Present /// Thrown if the presenter is disposed. public static Task PresentAsync(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult { - return ((IPresentResult)presenter.Present(typeof(TController), null, options, transform)).Task; + return ((IPresentResultOf)presenter.Present(typeof(TController), null, options, transform)).Task; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs index 40f643c..b4e466a 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs @@ -14,12 +14,28 @@ namespace UnityFx.Mvc.Extensions [EditorBrowsable(EditorBrowsableState.Never)] public static class MessageBoxExtensions { + /// + /// Presents a message box with the specified . + /// + public static IPresentResult PresentMessageBox(this IPresenter presenter, MessageBoxOptions options, string text) + { + return (IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text)); + } + /// /// Presents a message box with the specified . /// public static Task PresentMessageBoxAsync(this IPresenter presenter, MessageBoxOptions options, string text) { - return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text))).Task; + return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text))).Task; + } + + /// + /// Presents a message box with the specified and . + /// + public static IPresentResult PresentMessageBox(this IPresenter presenter, MessageBoxOptions options, string text, string title) + { + return (IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text, title)); } /// @@ -27,7 +43,15 @@ public static Task PresentMessageBoxAsync(this IPresenter pres /// public static Task PresentMessageBoxAsync(this IPresenter presenter, MessageBoxOptions options, string text, string title) { - return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text, title))).Task; + return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text, title))).Task; + } + + /// + /// Presents a message box with the specified and . + /// + public static IPresentResult PresentMessageBox(this IPresenter presenter, MessageBoxOptions options, string text, string title, string okText, string cancelText) + { + return (IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text, title, okText, cancelText)); } /// @@ -35,7 +59,7 @@ public static Task PresentMessageBoxAsync(this IPresenter pres /// public static Task PresentMessageBoxAsync(this IPresenter presenter, MessageBoxOptions options, string text, string title, string okText, string cancelText) { - return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text, title, okText, cancelText))).Task; + return ((IPresentResult)presenter.Present(typeof(MessageBoxController), new MessageBoxArgs(options, text, title, okText, cancelText))).Task; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs index d674b3f..b177679 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -8,7 +8,7 @@ namespace UnityFx.Mvc { - internal interface IPresentable : IPresentResult, ICommandTarget + internal interface IPresentable : IPresentResult, IViewControllerInfo { bool IsDismissed { get; } IPresentable Parent { get; } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs index beb8333..0141ec6 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs @@ -8,7 +8,7 @@ namespace UnityFx.Mvc { - internal interface IPresentable : IPresentable, IPresentResult where T : IViewController + internal interface IPresentable : IPresentable, IPresentResultOf where T : IViewController { } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs index 02153f3..1cbe047 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs @@ -20,7 +20,7 @@ namespace UnityFx.Mvc /// controller context outside of actual controller. This class manages the controller created, provides its context /// (via interface) and serves as a proxy between the controller and user. /// - internal class PresentResult : TaskCompletionSource, IPresentContext, IPresentResult, IPresentable, IEnumerator where TController : class, IViewController + internal class PresentResult : TaskCompletionSource, IPresentContext, IPresentResult, IPresentResultOf, IPresentResultOf, IPresentable, IEnumerator where TController : class, IViewController { #region data @@ -294,27 +294,25 @@ public IPresentResult Present(Type controllerType, PresentArgs args, PresentOpti #region IPresentResult - IViewController IPresentResult.Controller => _controller; - Task IPresentResult.Task => Task; - Task IPresentResult.PresentTask - { - get - { - if (_presentTcs is null) - { - if (_state != State.Initialized) - { - return System.Threading.Tasks.Task.CompletedTask; - } - - _presentTcs = new TaskCompletionSource(); - } - - return _presentTcs.Task; - } - } + ////Task IPresentResult.PresentTask + ////{ + //// get + //// { + //// if (_presentTcs is null) + //// { + //// if (_state != State.Initialized) + //// { + //// return System.Threading.Tasks.Task.CompletedTask; + //// } + + //// _presentTcs = new TaskCompletionSource(); + //// } + + //// return _presentTcs.Task; + //// } + ////} public TController Controller => _controller; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs index 2243cfd..5e3f077 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs @@ -195,7 +195,7 @@ public void DismissAllPopups() /// /// Gets top popup controller or . /// - protected IPresentResult GetPresentResult(T controller) + protected IPresentResultOf GetPresentResult(T controller) { foreach (var p in _presentables) { From fe03ce313d6bbc4b7d84ee89b84109963fd2d86d Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 18:46:05 +0200 Subject: [PATCH 11/34] Added code comments --- .../Attributes/ViewControllerAttribute.cs | 2 +- .../Abstractions/Commands/CommandEventArgs.cs | 2 +- .../Abstractions/Commands/ICommandTarget.cs | 2 +- .../Abstractions/Commands/IConfigurable{T}.cs | 2 +- .../Abstractions/Commands/INotifyCommand.cs | 2 +- .../Abstractions/Common/PresentArgs.cs | 2 +- .../Abstractions/Common/PresentArgs{T}.cs | 2 +- .../Abstractions/Common/PresentOptions.cs | 2 +- .../Runtime/Scripts/Abstractions/Mvc/IView.cs | 2 +- .../Abstractions/Mvc/IViewController.cs | 3 +- .../Mvc/IViewControllerAccess{TController}.cs | 6 +- .../Mvc/IViewControllerCollection.cs | 3 +- .../Abstractions/Mvc/IViewControllerEvents.cs | 4 +- .../Mvc/IViewControllerFactory.cs | 22 ++-- .../Abstractions/Mvc/IViewControllerInfo.cs | 39 ------- .../Mvc/IViewControllerInfo.cs.meta | 11 -- .../IViewControllerResultAccess{TResult}.cs | 4 +- .../Mvc/IViewControllerResult{TResult}.cs | 4 +- .../Scripts/Abstractions/Mvc/IViewFactory.cs | 10 +- .../Presenters/IPresentContext.cs | 41 +++++-- .../Presenters/IPresentContext{TResult}.cs | 7 +- .../Abstractions/Presenters/IPresentResult.cs | 11 +- .../IPresentResultOf{TController,TResult}.cs | 2 +- .../IPresentResultOf{TController}.cs | 2 +- .../Presenters/IPresentResult{TResult}.cs | 5 +- .../Abstractions/Presenters/IPresenter.cs | 8 +- .../Presenters/IPresenterExtensions.cs | 2 +- .../Extensions/MessageBox/MessageBoxArgs.cs | 2 +- .../MessageBox/MessageBoxController.cs | 2 +- .../MessageBox/MessageBoxExtensions.cs | 2 +- .../MessageBox/MessageBoxOptions.cs | 2 +- .../Extensions/MessageBox/MessageBoxResult.cs | 2 +- .../Extensions/MessageBox/MessageBoxView.cs | 2 +- .../Common/ActivatorUtilities.cs | 2 +- .../Implementation/Common/AssemblyInfo.cs | 2 +- .../Implementation/Presenters/IPresentable.cs | 6 +- .../Presenters/IPresentableExtensions.cs | 2 +- .../Presenters/IPresentable{T}.cs | 2 +- .../Presenters/IPresenterInternal.cs | 6 +- .../PresentResult{TController,TResult}.cs | 102 ++++-------------- .../Implementation/Presenters/Presenter.cs | 2 +- .../Presenters/PresenterBase.cs | 2 +- .../Implementation/Presenters/Presenter{T}.cs | 32 +++++- .../Scripts/Implementation/ViewController.cs | 2 +- .../Implementation/ViewControllerFactory.cs | 50 +++++++-- .../ViewController{TView,TResult}.cs | 2 +- .../Implementation/ViewController{TView}.cs | 2 +- .../Scripts/Implementation/Views/View.cs | 2 +- .../Views/ViewFactory.ViewCollection.cs | 2 +- .../Views/ViewFactory.ViewProxy.cs | 2 +- .../Implementation/Views/ViewFactory.cs | 4 +- .../Scripts/Controllers/AbstractController.cs | 2 +- .../Scripts/Controllers/InvalidController.cs | 2 +- .../Scripts/Controllers/MinimalController.cs | 2 +- .../Scripts/Controllers/TimerController.cs | 2 +- .../Scripts/Helpers/DefaultViewFactory.cs | 4 +- .../Tests/Editor/Scripts/PresenterTests.cs | 2 +- Assets/Scripts/AppRoot.cs | 4 +- Assets/Scripts/Splash/SplashController.cs | 2 +- 59 files changed, 224 insertions(+), 234 deletions(-) delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs index 51ea7f8..fb65b07 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/CommandEventArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/CommandEventArgs.cs index a6f91c3..c4269d9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/CommandEventArgs.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/CommandEventArgs.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/ICommandTarget.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/ICommandTarget.cs index 3f09453..028050d 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/ICommandTarget.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/ICommandTarget.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs index 72ee9c9..3623eef 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/INotifyCommand.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/INotifyCommand.cs index b73fdd4..df35c82 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/INotifyCommand.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/INotifyCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs.cs index 0c6c15f..1f854b9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs{T}.cs index bb937b6..a1afb21 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs{T}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentOptions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentOptions.cs index a1a547b..3184767 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentOptions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs index b0d8ef4..00a24df 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs index b05b8ef..f1da6ff 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -10,6 +10,7 @@ namespace UnityFx.Mvc /// /// /// As the name states, main responsibility of a view controller is managing its view. + /// Controllers are created via a instance. /// /// /// diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs index 0df9a7f..9fd47b4 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs @@ -1,14 +1,14 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.Threading.Tasks; namespace UnityFx.Mvc { /// - /// Result of a present operation. Can be used very much like . + /// Manages access to a controller of a specific type. /// + /// Type of the controller. /// public interface IViewControllerAccess where TController : IViewController { diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerCollection.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerCollection.cs index 43c8576..2fbb45c 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerCollection.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -10,7 +10,6 @@ namespace UnityFx.Mvc /// A collection of items. /// /// - /// public interface IViewControllerCollection : IReadOnlyCollection { /// diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerEvents.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerEvents.cs index ee04495..4e05bca 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerEvents.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerEvents.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -6,7 +6,7 @@ namespace UnityFx.Mvc { /// - /// Defines event handlers for a presentable obejct. + /// Defines event handlers for a implementation. /// /// public interface IViewControllerEvents diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerFactory.cs index 3b0641a..342effe 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -6,7 +6,7 @@ namespace UnityFx.Mvc { /// - /// A factory of instances. + /// Provides methods for creation and disposal of view controllers. /// /// public interface IViewControllerFactory @@ -14,18 +14,26 @@ public interface IViewControllerFactory /// /// Creates a scoped instance. /// - /// A service provider passed to the controller created by the factory. + /// A used to resolve controller dependencies. /// A disposable scope created or . - IDisposable CreateControllerScope(ref IServiceProvider serviceProvider); + IDisposable CreateScope(ref IServiceProvider serviceProvider); /// /// Creates a new instance of and injects its dependencies. /// /// Type of the controller to be created. - /// Additional arguments to use when injecting controller dependencies. + /// Additional arguments to use when resolving controller dependencies. /// Thrown if is . - /// Thrown if is not a valid controller type. + /// Thrown if is not a valid controller type (for instance, is abstract). /// The created controller instance. - IViewController CreateController(Type controllerType, params object[] args); + /// + IViewController Create(Type controllerType, params object[] args); + + /// + /// Releases a controller after it has been dismissed. + /// + /// The controller to be disposed. + /// + void Release(IViewController controller); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs deleted file mode 100644 index 1d57482..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Alexander Bogarsukov. -// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; - -namespace UnityFx.Mvc -{ - /// - /// Read-only view controller info. - /// - /// - public interface IViewControllerInfo - { - /// - /// Gets unique identifier of the controller. - /// - int Id { get; } - - /// - /// Gets the controller present arguments. - /// - PresentArgs PresentArgs { get; } - - /// - /// Gets the present flags used when instantiating the controller. - /// - PresentOptions PresentOptions { get; } - - /// - /// Gets time elapsed since the controller has been presented (in seconds). - /// - float PresentTime { get; } - - /// - /// Gets a value indicating whether the controller is active. - /// - bool IsActive { get; } - } -} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs.meta deleted file mode 100644 index ac96eed..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerInfo.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b5dbe7af29f99494eb94f3818c25cb48 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs index da71f32..f87c121 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -7,7 +7,7 @@ namespace UnityFx.Mvc { /// - /// Represents results of a present operation. + /// Manages access to result of a present operation. /// /// public interface IViewControllerResultAccess diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs index 08f5d61..fa96d0c 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -6,7 +6,7 @@ namespace UnityFx.Mvc { /// - /// A result value of a . + /// Tag interface for all implementations that have a result value. /// /// public interface IViewControllerResult diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewFactory.cs index 74cc41e..b6de0d6 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -9,18 +9,18 @@ namespace UnityFx.Mvc { /// - /// A factory of instances. + /// Provides methods for creation and disposal of views. /// /// public interface IViewFactory { /// - /// Creates a view for the specified controller. + /// Creates a view for a controller of the specified type. /// - /// Type of the view controller. + /// Type of the view controller to create view for. /// Z-order index. /// Present options. /// Parent transform for the view (or ). - Task CreateViewAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent); + Task CreateAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs index cd35977..ec2f621 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -6,23 +6,52 @@ namespace UnityFx.Mvc { /// - /// Context data for an instance. The class is a link between and its controllers. - /// It is here for the sake of testability/explicit dependencies for implementations. + /// Context data for a instance. The class is a link between and its controllers. /// + /// /// - public interface IPresentContext : IViewControllerInfo, IPresenter, IServiceProvider + public interface IPresentContext : IPresenter, IServiceProvider { /// - /// Gets the controller view. + /// Gets unique identifier of the controller. /// - IView View { get; } + int Id { get; } + + /// + /// Gets the controller present arguments. + /// + /// + PresentArgs PresentArgs { get; } + + /// + /// Gets the present flags used when instantiating the controller. + /// + /// + PresentOptions PresentOptions { get; } + + /// + /// Gets time elapsed since the controller has been presented (in seconds). + /// + float PresentTime { get; } + + /// + /// Gets a value indicating whether the controller is active. + /// + /// + bool IsActive { get; } /// /// Gets a value indicating whether the controller is dismissed. /// /// + /// bool IsDismissed { get; } + /// + /// Gets the controller view. + /// + IView View { get; } + /// /// Schedules a callback to be called in the specified . /// diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext{TResult}.cs index c499628..9543e7f 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext{TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext{TResult}.cs @@ -1,20 +1,19 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.Net; namespace UnityFx.Mvc { /// /// Context data for an instance. The class is a link between and its controllers. - /// It is here for the sake of testability/explicit dependencies for implementations. /// + /// /// public interface IPresentContext : IPresentContext { /// - /// Dismisses the controller. + /// Dismisses the controller with a specific . /// void Dismiss(TResult result); } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs index 516f6d9..951363e 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -8,14 +8,19 @@ namespace UnityFx.Mvc { /// - /// Result of a present operation. Can be used very much like . + /// Result of a present operation. Disposing the present result dismisses the attached controller (and its view). /// /// /// public interface IPresentResult : ICommandTarget, IDisposable { /// - /// Gets a instance that can be used to await the operation completion (i.e. until the is dismissed). + /// Gets unique identifier of the present operation. + /// + int Id { get; } + + /// + /// Gets a instance that can be used to await the operation completion (i.e. until the controller is dismissed). /// Task Task { get; } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs index 1de6ebc..8381ebf 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs index 0d7fda9..351c601 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs index e387dbe..ea8d7f2 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -7,8 +7,9 @@ namespace UnityFx.Mvc { /// - /// Result of a present operation. + /// Result of a present operation having with a result. /// + /// Type of the result value. /// public interface IPresentResult : IPresentResult, IViewControllerResultAccess { diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs index 1de4f6e..fe1e0ca 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -9,6 +9,10 @@ namespace UnityFx.Mvc /// /// An object capable of presenting view controllers. /// + /// + /// Please note that users of this type should not access or its directly. + /// Instead, can be used to track the controller lifetime events or to dismiss it. + /// /// /// /// @@ -21,7 +25,7 @@ public interface IPresenter /// Controller arguments. /// Present flags. /// Parent transform for the view (or ). - /// An object that can be used to track the operation progress. + /// An object that can be used to track the operation propress. /// Thrown if is . /// Thrown if cannot be used to instantiate the controller (for instance, it is abstract type). /// Thrown if the presenter is disposed. diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs index 6296dad..18940a5 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs index c20470d..df55099 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs index 4d7eb6b..0dba86a 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs index b4e466a..471870e 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs index 3c55aff..e0f19ea 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs index 22912ee..d981378 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs index 5428c7a..cd7aa4f 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs index 410262a..2d7e9b9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs index f3e7f47..e49a921 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System.Reflection; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs index b177679..176bb93 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -8,10 +8,12 @@ namespace UnityFx.Mvc { - internal interface IPresentable : IPresentResult, IViewControllerInfo + internal interface IPresentable : IPresentResult { + bool IsActive { get; } bool IsDismissed { get; } IPresentable Parent { get; } + PresentOptions PresentOptions { get; } Task PresentAsync(IViewFactory viewFactory, int index, Transform parent); void Update(float frameTime, bool isTop); void DismissUnsafe(); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentableExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentableExtensions.cs index 70966e1..640f5df 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentableExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentableExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs index 0141ec6..9620f80 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresenterInternal.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresenterInternal.cs index 09090ae..9fe9e6f 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresenterInternal.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresenterInternal.cs @@ -1,9 +1,7 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.Threading; -using System.Threading.Tasks; using UnityEngine; namespace UnityFx.Mvc @@ -11,6 +9,8 @@ namespace UnityFx.Mvc internal interface IPresenterInternal { IServiceProvider ServiceProvider { get; } + IViewFactory ViewFactory { get; } + IViewControllerFactory ControllerFactory { get; } IPresentResult PresentAsync(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args); void Dismiss(IPresentable presentable); int GetNextId(); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs index 1cbe047..164714e 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -41,6 +41,7 @@ private struct TimerData } private readonly IPresenterInternal _presenter; + private readonly IViewControllerFactory _controllerFactory; private readonly Type _controllerType; private readonly PresentArgs _presentArgs; private readonly PresentOptions _presentOptions; @@ -50,13 +51,13 @@ private struct TimerData private IServiceProvider _serviceProvider; private IDisposable _scope; private TController _controller; + private IViewControllerEvents _controllerEvents; private IView _view; private LinkedList _timers; private float _timer; private List _exceptions; - private TaskCompletionSource _presentTcs; private State _state; #endregion @@ -73,6 +74,7 @@ public PresentResult(IPresenterInternal presenter, IPresentable parent, Type con _presenter = presenter; _parent = parent; _serviceProvider = presenter.ServiceProvider; + _controllerFactory = presenter.ControllerFactory; _controllerType = controllerType; _presentArgs = args; _presentOptions = presentOptions; @@ -90,12 +92,7 @@ public bool TryActivate() if (_state == State.Presented) { _state = State.Active; - - if (_controller is IViewControllerEvents c) - { - c.OnActivate(); - } - + _controllerEvents?.OnActivate(); return true; } @@ -107,12 +104,7 @@ public bool TryDeactivate() if (_state == State.Active) { _state = State.Presented; - - if (_controller is IViewControllerEvents c) - { - c.OnDeactivate(); - } - + _controllerEvents?.OnDeactivate(); return true; } @@ -126,7 +118,7 @@ public async Task PresentAsync(IViewFactory viewFactory, int index, Transform pa try { - _view = await viewFactory.CreateViewAsync(_controllerType, index, _presentOptions, parent); + _view = await viewFactory.CreateAsync(_controllerType, index, _presentOptions, parent); if (_state == State.Initialized) { @@ -135,30 +127,12 @@ public async Task PresentAsync(IViewFactory viewFactory, int index, Transform pa throw new InvalidOperationException(); } - if (_serviceProvider.GetService(typeof(IViewControllerFactory)) is IViewControllerFactory controllerFactory) - { - _scope = controllerFactory.CreateControllerScope(ref _serviceProvider); - _controller = (TController)controllerFactory.CreateController(_controllerType, this, _presentArgs, _view); - } - else - { - _controller = (TController)ActivatorUtilities.CreateInstance(_serviceProvider, _controllerType, this, _presentArgs, _view); - } - - if (_controller is null) - { - throw new InvalidOperationException(); - } - + _scope = _controllerFactory.CreateScope(ref _serviceProvider); + _controller = (TController)_controllerFactory.Create(_controllerType, this, _presentArgs, _view); + _controllerEvents = _controller as IViewControllerEvents; + _controllerEvents?.OnPresent(); _view.Disposed += OnDismissed; - - if (_controller is IViewControllerEvents c) - { - c.OnPresent(); - } - _state = State.Presented; - _presentTcs?.TrySetResult(_controller); } else { @@ -169,8 +143,6 @@ public async Task PresentAsync(IViewFactory viewFactory, int index, Transform pa } catch (Exception e) { - _presentTcs?.TrySetException(e); - LogException(e); DismissInternal(default, true); } @@ -296,24 +268,6 @@ public IPresentResult Present(Type controllerType, PresentArgs args, PresentOpti Task IPresentResult.Task => Task; - ////Task IPresentResult.PresentTask - ////{ - //// get - //// { - //// if (_presentTcs is null) - //// { - //// if (_state != State.Initialized) - //// { - //// return System.Threading.Tasks.Task.CompletedTask; - //// } - - //// _presentTcs = new TaskCompletionSource(); - //// } - - //// return _presentTcs.Task; - //// } - ////} - public TController Controller => _controller; public TResult Result => Task.Result; @@ -405,12 +359,7 @@ private void DismissInternal(TResult result, bool cancelled) if (_state != State.Disposed) { _state = State.Disposed; - - if (_controller is IDisposable d) - { - d.Dispose(); - } - + _controllerFactory.Release(_controller); _view?.Dispose(); _scope?.Dispose(); } @@ -445,21 +394,13 @@ private void UpdateActive(bool isTop) if (_state == State.Presented) { _state = State.Active; - - if (_controller is IViewControllerEvents c) - { - c.OnActivate(); - } + _controllerEvents?.OnActivate(); } } else if (_state == State.Active) { _state = State.Presented; - - if (_controller is IViewControllerEvents c) - { - c.OnDeactivate(); - } + _controllerEvents?.OnDeactivate(); } } catch (Exception e) @@ -470,16 +411,13 @@ private void UpdateActive(bool isTop) private void UpdateController(float frameTime) { - if (_controller is IViewControllerEvents c) + try { - try - { - c.OnUpdate(frameTime); - } - catch (Exception e) - { - Debug.LogException(e); - } + _controllerEvents?.OnUpdate(frameTime); + } + catch (Exception e) + { + Debug.LogException(e); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter.cs index 7192ec0..c6c2d60 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresenterBase.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresenterBase.cs index a39f0a4..9a71be1 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresenterBase.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresenterBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs index 5e3f077..75f3879 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -23,6 +23,7 @@ public class Presenter : PresenterBase, IPresenterInternal, IPresenter, IComm private IServiceProvider _serviceProvider; private IViewFactory _viewFactory; + private IViewControllerFactory _controllerFactory; private LinkedList> _presentables = new LinkedList>(); private ViewControllerCollection _controllers; @@ -159,14 +160,35 @@ public T ActiveController protected bool IsDisposed => _disposed; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. + /// + /// A used to resolve controller dependencies. + /// + public void Initialize(IServiceProvider serviceProvider) + { + if (serviceProvider is null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + + var viewFactory = (IViewFactory)serviceProvider.GetService(typeof(IViewFactory)); + var viewControllerFactory = (IViewControllerFactory)(serviceProvider.GetService(typeof(IViewControllerFactory)) ?? new ViewControllerFactory(serviceProvider)); + + Initialize(serviceProvider, viewFactory, viewControllerFactory); + } + + /// + /// Initializes a new instance of the class. /// /// A used to resolve controller dependencies. /// A that is used to create views. - public void Initialize(IServiceProvider serviceProvider, IViewFactory viewFactory) + /// A used to create controller. + /// + public void Initialize(IServiceProvider serviceProvider, IViewFactory viewFactory, IViewControllerFactory controllerFactory) { _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); _viewFactory = viewFactory ?? throw new ArgumentNullException(nameof(viewFactory)); + _controllerFactory = controllerFactory ?? throw new ArgumentNullException(nameof(controllerFactory)); _controllers = new ViewControllerCollection(_presentables); } @@ -285,6 +307,10 @@ private void OnDestroy() #region IPresenterInternal + IViewFactory IPresenterInternal.ViewFactory => _viewFactory; + + IViewControllerFactory IPresenterInternal.ControllerFactory => _controllerFactory; + IPresentResult IPresenterInternal.PresentAsync(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) { return PresentInternal(presentable, controllerType, presentOptions, parent, args); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs index 91f29a6..65dc1ea 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs index 7700f8c..c2897a9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs @@ -1,17 +1,15 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.ComponentModel; -using System.Diagnostics; namespace UnityFx.Mvc { /// - /// Default implementation of . + /// Provides methods for creation and disposal of view controllers. /// - /// - public abstract class ViewControllerFactory : IViewControllerFactory + /// + public class ViewControllerFactory : IViewControllerFactory { #region data @@ -25,7 +23,7 @@ public abstract class ViewControllerFactory : IViewControllerFactory /// Initializes a new instance of the class. /// /// The instance to use. - protected ViewControllerFactory(IServiceProvider serviceProvider) + public ViewControllerFactory(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); } @@ -34,18 +32,48 @@ protected ViewControllerFactory(IServiceProvider serviceProvider) #region IViewControllerFactory - /// - public virtual IDisposable CreateControllerScope(ref IServiceProvider serviceProvider) + /// + /// Creates a scoped instance. Default implementation does not create scopes. + /// + /// A used to resolve controller dependencies. + /// A disposable scope created or . + public virtual IDisposable CreateScope(ref IServiceProvider serviceProvider) { return null; } - /// - public virtual IViewController CreateController(Type controllerType, params object[] args) + /// + /// Creates a new instance of and injects its dependencies. + /// + /// Type of the controller to be created. + /// Additional arguments to use when resolving controller dependencies. + /// Thrown if is . + /// Thrown if is not a valid controller type (for instance, is abstract). + /// The created controller instance. + /// + public virtual IViewController Create(Type controllerType, params object[] args) { + if (controllerType is null) + { + throw new ArgumentNullException(nameof(controllerType)); + } + return (IViewController)ActivatorUtilities.CreateInstance(_serviceProvider, controllerType, args); } + /// + /// Releases a controller after it has been dismissed. Default implementation calls if controller supports it. + /// + /// The controller to be disposed. + /// + public virtual void Release(IViewController controller) + { + if (controller is IDisposable d) + { + d.Dispose(); + } + } + #endregion #region implementation diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs index a221f05..3d5e8ed 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView}.cs index d3fdb8a..d425bc1 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView}.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/View.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/View.cs index 11f065c..74490b1 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/View.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/View.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs index 61ace97..62616c1 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewProxy.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewProxy.cs index 3b82644..4bfed85 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewProxy.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewProxy.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs index e534805..356d4d5 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -160,7 +160,7 @@ private void OnDestroy() #region IViewFactory - public async Task CreateViewAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent) + public async Task CreateAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent) { ThrowIfDisposed(); diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/AbstractController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/AbstractController.cs index aaa8db3..7ed4f04 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/AbstractController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/AbstractController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/InvalidController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/InvalidController.cs index 26b4de5..30bf5fd 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/InvalidController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/InvalidController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/MinimalController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/MinimalController.cs index 7e5c283..be78d57 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/MinimalController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/MinimalController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/TimerController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/TimerController.cs index 978caba..5e49fc9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/TimerController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/TimerController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultViewFactory.cs index 8c8fabc..9e424ea 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultViewFactory.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. +// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. // See the LICENSE.md file in the project root for more information. using System; @@ -10,7 +10,7 @@ namespace UnityFx.Mvc { public class DefaultViewFactory : IViewFactory { - public async Task CreateViewAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent) + public async Task CreateAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent) { await Task.Delay(10); return new DefaultView(); diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs index bb3a305..05c8142 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs @@ -27,7 +27,7 @@ public void Init() _go = new GameObject("PresenterTest"); _presenter = _go.AddComponent(); - _presenter.Initialize(_serviceProvider, _viewFactory); + _presenter.Initialize(_serviceProvider, _viewFactory, new ViewControllerFactory(_serviceProvider)); } [TearDown] diff --git a/Assets/Scripts/AppRoot.cs b/Assets/Scripts/AppRoot.cs index d1db154..d5b6069 100644 --- a/Assets/Scripts/AppRoot.cs +++ b/Assets/Scripts/AppRoot.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -24,7 +24,7 @@ private void Awake() _viewFactory = gameObject.AddComponent(); } - _presenter.Initialize(this, _viewFactory); + _presenter.Initialize(this); } private async void Start() diff --git a/Assets/Scripts/Splash/SplashController.cs b/Assets/Scripts/Splash/SplashController.cs index 8ad0fa4..3839f3f 100644 --- a/Assets/Scripts/Splash/SplashController.cs +++ b/Assets/Scripts/Splash/SplashController.cs @@ -1,4 +1,4 @@ -// Copyright (c) Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; From 043f3ab3d87929e4447caaef9af1359b62c04288 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 19:52:15 +0200 Subject: [PATCH 12/34] Changed package structure --- .editorconfig | 2 +- .../Editor/{Scripts.meta => Inspectors.meta} | 2 +- .../PresenterEditor.cs | 0 .../PresenterEditor.cs.meta | 0 .../ViewFactoryEditor.cs | 0 .../ViewFactoryEditor.cs.meta | 0 .../ViewProxyEditor.cs | 0 .../ViewProxyEditor.cs.meta | 0 .../Editor/Scripts/MenuExtensions.cs | 16 --- .../Editor/UnityFx.Mvc.Editor.asmdef | 1 + .../Editor/{Scripts => }/Windows.meta | 0 .../Windows/CreateViewControllerWindow.cs | 0 .../CreateViewControllerWindow.cs.meta | 0 .../Runtime/{Scripts => }/Abstractions.meta | 0 .../Abstractions/Attributes.meta | 0 .../Attributes/ViewControllerAttribute.cs | 0 .../ViewControllerAttribute.cs.meta | 0 .../{Scripts => }/Abstractions/Commands.meta | 0 .../Abstractions/Commands/CommandEventArgs.cs | 0 .../Commands/CommandEventArgs.cs.meta | 0 .../Abstractions/Commands/ICommandTarget.cs | 0 .../Commands/ICommandTarget.cs.meta | 0 .../Abstractions/Commands/IConfigurable{T}.cs | 0 .../Commands/IConfigurable{T}.cs.meta | 0 .../Abstractions/Commands/INotifyCommand.cs | 0 .../Commands/INotifyCommand.cs.meta | 0 .../{Scripts => }/Abstractions/Common.meta | 0 .../Abstractions/Common/AssemblyInfo.cs | 39 ++++++ .../Common/AssemblyInfo.cs.meta} | 2 +- .../Abstractions/Common/PresentArgs.cs | 0 .../Abstractions/Common/PresentArgs.cs.meta | 0 .../Abstractions/Common/PresentArgs{T}.cs | 0 .../Common/PresentArgs{T}.cs.meta | 0 .../Abstractions/Common/PresentOptions.cs | 0 .../Common/PresentOptions.cs.meta | 0 .../{Scripts => }/Abstractions/Mvc.meta | 0 .../{Scripts => }/Abstractions/Mvc/IView.cs | 0 .../Abstractions/Mvc/IView.cs.meta | 0 .../Abstractions/Mvc/IViewController.cs | 0 .../Abstractions/Mvc/IViewController.cs.meta | 0 .../Mvc/IViewControllerAccess{TController}.cs | 0 ...IViewControllerAccess{TController}.cs.meta | 0 .../Mvc/IViewControllerCollection.cs | 0 .../Mvc/IViewControllerCollection.cs.meta | 0 .../Abstractions/Mvc/IViewControllerEvents.cs | 0 .../Mvc/IViewControllerEvents.cs.meta | 0 .../Mvc/IViewControllerFactory.cs | 0 .../Mvc/IViewControllerFactory.cs.meta | 0 .../IViewControllerResultAccess{TResult}.cs | 0 ...iewControllerResultAccess{TResult}.cs.meta | 0 .../Mvc/IViewControllerResult{TResult}.cs | 0 .../IViewControllerResult{TResult}.cs.meta | 0 .../Abstractions/Mvc/IViewFactory.cs | 0 .../Abstractions/Mvc/IViewFactory.cs.meta | 0 .../Views => Abstractions/Mvc}/View.cs | 0 .../Views => Abstractions/Mvc}/View.cs.meta | 0 .../Mvc}/ViewController.cs | 0 .../Mvc}/ViewController.cs.meta | 0 .../Mvc}/ViewControllerFactory.cs | 82 ++++++++++- .../Mvc}/ViewControllerFactory.cs.meta | 0 .../Mvc}/ViewController{TView,TResult}.cs | 0 .../ViewController{TView,TResult}.cs.meta | 0 .../Mvc}/ViewController{TView}.cs | 0 .../Mvc}/ViewController{TView}.cs.meta | 0 .../Abstractions/Presenters.meta | 0 .../Presenters/IPresentContext.cs | 0 .../Presenters/IPresentContext.cs.meta | 0 .../Presenters/IPresentContext{TResult}.cs | 0 .../IPresentContext{TResult}.cs.meta | 0 .../Abstractions/Presenters/IPresentResult.cs | 0 .../Presenters/IPresentResult.cs.meta | 0 .../IPresentResultOf{TController,TResult}.cs | 0 ...esentResultOf{TController,TResult}.cs.meta | 0 .../IPresentResultOf{TController}.cs | 0 .../IPresentResultOf{TController}.cs.meta | 0 .../Presenters/IPresentResult{TResult}.cs | 0 .../IPresentResult{TResult}.cs.meta | 0 .../Abstractions/Presenters/IPresenter.cs | 0 .../Presenters/IPresenter.cs.meta | 0 .../Presenters/IPresenterExtensions.cs | 0 .../Presenters/IPresenterExtensions.cs.meta | 0 .../UnityFx.Mvc.Abstractions.asmdef | 3 + .../UnityFx.Mvc.Abstractions.asmdef.meta | 7 + .../Implementation.meta => Core.meta} | 0 .../Implementation => Core}/Common.meta | 0 .../Common/AssemblyInfo.cs | 6 +- .../Common/AssemblyInfo.cs.meta | 0 .../Implementation => Core}/Presenters.meta | 0 .../Presenters/IPresentable.cs | 0 .../Presenters/IPresentable.cs.meta | 0 .../Presenters/IPresentableExtensions.cs | 0 .../Presenters/IPresentableExtensions.cs.meta | 0 .../Presenters/IPresentable{T}.cs | 0 .../Presenters/IPresentable{T}.cs.meta | 0 .../Presenters/IPresenterInternal.cs | 0 .../Presenters/IPresenterInternal.cs.meta | 0 .../PresentResult{TController,TResult}.cs | 0 ...PresentResult{TController,TResult}.cs.meta | 0 .../Presenters/Presenter.cs | 0 .../Presenters/Presenter.cs.meta | 0 .../Presenters/PresenterBase.cs | 0 .../Presenters/PresenterBase.cs.meta | 0 .../Presenters/Presenter{TController}.cs} | 32 ++--- .../Presenter{TController}.cs.meta} | 0 .../Runtime/Core/UnityFx.Mvc.asmdef | 14 ++ .../{ => Core}/UnityFx.Mvc.asmdef.meta | 0 .../Implementation => Core}/Views.meta | 0 .../Views/ViewFactory.ViewCollection.cs | 0 .../Views/ViewFactory.ViewCollection.cs.meta | 0 .../Views/ViewFactory.ViewProxy.cs | 0 .../Views/ViewFactory.ViewProxy.cs.meta | 0 .../Views/ViewFactory.cs | 0 .../Views/ViewFactory.cs.meta | 0 .../Runtime/{Scripts => }/Extensions.meta | 0 .../Extensions/Common.meta} | 2 +- .../Runtime/Extensions/Common/AssemblyInfo.cs | 39 ++++++ .../Extensions/Common/AssemblyInfo.cs.meta} | 2 +- .../{Scripts => }/Extensions/MessageBox.meta | 0 .../Extensions/MessageBox/MessageBoxArgs.cs | 0 .../MessageBox/MessageBoxArgs.cs.meta | 0 .../MessageBox/MessageBoxController.cs | 0 .../MessageBox/MessageBoxController.cs.meta | 0 .../MessageBox/MessageBoxExtensions.cs | 0 .../MessageBox/MessageBoxExtensions.cs.meta | 0 .../MessageBox/MessageBoxOptions.cs | 0 .../MessageBox/MessageBoxOptions.cs.meta | 0 .../Extensions/MessageBox/MessageBoxResult.cs | 0 .../MessageBox/MessageBoxResult.cs.meta | 0 .../Extensions/MessageBox/MessageBoxView.cs | 0 .../MessageBox/MessageBoxView.cs.meta | 0 .../Extensions/UnityFx.Mvc.Extensions.asmdef | 14 ++ .../UnityFx.Mvc.Extensions.asmdef.meta | 7 + .../Common/ActivatorUtilities.cs | 128 ------------------ .../UnityFx.Mvc/Runtime/UnityFx.Mvc.asmdef | 3 - .../Editor/{Scripts => }/Controllers.meta | 0 .../Controllers/AbstractController.cs | 0 .../Controllers/AbstractController.cs.meta | 0 .../Controllers/InvalidController.cs | 0 .../Controllers/InvalidController.cs.meta | 0 .../Controllers/MinimalController.cs | 0 .../Controllers/MinimalController.cs.meta | 0 .../Controllers/TimerController.cs | 0 .../Controllers/TimerController.cs.meta | 0 .../Tests/Editor/{Scripts => }/Helpers.meta | 0 .../Helpers/DefaultServiceProvider.cs | 0 .../Helpers/DefaultServiceProvider.cs.meta | 0 .../{Scripts => }/Helpers/DefaultView.cs | 0 .../{Scripts => }/Helpers/DefaultView.cs.meta | 0 .../Helpers/DefaultViewFactory.cs | 0 .../Helpers/DefaultViewFactory.cs.meta | 0 .../Scripts.meta => Tests/Editor/Tests.meta} | 2 +- .../{Scripts => Tests}/PresenterTests.cs | 0 .../{Scripts => Tests}/PresenterTests.cs.meta | 0 .../{Scripts => Tests}/ViewFactoryTests.cs | 0 .../ViewFactoryTests.cs.meta | 0 .../Editor/UnityFx.Mvc.Editor.Tests.asmdef | 1 + 156 files changed, 231 insertions(+), 173 deletions(-) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts.meta => Inspectors.meta} (77%) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => Inspectors}/PresenterEditor.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => Inspectors}/PresenterEditor.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => Inspectors}/ViewFactoryEditor.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => Inspectors}/ViewFactoryEditor.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => Inspectors}/ViewProxyEditor.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => Inspectors}/ViewProxyEditor.cs.meta (100%) delete mode 100644 Assets/Plugins/UnityFx.Mvc/Editor/Scripts/MenuExtensions.cs rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => }/Windows.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => }/Windows/CreateViewControllerWindow.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Editor/{Scripts => }/Windows/CreateViewControllerWindow.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Attributes.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Attributes/ViewControllerAttribute.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Attributes/ViewControllerAttribute.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands/CommandEventArgs.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands/CommandEventArgs.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands/ICommandTarget.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands/ICommandTarget.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands/IConfigurable{T}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands/IConfigurable{T}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands/INotifyCommand.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Commands/INotifyCommand.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Common.meta (100%) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/AssemblyInfo.cs rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation/Common/ActivatorUtilities.cs.meta => Abstractions/Common/AssemblyInfo.cs.meta} (83%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Common/PresentArgs.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Common/PresentArgs.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Common/PresentArgs{T}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Common/PresentArgs{T}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Common/PresentOptions.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Common/PresentOptions.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IView.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IView.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewController.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewController.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerAccess{TController}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerCollection.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerCollection.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerEvents.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerEvents.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerFactory.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerFactory.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerResult{TResult}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewFactory.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Mvc/IViewFactory.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation/Views => Abstractions/Mvc}/View.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation/Views => Abstractions/Mvc}/View.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Abstractions/Mvc}/ViewController.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Abstractions/Mvc}/ViewController.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Abstractions/Mvc}/ViewControllerFactory.cs (56%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Abstractions/Mvc}/ViewControllerFactory.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Abstractions/Mvc}/ViewController{TView,TResult}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Abstractions/Mvc}/ViewController{TView,TResult}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Abstractions/Mvc}/ViewController{TView}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Abstractions/Mvc}/ViewController{TView}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentContext.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentContext.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentContext{TResult}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentContext{TResult}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentResult.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentResult.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentResultOf{TController}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentResultOf{TController}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentResult{TResult}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresentResult{TResult}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresenter.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresenter.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresenterExtensions.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Abstractions/Presenters/IPresenterExtensions.cs.meta (100%) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/UnityFx.Mvc.Abstractions.asmdef create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/UnityFx.Mvc.Abstractions.asmdef.meta rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation.meta => Core.meta} (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Common.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Common/AssemblyInfo.cs (86%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Common/AssemblyInfo.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/IPresentable.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/IPresentable.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/IPresentableExtensions.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/IPresentableExtensions.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/IPresentable{T}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/IPresentable{T}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/IPresenterInternal.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/IPresenterInternal.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/PresentResult{TController,TResult}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/PresentResult{TController,TResult}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/Presenter.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/Presenter.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/PresenterBase.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Presenters/PresenterBase.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation/Presenters/Presenter{T}.cs => Core/Presenters/Presenter{TController}.cs} (90%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation/Presenters/Presenter{T}.cs.meta => Core/Presenters/Presenter{TController}.cs.meta} (100%) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Core/UnityFx.Mvc.asmdef rename Assets/Plugins/UnityFx.Mvc/Runtime/{ => Core}/UnityFx.Mvc.asmdef.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Views.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Views/ViewFactory.ViewCollection.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Views/ViewFactory.ViewCollection.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Views/ViewFactory.ViewProxy.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Views/ViewFactory.ViewProxy.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Views/ViewFactory.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts/Implementation => Core}/Views/ViewFactory.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions.meta (100%) rename Assets/Plugins/UnityFx.Mvc/{Tests/Editor/Scripts.meta => Runtime/Extensions/Common.meta} (77%) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common/AssemblyInfo.cs rename Assets/Plugins/UnityFx.Mvc/{Editor/Scripts/MenuExtensions.cs.meta => Runtime/Extensions/Common/AssemblyInfo.cs.meta} (83%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxArgs.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxArgs.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxController.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxController.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxExtensions.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxExtensions.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxOptions.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxOptions.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxResult.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxResult.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxView.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/{Scripts => }/Extensions/MessageBox/MessageBoxView.cs.meta (100%) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/UnityFx.Mvc.Extensions.asmdef create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/UnityFx.Mvc.Extensions.asmdef.meta delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/UnityFx.Mvc.asmdef rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers/AbstractController.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers/AbstractController.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers/InvalidController.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers/InvalidController.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers/MinimalController.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers/MinimalController.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers/TimerController.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Controllers/TimerController.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Helpers.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Helpers/DefaultServiceProvider.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Helpers/DefaultServiceProvider.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Helpers/DefaultView.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Helpers/DefaultView.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Helpers/DefaultViewFactory.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => }/Helpers/DefaultViewFactory.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/{Runtime/Scripts.meta => Tests/Editor/Tests.meta} (77%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => Tests}/PresenterTests.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => Tests}/PresenterTests.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => Tests}/ViewFactoryTests.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Tests/Editor/{Scripts => Tests}/ViewFactoryTests.cs.meta (100%) diff --git a/.editorconfig b/.editorconfig index c5ec6d0..e9e93bf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,7 +5,7 @@ root = true # Use tabs for indentation. [*] -charset = utf-8 +charset = utf-8-bom end_of_line = crlf insert_final_newline = true indent_style = tab diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts.meta b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors.meta similarity index 77% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts.meta rename to Assets/Plugins/UnityFx.Mvc/Editor/Inspectors.meta index 1cf5d63..f865241 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts.meta +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 02b6e768c2f56214ba2c2835364eed87 +guid: 94faaafd3fb3d28488ca0fc2f7c74b09 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/PresenterEditor.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/PresenterEditor.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/PresenterEditor.cs rename to Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/PresenterEditor.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/PresenterEditor.cs.meta b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/PresenterEditor.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/PresenterEditor.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/PresenterEditor.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/ViewFactoryEditor.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/ViewFactoryEditor.cs rename to Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/ViewFactoryEditor.cs.meta b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/ViewFactoryEditor.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/ViewProxyEditor.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/ViewProxyEditor.cs rename to Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/ViewProxyEditor.cs.meta b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/ViewProxyEditor.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/MenuExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/MenuExtensions.cs deleted file mode 100644 index 2f2003e..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/MenuExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. -// See the LICENSE.md file in the project root for more information. - -using System; -using UnityEditor; -using UnityEngine; - -namespace UnityFx.Mvc -{ - /// - /// Unity menu extensions. - /// - public static class MenuExtensions - { - } -} diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/UnityFx.Mvc.Editor.asmdef b/Assets/Plugins/UnityFx.Mvc/Editor/UnityFx.Mvc.Editor.asmdef index 3712748..0e631bb 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/UnityFx.Mvc.Editor.asmdef +++ b/Assets/Plugins/UnityFx.Mvc/Editor/UnityFx.Mvc.Editor.asmdef @@ -1,6 +1,7 @@ { "name": "UnityFx.Mvc.Editor", "references": [ + "UnityFx.Mvc.Abstractions", "UnityFx.Mvc" ], "optionalUnityReferences": [], diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows.meta b/Assets/Plugins/UnityFx.Mvc/Editor/Windows.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows.meta rename to Assets/Plugins/UnityFx.Mvc/Editor/Windows.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows/CreateViewControllerWindow.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows/CreateViewControllerWindow.cs rename to Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows/CreateViewControllerWindow.cs.meta b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/Windows/CreateViewControllerWindow.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Attributes/ViewControllerAttribute.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/CommandEventArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/CommandEventArgs.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/CommandEventArgs.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/CommandEventArgs.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/ICommandTarget.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTarget.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/ICommandTarget.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTarget.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/ICommandTarget.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTarget.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/ICommandTarget.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTarget.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/IConfigurable{T}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/IConfigurable{T}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/IConfigurable{T}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/IConfigurable{T}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/IConfigurable{T}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/INotifyCommand.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/INotifyCommand.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/INotifyCommand.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/INotifyCommand.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/INotifyCommand.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/INotifyCommand.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Commands/INotifyCommand.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/INotifyCommand.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/AssemblyInfo.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/AssemblyInfo.cs new file mode 100644 index 0000000..d11c435 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/AssemblyInfo.cs @@ -0,0 +1,39 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UnityFx.Mvc.Abstractions")] +[assembly: AssemblyDescription("MVC framework for Unity.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnityFx.Mvc")] +[assembly: AssemblyCopyright("Copyright © 2018-2020 Alexander Bogarsukov")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8596BBA3-E5F5-4678-9472-9E88A647F74B")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + +// Editor assembly should access core internals. +[assembly: InternalsVisibleTo("UnityFx.Mvc.Editor")] diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/AssemblyInfo.cs.meta similarity index 83% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/AssemblyInfo.cs.meta index 6b4c14b..330c66e 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs.meta +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/AssemblyInfo.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0be6a428b7aff4d4f83c90dbf5242a9b +guid: 8458305ea4335d7439998f6302ae2042 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs{T}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs{T}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs{T}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs{T}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs{T}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentArgs{T}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs{T}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentOptions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentOptions.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentOptions.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentOptions.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentOptions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentOptions.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Common/PresentOptions.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentOptions.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IView.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IView.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IView.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IView.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IView.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewController.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewController.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewController.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewController.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewController.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerAccess{TController}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerAccess{TController}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerAccess{TController}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerCollection.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerCollection.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerCollection.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerCollection.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerCollection.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerCollection.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerCollection.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerCollection.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerEvents.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerEvents.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerEvents.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerEvents.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerEvents.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerEvents.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerEvents.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerEvents.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerFactory.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerFactory.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerFactory.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerFactory.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerFactory.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerFactory.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerFactory.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerResultAccess{TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerResult{TResult}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerResult{TResult}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewControllerResult{TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewFactory.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewFactory.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewFactory.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewFactory.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewFactory.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Mvc/IViewFactory.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewFactory.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/View.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/View.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/View.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/View.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerFactory.cs similarity index 56% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerFactory.cs index c2897a9..f4c0571 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerFactory.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; +using System.Reflection; +using System.Runtime.ExceptionServices; namespace UnityFx.Mvc { @@ -58,7 +60,33 @@ public virtual IViewController Create(Type controllerType, params object[] args) throw new ArgumentNullException(nameof(controllerType)); } - return (IViewController)ActivatorUtilities.CreateInstance(_serviceProvider, controllerType, args); + try + { + var constructors = controllerType.GetConstructors(BindingFlags.Instance | BindingFlags.Public); + + if (constructors.Length > 0) + { + // Select the first public non-static ctor with matching arguments. + foreach (var ctor in constructors) + { + if (TryGetMethodArguments(ctor, args, out var argValues)) + { + return (IViewController)ctor.Invoke(argValues); + } + } + + throw new InvalidOperationException($"A suitable constructor for type '{controllerType}' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor."); + } + else + { + return (IViewController)Activator.CreateInstance(controllerType); + } + } + catch (TargetInvocationException e) + { + ExceptionDispatchInfo.Capture(e.InnerException).Throw(); + throw e.InnerException; + } } /// @@ -77,6 +105,58 @@ public virtual void Release(IViewController controller) #endregion #region implementation + + private bool TryGetMethodArguments(MethodBase method, object[] args, out object[] argValues) + { + var argInfo = method.GetParameters(); + var argumentsValidated = true; + + argValues = new object[argInfo.Length]; + + for (var i = 0; i < argInfo.Length; ++i) + { + var argType = argInfo[i].ParameterType; + var argValue = default(object); + + // Try to match the argument using args first. + for (var j = 0; j < args.Length; ++j) + { + var arg = args[j]; + + if (arg != null && argType.IsAssignableFrom(arg.GetType())) + { + argValue = arg; + break; + } + } + + // If argument matching failed try to resolve the argument using serviceProvider. + if (argValue == null) + { + argValue = _serviceProvider.GetService(argType); + } + + // If the argument is matched/resolved, store the value, otherwise fail the constructor validation. + if (argValue != null) + { + argValues[i] = argValue; + } + else + { + argumentsValidated = false; + break; + } + } + + // If all arguments matched/resolved, use this constructor for activation. + if (argumentsValidated) + { + return true; + } + + return false; + } + #endregion } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerFactory.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewControllerFactory.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerFactory.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController{TView,TResult}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController{TView,TResult}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController{TView,TResult}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView,TResult}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController{TView,TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController{TView}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController{TView}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController{TView}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/ViewController{TView}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController{TView}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext{TResult}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext{TResult}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext{TResult}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext{TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext{TResult}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentContext{TResult}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext{TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResultOf{TController,TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResultOf{TController}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResultOf{TController}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResultOf{TController}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResultOf{TController}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResultOf{TController}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult{TResult}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult{TResult}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult{TResult}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresentResult{TResult}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult{TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenter.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenter.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenter.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenter.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenter.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenterExtensions.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenterExtensions.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenterExtensions.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Abstractions/Presenters/IPresenterExtensions.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenterExtensions.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/UnityFx.Mvc.Abstractions.asmdef b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/UnityFx.Mvc.Abstractions.asmdef new file mode 100644 index 0000000..f682de4 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/UnityFx.Mvc.Abstractions.asmdef @@ -0,0 +1,3 @@ +{ + "name": "UnityFx.Mvc.Abstractions" +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/UnityFx.Mvc.Abstractions.asmdef.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/UnityFx.Mvc.Abstractions.asmdef.meta new file mode 100644 index 0000000..62fd6a7 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/UnityFx.Mvc.Abstractions.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2b10b0ce15871aa4c8b8aa574809b662 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Common.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Common.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Common/AssemblyInfo.cs similarity index 86% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Common/AssemblyInfo.cs index e49a921..f6bd637 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Common/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System.Reflection; @@ -13,12 +13,12 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("UnityFx.Mvc")] -[assembly: AssemblyCopyright("Copyright © Alexander Bogarsukov 2018-2019")] +[assembly: AssemblyCopyright("Copyright © 2018-2020 Alexander Bogarsukov")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Common/AssemblyInfo.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/AssemblyInfo.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Common/AssemblyInfo.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentableExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentableExtensions.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentableExtensions.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentableExtensions.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentableExtensions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentableExtensions.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentableExtensions.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentableExtensions.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable{T}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable{T}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable{T}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresentable{T}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable{T}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresenterInternal.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresenterInternal.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresenterInternal.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresenterInternal.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresenterInternal.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresenterInternal.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/IPresenterInternal.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresenterInternal.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresentResult{TController,TResult}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresenterBase.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresenterBase.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresenterBase.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresenterBase.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresenterBase.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresenterBase.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/PresenterBase.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresenterBase.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs similarity index 90% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs index 75f3879..af999c1 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs @@ -17,7 +17,7 @@ namespace UnityFx.Mvc /// /// /// - public class Presenter : PresenterBase, IPresenterInternal, IPresenter, ICommandTarget, IDisposable where T : class, IViewController + public class Presenter : PresenterBase, IPresenterInternal, IPresenter, ICommandTarget, IDisposable where TController : class, IViewController { #region data @@ -25,7 +25,7 @@ public class Presenter : PresenterBase, IPresenterInternal, IPresenter, IComm private IViewFactory _viewFactory; private IViewControllerFactory _controllerFactory; - private LinkedList> _presentables = new LinkedList>(); + private LinkedList> _presentables = new LinkedList>(); private ViewControllerCollection _controllers; private int _idCounter; @@ -39,11 +39,11 @@ public class Presenter : PresenterBase, IPresenterInternal, IPresenter, IComm /// /// A read-only stack of objects. /// - public class ViewControllerCollection : IReadOnlyCollection + public class ViewControllerCollection : IReadOnlyCollection { - private readonly LinkedList> _presentables; + private readonly LinkedList> _presentables; - internal ViewControllerCollection(LinkedList> presentables) + internal ViewControllerCollection(LinkedList> presentables) { _presentables = presentables; } @@ -52,7 +52,7 @@ internal ViewControllerCollection(LinkedList> presentables) /// Gets top element of the stack. /// /// Thrown if the collection is empty. - public T Peek() + public TController Peek() { if (_presentables.First is null) { @@ -65,7 +65,7 @@ public T Peek() /// /// Attempts to get top controller of the collection. /// - public bool TryPeek(out T controller) + public bool TryPeek(out TController controller) { controller = _presentables.Last?.Value.Controller; return controller != null; @@ -106,7 +106,7 @@ public bool Contains(Type controllerType) /// /// Enumerates all controllers in the collection starting with the top (last) one. /// - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { var node = _presentables.First; @@ -134,7 +134,7 @@ public IEnumerator GetEnumerator() /// /// Gets an active controller (or ). /// - public T ActiveController + public TController ActiveController { get { @@ -217,7 +217,7 @@ public void DismissAllPopups() /// /// Gets top popup controller or . /// - protected IPresentResultOf GetPresentResult(T controller) + protected IPresentResultOf GetPresentResult(TController controller) { foreach (var p in _presentables) { @@ -450,7 +450,7 @@ private IPresentResult PresentInternal(IPresentable presentable, Type controller return result; } - private void PresentInternal(IPresentable presentable, IPresentable presentableParent, Transform transform) + private void PresentInternal(IPresentable presentable, IPresentable presentableParent, Transform transform) { var zIndex = 0; @@ -482,7 +482,7 @@ private void PresentInternal(IPresentable presentable, IPresentable presentab } } - private IPresentable CreatePresentable(IPresentable parent, Type controllerType, PresentOptions presentOptions, PresentArgs args) + private IPresentable CreatePresentable(IPresentable parent, Type controllerType, PresentOptions presentOptions, PresentArgs args) { Debug.Assert(controllerType != null); Debug.Assert(!_disposed); @@ -516,14 +516,14 @@ private IPresentable CreatePresentable(IPresentable parent, Type controllerTy // https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/how-to-examine-and-instantiate-generic-types-with-reflection var presentResultType = typeof(PresentResult<,>).MakeGenericType(controllerType, resultType); - var c = (IPresentable)Activator.CreateInstance(presentResultType, this, parent, controllerType, presentOptions, args); + var c = (IPresentable)Activator.CreateInstance(presentResultType, this, parent, controllerType, presentOptions, args); AddPresentable(c); return c; } - private void AddPresentable(IPresentable presentable) + private void AddPresentable(IPresentable presentable) { Debug.Assert(presentable != null); Debug.Assert(!_disposed); @@ -607,9 +607,9 @@ private static void ThrowIfInvalidControllerType(Type controllerType) throw new ArgumentException($"Cannot instantiate abstract type {controllerType.Name}.", nameof(controllerType)); } - if (!typeof(T).IsAssignableFrom(controllerType)) + if (!typeof(TController).IsAssignableFrom(controllerType)) { - throw new ArgumentException($"A view controller is expected to implement {typeof(T).Name}.", nameof(controllerType)); + throw new ArgumentException($"A view controller is expected to implement {typeof(TController).Name}.", nameof(controllerType)); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Presenters/Presenter{T}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/UnityFx.Mvc.asmdef b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/UnityFx.Mvc.asmdef new file mode 100644 index 0000000..842ed23 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/UnityFx.Mvc.asmdef @@ -0,0 +1,14 @@ +{ + "name": "UnityFx.Mvc", + "references": [ + "UnityFx.Mvc.Abstractions" + ], + "optionalUnityReferences": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/UnityFx.Mvc.asmdef.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/UnityFx.Mvc.asmdef.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/UnityFx.Mvc.asmdef.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/UnityFx.Mvc.asmdef.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewCollection.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewProxy.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewProxy.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewProxy.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.ViewProxy.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Views/ViewFactory.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common.meta similarity index 77% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common.meta index 79b0dba..67718ae 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts.meta +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b66d996d796b11a4bbdbbb4657a7a51d +guid: cfd0cb4f615b54141869bc960c66ff69 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common/AssemblyInfo.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common/AssemblyInfo.cs new file mode 100644 index 0000000..4dcbdb2 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common/AssemblyInfo.cs @@ -0,0 +1,39 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UnityFx.Mvc.Extensions")] +[assembly: AssemblyDescription("MVC framework for Unity.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnityFx.Mvc")] +[assembly: AssemblyCopyright("Copyright © 2018-2020 Alexander Bogarsukov")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7263C628-4EFC-4841-AF29-E20A46EADABD")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + +// Editor assembly should access core internals. +[assembly: InternalsVisibleTo("UnityFx.Mvc.Editor")] diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/MenuExtensions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common/AssemblyInfo.cs.meta similarity index 83% rename from Assets/Plugins/UnityFx.Mvc/Editor/Scripts/MenuExtensions.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common/AssemblyInfo.cs.meta index e883bdb..b9d4e3f 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Scripts/MenuExtensions.cs.meta +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/Common/AssemblyInfo.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: efdb15e2cfe9a0e459e19a02be2a440d +guid: e0437b05dc8b8354ab7c0bac04a3cd79 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxArgs.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxArgs.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxArgs.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxArgs.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxArgs.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxController.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxExtensions.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxExtensions.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxExtensions.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxExtensions.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxExtensions.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxOptions.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxOptions.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxOptions.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxOptions.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxOptions.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxResult.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxResult.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxResult.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxResult.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxResult.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxView.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxView.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxView.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Extensions/MessageBox/MessageBoxView.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxView.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/UnityFx.Mvc.Extensions.asmdef b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/UnityFx.Mvc.Extensions.asmdef new file mode 100644 index 0000000..cabab03 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/UnityFx.Mvc.Extensions.asmdef @@ -0,0 +1,14 @@ +{ + "name": "UnityFx.Mvc.Extensions", + "references": [ + "UnityFx.Mvc.Abstractions" + ], + "optionalUnityReferences": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/UnityFx.Mvc.Extensions.asmdef.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/UnityFx.Mvc.Extensions.asmdef.meta new file mode 100644 index 0000000..26de2de --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/UnityFx.Mvc.Extensions.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: ce709374c15c52145a084653aacd8279 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs deleted file mode 100644 index 2d7e9b9..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts/Implementation/Common/ActivatorUtilities.cs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. -// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; -using System.Diagnostics; -using System.Globalization; -using System.Reflection; -using System.Runtime.ExceptionServices; - -namespace UnityFx.Mvc -{ - /// - /// Defines -related helpers. - /// - internal static class ActivatorUtilities - { - #region interface - - /// - /// Creates an object of a specific type matching constructor arguments with values of and specified. - /// - /// A service provider used to match constructor arguments. - /// A type to instantiate. - /// An optional list of the constructor argument values. - /// Thrown if or is . - /// Thrown if the cannot be instantiated. - /// A instance created. - public static object CreateInstance(IServiceProvider serviceProvider, Type type, params object[] args) - { - if (serviceProvider == null) - { - throw new ArgumentNullException(nameof(serviceProvider)); - } - - if (type == null) - { - throw new ArgumentNullException(nameof(type)); - } - - try - { - var constructors = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public); - - if (constructors.Length > 0) - { - // Select the first public non-static ctor with matching arguments. - foreach (var ctor in constructors) - { - if (TryGetMethodArguments(ctor, serviceProvider, args, out var argValues)) - { - return ctor.Invoke(argValues); - } - } - - throw new InvalidOperationException($"A suitable constructor for type '{type}' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor."); - } - else - { - return Activator.CreateInstance(type); - } - } - catch (TargetInvocationException e) - { -#if !NET35 - ExceptionDispatchInfo.Capture(e.InnerException).Throw(); -#endif - throw e.InnerException; - } - } - - #endregion - - #region implementation - - private static bool TryGetMethodArguments(MethodBase method, IServiceProvider serviceProvider, object[] args, out object[] argValues) - { - var argInfo = method.GetParameters(); - var argumentsValidated = true; - - argValues = new object[argInfo.Length]; - - for (var i = 0; i < argInfo.Length; ++i) - { - var argType = argInfo[i].ParameterType; - var argValue = default(object); - - // Try to match the argument using args first. - for (var j = 0; j < args.Length; ++j) - { - var arg = args[j]; - - if (arg != null && argType.IsAssignableFrom(arg.GetType())) - { - argValue = arg; - break; - } - } - - // If argument matching failed try to resolve the argument using serviceProvider. - if (argValue == null) - { - argValue = serviceProvider.GetService(argType); - } - - // If the argument is matched/resolved, store the value, otherwise fail the constructor validation. - if (argValue != null) - { - argValues[i] = argValue; - } - else - { - argumentsValidated = false; - break; - } - } - - // If all arguments matched/resolved, use this constructor for activation. - if (argumentsValidated) - { - return true; - } - - return false; - } - - #endregion - } -} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/UnityFx.Mvc.asmdef b/Assets/Plugins/UnityFx.Mvc/Runtime/UnityFx.Mvc.asmdef deleted file mode 100644 index a47822c..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/UnityFx.Mvc.asmdef +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "UnityFx.Mvc" -} diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/AbstractController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/AbstractController.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/AbstractController.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/AbstractController.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/AbstractController.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/AbstractController.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/AbstractController.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/AbstractController.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/InvalidController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/InvalidController.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/InvalidController.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/InvalidController.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/InvalidController.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/InvalidController.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/InvalidController.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/InvalidController.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/MinimalController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/MinimalController.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/MinimalController.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/MinimalController.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/MinimalController.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/MinimalController.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/MinimalController.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/MinimalController.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/TimerController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/TimerController.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/TimerController.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/TimerController.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/TimerController.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/TimerController.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Controllers/TimerController.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/TimerController.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultServiceProvider.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultServiceProvider.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultServiceProvider.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultServiceProvider.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultServiceProvider.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultServiceProvider.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultServiceProvider.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultServiceProvider.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultView.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultView.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultView.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultView.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultView.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultView.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultView.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultView.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultViewFactory.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultViewFactory.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultViewFactory.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultViewFactory.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultViewFactory.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/Helpers/DefaultViewFactory.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultViewFactory.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests.meta similarity index 77% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Scripts.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests.meta index 0b85206..9054e36 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Scripts.meta +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f701ab24a8e696e4f956087496491d01 +guid: ef594abf87a823949bc4f366b2b72ec3 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/PresenterTests.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/PresenterTests.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/PresenterTests.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/PresenterTests.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/PresenterTests.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/ViewFactoryTests.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/ViewFactoryTests.cs rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/ViewFactoryTests.cs.meta b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Tests/Editor/Scripts/ViewFactoryTests.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/UnityFx.Mvc.Editor.Tests.asmdef b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/UnityFx.Mvc.Editor.Tests.asmdef index 29c3a96..7991cbc 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/UnityFx.Mvc.Editor.Tests.asmdef +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/UnityFx.Mvc.Editor.Tests.asmdef @@ -1,6 +1,7 @@ { "name": "UnityFx.Mvc.Editor.Tests", "references": [ + "UnityFx.Mvc.Abstractions", "UnityFx.Mvc" ], "optionalUnityReferences": [ From 9a1e23f8fd333796f931bab1e8e53a7028cc1252 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 19:52:22 +0200 Subject: [PATCH 13/34] CHANGELOG update --- Assets/Plugins/UnityFx.Mvc/CHANGELOG.md | 2 +- CHANGELOG.md | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/CHANGELOG.md b/Assets/Plugins/UnityFx.Mvc/CHANGELOG.md index efcc5f7..356dbf5 100644 --- a/Assets/Plugins/UnityFx.Mvc/CHANGELOG.md +++ b/Assets/Plugins/UnityFx.Mvc/CHANGELOG.md @@ -1,4 +1,4 @@ -# UnityFx.AppStates changelog +# UnityFx.Mvc changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/). diff --git a/CHANGELOG.md b/CHANGELOG.md index efcc5f7..97c96d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,25 @@ -# UnityFx.AppStates changelog +# UnityFx.Mvc changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.0] - unreleased + +### Added +- Added view layers support (via `ViewControllerAttribute`). +- Added `IViewControllerResult` interface to tag controllers that have a result value. +- Added `IConfigurable` interfaces. +- Added message box extensions. + +### Changed +- Changed the package layout. The code is now splitted into 3 assemblies (`UnityFx.Mvc`, `UnityFx.Mvc.Abstractions` and `UnityFx.Mvc.Extensions`). +- Renamed `IPresenter.PresentAsync` to `Present`. Added a group of `PresentAsync` extension methods returning `Task` instead of `IPresentResult`. +- Renamed `IPresentResult.DismissTask` to `Task`. +- Changed `Present`/`PresentAsync` arguments. + +### Removed +- Removed `IPresentResult.PresentTask`. + ## [0.1.0] - 2019.11.14 ### Added From 913f3232f371c6942e4cc90d16ea400962eac5fb Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 20:02:37 +0200 Subject: [PATCH 14/34] Added github workflow file --- .github/workflows/npmpublish.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/npmpublish.yml diff --git a/.github/workflows/npmpublish.yml b/.github/workflows/npmpublish.yml new file mode 100644 index 0000000..9e594dc --- /dev/null +++ b/.github/workflows/npmpublish.yml @@ -0,0 +1,31 @@ +name: Node.js Package + +on: + push: + branches: + - master + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + - run: npm publish Packages/UnityFx.Mvc + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + + publish-gpr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://npm.pkg.github.com/ + - run: npm publish Packages/UnityFx.Mvc + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} From 74e5e10ee9df44d365675cc4a1c172e4e283e088 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 20:05:51 +0200 Subject: [PATCH 15/34] README update --- Assets/Plugins/UnityFx.Mvc/README.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/README.md b/Assets/Plugins/UnityFx.Mvc/README.md index 7583dbc..3e71035 100644 --- a/Assets/Plugins/UnityFx.Mvc/README.md +++ b/Assets/Plugins/UnityFx.Mvc/README.md @@ -1,4 +1,4 @@ -# UnityFx.Outline +# UnityFx.Mvc ## SUMMARY MVC(S) framework for Unity. diff --git a/README.md b/README.md index bc8d4ff..87106f3 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Npm package is available at [npmjs.com](https://www.npmjs.com/package/com.unityf } ], "dependencies": { - "com.unityfx.mvc": "0.1.0" + "com.unityfx.mvc": "0.2.0" } } ``` From 5171c7eed202879a56ba893bab6d04f67e40e72b Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 29 Dec 2019 23:52:05 +0200 Subject: [PATCH 16/34] Project structure changes/renames --- .../UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs | 6 +++--- .../UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs | 6 +++--- .../Abstractions/{Commands => Common}/IConfigurable{T}.cs | 0 .../{Commands => Common}/IConfigurable{T}.cs.meta | 0 .../Abstractions/{Common => Presenters}/PresentArgs.cs | 0 .../Abstractions/{Common => Presenters}/PresentArgs.cs.meta | 0 .../Abstractions/{Common => Presenters}/PresentArgs{T}.cs | 0 .../{Common => Presenters}/PresentArgs{T}.cs.meta | 0 .../Abstractions/{Common => Presenters}/PresentOptions.cs | 0 .../{Common => Presenters}/PresentOptions.cs.meta | 0 ....ViewCollection.cs => UGUIViewFactory.ViewCollection.cs} | 6 +++--- ...ction.cs.meta => UGUIViewFactory.ViewCollection.cs.meta} | 0 ...iewFactory.ViewProxy.cs => UGUIViewFactory.ViewProxy.cs} | 2 +- ....ViewProxy.cs.meta => UGUIViewFactory.ViewProxy.cs.meta} | 0 .../Core/Views/{ViewFactory.cs => UGUIViewFactory.cs} | 4 ++-- .../Views/{ViewFactory.cs.meta => UGUIViewFactory.cs.meta} | 0 .../UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs | 6 +++--- Assets/Scripts/AppRoot.cs | 4 ++-- 18 files changed, 17 insertions(+), 17 deletions(-) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Commands => Common}/IConfigurable{T}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Commands => Common}/IConfigurable{T}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Common => Presenters}/PresentArgs.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Common => Presenters}/PresentArgs.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Common => Presenters}/PresentArgs{T}.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Common => Presenters}/PresentArgs{T}.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Common => Presenters}/PresentOptions.cs (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Common => Presenters}/PresentOptions.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/{ViewFactory.ViewCollection.cs => UGUIViewFactory.ViewCollection.cs} (95%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/{ViewFactory.ViewCollection.cs.meta => UGUIViewFactory.ViewCollection.cs.meta} (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/{ViewFactory.ViewProxy.cs => UGUIViewFactory.ViewProxy.cs} (98%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/{ViewFactory.ViewProxy.cs.meta => UGUIViewFactory.ViewProxy.cs.meta} (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/{ViewFactory.cs => UGUIViewFactory.cs} (98%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/{ViewFactory.cs.meta => UGUIViewFactory.cs.meta} (100%) diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs index 4e5a144..327adb6 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewFactoryEditor.cs @@ -7,14 +7,14 @@ namespace UnityFx.Mvc { - [CustomEditor(typeof(ViewFactory))] + [CustomEditor(typeof(UGUIViewFactory))] public class ViewFactoryEditor : Editor { - private ViewFactory _viewFactory; + private UGUIViewFactory _viewFactory; private void OnEnable() { - _viewFactory = (ViewFactory)target; + _viewFactory = (UGUIViewFactory)target; } public override void OnInspectorGUI() diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs index 5437a6e..c146917 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs @@ -7,14 +7,14 @@ namespace UnityFx.Mvc { - [CustomEditor(typeof(ViewFactory.ViewProxy), true)] + [CustomEditor(typeof(UGUIViewFactory.ViewProxy), true)] public class ViewProxyEditor : Editor { - private ViewFactory.ViewProxy _viewProxy; + private UGUIViewFactory.ViewProxy _viewProxy; private void OnEnable() { - _viewProxy = (ViewFactory.ViewProxy)target; + _viewProxy = (UGUIViewFactory.ViewProxy)target; } public override void OnInspectorGUI() diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/IConfigurable{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/IConfigurable{T}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/IConfigurable{T}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/IConfigurable{T}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/IConfigurable{T}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/IConfigurable{T}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/IConfigurable{T}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/IConfigurable{T}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentArgs.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentArgs.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentArgs.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentArgs.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs{T}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentArgs{T}.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs{T}.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentArgs{T}.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs{T}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentArgs{T}.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentArgs{T}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentArgs{T}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentOptions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentOptions.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentOptions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Common/PresentOptions.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs similarity index 95% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs index 62616c1..20b8afb 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs @@ -10,7 +10,7 @@ namespace UnityFx.Mvc { - partial class ViewFactory + partial class UGUIViewFactory { #region interface @@ -18,13 +18,13 @@ public class ViewCollection : ICollection, IReadOnlyCollection { #region data - private readonly ViewFactory _factory; + private readonly UGUIViewFactory _factory; #endregion #region interface - internal ViewCollection(ViewFactory factory) + internal ViewCollection(UGUIViewFactory factory) { _factory = factory; } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewCollection.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs similarity index 98% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs index 4bfed85..6c30673 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs @@ -9,7 +9,7 @@ namespace UnityFx.Mvc { - partial class ViewFactory + partial class UGUIViewFactory { #region implementation diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.ViewProxy.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs similarity index 98% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs index 356d4d5..56cc160 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -13,7 +13,7 @@ namespace UnityFx.Mvc /// /// Default -based view factory. /// - public partial class ViewFactory : MonoBehaviour, IViewFactory, IContainer + public partial class UGUIViewFactory : MonoBehaviour, IViewFactory, IContainer { #region data diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/ViewFactory.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs index 73e87e0..c81f824 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Tests/ViewFactoryTests.cs @@ -11,17 +11,17 @@ namespace UnityFx.Mvc { - [Category("ViewFactory"), TestOf(typeof(ViewFactory))] + [Category("ViewFactory"), TestOf(typeof(UGUIViewFactory))] public class ViewFactoryTests : IDisposable { private GameObject _go; - private ViewFactory _viewFactory; + private UGUIViewFactory _viewFactory; [SetUp] public void Init() { _go = new GameObject("ViewFactoryTest"); - _viewFactory = _go.AddComponent(); + _viewFactory = _go.AddComponent(); } [TearDown] diff --git a/Assets/Scripts/AppRoot.cs b/Assets/Scripts/AppRoot.cs index d5b6069..0c2ff39 100644 --- a/Assets/Scripts/AppRoot.cs +++ b/Assets/Scripts/AppRoot.cs @@ -10,7 +10,7 @@ public class AppRoot : MonoBehaviour, IServiceProvider [SerializeField] private Presenter _presenter; [SerializeField] - private ViewFactory _viewFactory; + private UGUIViewFactory _viewFactory; private void Awake() { @@ -21,7 +21,7 @@ private void Awake() if (_viewFactory is null) { - _viewFactory = gameObject.AddComponent(); + _viewFactory = gameObject.AddComponent(); } _presenter.Initialize(this); From f4b15088beaf1d7b110ba845e4446d8a91e6fb8a Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Mon, 30 Dec 2019 18:11:56 +0200 Subject: [PATCH 17/34] Added generic command support --- .../Windows/CreateViewControllerWindow.cs | 19 +- .../Abstractions/Commands/CommandEventArgs.cs | 26 --- .../Commands/CommandEventArgs.cs.meta | 2 +- .../CommandEventArgs{TCommand,TArgs}.cs | 39 ++++ .../CommandEventArgs{TCommand,TArgs}.cs.meta | 11 ++ .../Commands/CommandEventArgs{TCommand}.cs | 37 ++++ .../CommandEventArgs{TCommand}.cs.meta | 11 ++ .../Commands/CommandWrapper{TCommand}.cs | 78 ++++++++ .../Commands/CommandWrapper{TCommand}.cs.meta | 11 ++ .../Abstractions/Commands/ICommandTarget.cs | 6 +- .../Commands/ICommandTargetExtensions.cs | 25 +++ .../Commands/ICommandTargetExtensions.cs.meta | 11 ++ .../Runtime/Abstractions/Mvc/View.cs | 57 +++++- .../Abstractions/Mvc/ViewController.cs | 184 ++---------------- .../PresentResult{TController,TResult}.cs | 18 +- .../Core/Presenters/Presenter{TController}.cs | 17 +- .../MessageBox/MessageBoxController.cs | 50 +++-- .../Extensions/MessageBox/MessageBoxView.cs | 8 +- .../Editor/Controllers/AbstractController.cs | 2 +- .../Editor/Controllers/MinimalController.cs | 2 +- .../Editor/Controllers/TimerController.cs | 2 +- .../Tests/Editor/Helpers/DefaultView.cs | 2 +- Assets/Scripts/App/AppController.cs | 14 +- Assets/Scripts/Lobby/LobbyController.cs | 14 +- 24 files changed, 365 insertions(+), 281 deletions(-) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTargetExtensions.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTargetExtensions.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs index d857e47..b4ed2be 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. +// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. // See the LICENSE.md file in the project root for more information. using System; @@ -124,10 +124,11 @@ private void CreateViewController(string path) controllerText.AppendLine(indent + " #region interface"); controllerText.AppendLine(""); controllerText.AppendLine(indent + " /// "); - controllerText.AppendLine(indent + " /// Controller-specific commands."); + controllerText.AppendLine(indent + " /// Enumerates controller-specific commands."); controllerText.AppendLine(indent + " /// "); - controllerText.AppendFormat(indent + " public abstract new class Commands : {0}.{1}" + Environment.NewLine, nameof(ViewController), nameof(ViewController.Commands)); + controllerText.AppendLine(indent + " public enum Commands"); controllerText.AppendLine(indent + " {"); + controllerText.AppendLine(indent + " Close"); controllerText.AppendLine(indent + " }"); controllerText.AppendLine(""); controllerText.AppendLine(indent + " /// "); @@ -145,9 +146,19 @@ private void CreateViewController(string path) controllerText.AppendLine(indent + " #region ViewController"); controllerText.AppendLine(""); controllerText.AppendLine(indent + " /// "); - controllerText.AppendLine(indent + " protected override bool OnCommand(string commandName, object commandArgs)"); + controllerText.AppendLine(indent + " protected override bool OnCommand(TCommand command)"); controllerText.AppendLine(indent + " {"); controllerText.AppendLine(indent + " // TODO: Process view commands here. See list of commands in Commands."); + controllerText.AppendLine(indent + " if (CommandWrapper.TryUnpack(command, out var cmd))"); + controllerText.AppendLine(indent + " {"); + controllerText.AppendLine(indent + " switch (cmd.Command)"); + controllerText.AppendLine(indent + " {"); + controllerText.AppendLine(indent + " case Commands.Close:"); + controllerText.AppendLine(indent + " Dismiss();"); + controllerText.AppendLine(indent + " return true;"); + controllerText.AppendLine(indent + " }"); + controllerText.AppendLine(indent + " }"); + controllerText.AppendLine(""); controllerText.AppendLine(indent + " return false;"); controllerText.AppendLine(indent + " }"); controllerText.AppendLine(""); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs index c4269d9..e430082 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs @@ -10,31 +10,5 @@ namespace UnityFx.Mvc /// public class CommandEventArgs : EventArgs { - /// - /// Gets the command name. - /// - public string CommandName { get; } - - /// - /// Gets the command arguments. - /// - public object CommandArguments { get; } - - /// - /// Initializes a new instance of the class. - /// - public CommandEventArgs(string commandName) - { - CommandName = commandName; - } - - /// - /// Initializes a new instance of the class. - /// - public CommandEventArgs(string commandName, object args) - { - CommandName = commandName; - CommandArguments = args; - } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs.meta index fd8bfe0..3a3637b 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs.meta +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0d2ea5f0b4d1d1f4cb00f2d779a57bf8 +guid: c354fefe296ecac4a9e69d6c5ae654b0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs new file mode 100644 index 0000000..1010aad --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs @@ -0,0 +1,39 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// Event arguments for an arbitraty action. + /// + /// Type of the command arguments. + public class CommandEventArgs : CommandEventArgs + { + /// + /// Gets the command arguments. + /// + public TArgs Args { get; } + + /// + /// Initializes a new instance of the class. + /// + public CommandEventArgs(TCommand command, TArgs args) + : base(command) + { + Args = args; + } + + /// + public override string ToString() + { + if (Args != null) + { + return base.ToString() + '(' + Args.ToString() + ')'; + } + + return base.ToString(); + } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs.meta new file mode 100644 index 0000000..d4ebc32 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cab31b235c3716949bff8fecdaeb1a8c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs new file mode 100644 index 0000000..3bbe142 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs @@ -0,0 +1,37 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// Event arguments for an arbitraty action. + /// + public class CommandEventArgs : CommandEventArgs + { + /// + /// Gets the command name. + /// + public TCommand Command { get; } + + /// + /// Initializes a new instance of the class. + /// + public CommandEventArgs(TCommand command) + { + Command = command; + } + + /// + public override string ToString() + { + if (Command != null) + { + return Command.ToString(); + } + + return "Null"; + } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs.meta new file mode 100644 index 0000000..fd8bfe0 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0d2ea5f0b4d1d1f4cb00f2d779a57bf8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs new file mode 100644 index 0000000..5aba72a --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs @@ -0,0 +1,78 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// Wrapper of a generic command. + /// + /// Type of the command. + public readonly struct CommandWrapper + { + private readonly TCommand _command; + private readonly CommandEventArgs _args; + + /// + /// Gets the command. + /// + public TCommand Command => _command; + + /// + /// Initializes a new instance of the struct. + /// + private CommandWrapper(TCommand command, CommandEventArgs args) + { + _command = command; + _args = args; + } + + /// + /// Returns command arguments of the specified type (if any). + /// + /// Type of the argyments. + public T GetArgs() + { + if (_args is CommandEventArgs ea) + { + return ea.Args; + } + + return default; + } + + /// + /// Attepts to create an instance of . + /// + /// Type of the packed command. + /// Packed command. + /// The operation result. + /// Returns if matches the ; otherwise. + public static bool TryUnpack(TPackedCommand command, out CommandWrapper commandWrapper) + { + if (command is CommandEventArgs ea) + { + commandWrapper = new CommandWrapper(ea.Command, ea); + return true; + } + + if (command is TCommand c) + { + commandWrapper = new CommandWrapper(c, null); + return true; + } + + commandWrapper = default; + return false; + } + + /// + /// Implicit conversion to . + /// + public static implicit operator TCommand(CommandWrapper wrapper) + { + return wrapper._command; + } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs.meta new file mode 100644 index 0000000..003dd6b --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7c77b4728eb6ae645975d050a1fe7649 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTarget.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTarget.cs index 028050d..880a5d8 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTarget.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTarget.cs @@ -14,10 +14,8 @@ public interface ICommandTarget /// /// Invokes a command. An implementation might choose to ignore the command, in this case the method should return . /// - /// Name of the command to invoke. - /// Command-specific arguments. - /// Thrown if is . + /// Command to invoke. /// Returns if the command has been handled; otherwise. - bool InvokeCommand(string commandName, object args); + bool InvokeCommand(TCommand command); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTargetExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTargetExtensions.cs new file mode 100644 index 0000000..08be29f --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTargetExtensions.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// Extensions of . + /// + /// + public static class ICommandTargetExtensions + { + /// + /// Invokes a command. An implementation might choose to ignore the command, in this case the method should return . + /// + /// Command to invoke. + /// Command arguments. + /// Returns if the command has been handled; otherwise. + public static bool InvokeCommand(this ICommandTarget commandTarget, TCommand command, TArgs args) + { + return commandTarget.InvokeCommand(new CommandEventArgs(command, args)); + } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTargetExtensions.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTargetExtensions.cs.meta new file mode 100644 index 0000000..048d5df --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandTargetExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 931a556c85f509047bf9e2f6ac0740fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs index 74490b1..cec2940 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs @@ -9,7 +9,7 @@ namespace UnityFx.Mvc { /// - /// Default -based view. + /// A -based view. /// /// public class View : MonoBehaviour, IView @@ -38,12 +38,27 @@ public class View : MonoBehaviour, IView /// /// Raises event. /// - /// Name of the command. + /// Type of the command. + /// A generic command. + /// + /// + protected void NotifyCommand(TCommand command) + { + Command?.Invoke(this, new CommandEventArgs(command)); + } + + /// + /// Raises event. + /// + /// Type of the command. + /// Type of the arguments. + /// A generic command. /// Command arguments. + /// /// - protected void NotifyCommand(string commandId, object args = null) + protected void NotifyCommand(TCommand command, TArgs args) { - Command?.Invoke(this, new CommandEventArgs(commandId, args)); + Command?.Invoke(this, new CommandEventArgs(command, args)); } /// @@ -69,6 +84,37 @@ protected virtual void OnDispose() { } + /// + /// Gets name of a view prefab assigned to the controllers of the specified type. + /// + /// Type of the controller. + /// Prefab name. + public static string GetPrefabName(Type controllerType) + { + if (controllerType is null) + { + throw new ArgumentNullException(nameof(controllerType)); + } + + var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false); + + if (attrs != null && attrs.Length > 0 && !string.IsNullOrEmpty(attrs[0].ViewPrefabName)) + { + return attrs[0].ViewPrefabName; + } + else + { + var viewName = controllerType.Name; + + if (viewName.EndsWith("Controller")) + { + viewName = viewName.Substring(0, viewName.Length - 10); + } + + return viewName; + } + } + #endregion #region MonoBehaviour @@ -110,7 +156,8 @@ public bool Enabled /// /// Raised when a user issues a command. /// - /// + /// + /// public event EventHandler Command; #endregion diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController.cs index 65dc1ea..d8975b5 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewController.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -22,158 +22,6 @@ public abstract class ViewController : IViewController, IViewControllerEvents #region interface - /// - /// Enumerates basic controller commands. - /// - public abstract class Commands - { - #region Common - - /// - /// Name of the OK command. - /// - public const string Ok = "Ok"; - - /// - /// Name of the CANCEL command. - /// - public const string Cancel = "Cancel"; - - /// - /// Name of the APPLY command. - /// - public const string Apply = "Apply"; - - /// - /// Name of the EXIT command. - /// - public const string Exit = "Exit"; - - /// - /// Name of the HELP command. - /// - public const string Help = "Help"; - - /// - /// Name of the ABOUT command. - /// - public const string About = "About"; - - #endregion - - #region Navigation - - /// - /// Name of the BACK command. - /// - public const string Back = "Back"; - - /// - /// Name of the NEXT command. - /// - public const string Next = "Next"; - - /// - /// Name of the PREV command. - /// - public const string Prev = "Prev"; - - /// - /// Name of the HOME command. - /// - public const string Home = "Home"; - - /// - /// Name of the END command. - /// - public const string End = "End"; - - #endregion - - #region File - - /// - /// Name of the NEW command. - /// - public const string New = "New"; - - /// - /// Name of the OPEN command. - /// - public const string Open = "Open"; - - /// - /// Name of the CLOSE command. - /// - public const string Close = "Close"; - - /// - /// Name of the SAVE command. - /// - public const string Save = "Save"; - - #endregion - - #region Editing - - /// - /// Name of the ADD command. - /// - public const string Add = "Add"; - - /// - /// Name of the REMOVE command. - /// - public const string Remove = "Remove"; - - /// - /// Name of the EDIT command. - /// - public const string Edit = "Edit"; - - /// - /// Name of the COPY command. - /// - public const string Copy = "Copy"; - - /// - /// Name of the CUT command. - /// - public const string Cut = "Cut"; - - /// - /// Name of the PASTE command. - /// - public const string Paste = "Paste"; - - /// - /// Name of the INSERT command. - /// - public const string Insert = "Insert"; - - /// - /// Name of the DELETE command. - /// - public const string Delete = "Delete"; - - /// - /// Name of the DUPLICATE command. - /// - public const string Duplicate = "Duplicate"; - - /// - /// Name of the UNDO command. - /// - public const string Undo = "Undo"; - - /// - /// Name of the REDO command. - /// - public const string Redo = "Redo"; - - #endregion - } - /// /// Gets the controller context. /// @@ -221,7 +69,7 @@ protected void ThrowIfDismissed() /// Called to process a command. /// /// Returns if the command has been handles; otherwise. - protected virtual bool OnCommand(string commandName, object commandArgs) + protected virtual bool OnCommand(TCommand command) { return false; } @@ -313,32 +161,32 @@ void IViewControllerEvents.OnUpdate(float frameTime) #region ICommandTarget /// - /// Invokes a command. + /// Invokes a command. An implementation might choose to ignore the command, in this case the method should return . /// - /// Name of the command to invoke. - /// Command-specific arguments. - /// Thrown if is . - /// Thrown if the controller is disposed. - /// Returns if the command has been handles; otherwise. - public bool InvokeCommand(string commandName, object args) + /// Command to invoke. + /// Returns if the command has been handled; otherwise. + public bool InvokeCommand(TCommand command) { - ThrowIfDismissed(); - - if (commandName is null) + if (command != null && !_context.IsDismissed) { - throw new ArgumentNullException(nameof(commandName)); + return OnCommand(command); } - return OnCommand(commandName, args); + return false; } #endregion #region implementation - private void OnCommand(object sender, CommandEventArgs e) + private void OnCommand(object sender, EventArgs e) { - OnCommand(e.CommandName, e.CommandArguments); + Debug.Assert(sender == _context.View); + + if (e != null && !_context.IsDismissed) + { + OnCommand(e); + } } #endregion diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs index 164714e..446028b 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -276,21 +276,9 @@ public IPresentResult Present(Type controllerType, PresentArgs args, PresentOpti #region ICommandTarget - public bool InvokeCommand(string commandName, object args) + public bool InvokeCommand(TCommand command) { - ThrowIfDisposed(); - - if (commandName is null) - { - throw new ArgumentNullException(nameof(commandName)); - } - - if (_state != State.Presented && _state != State.Active) - { - throw new InvalidOperationException(); - } - - return _controller.InvokeCommand(commandName, args); + return _controller.InvokeCommand(command); } #endregion diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs index af999c1..3579db9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -378,17 +378,13 @@ public IPresentResult Present(Type controllerType, PresentArgs args, PresentOpti #region ICommandTarget /// - /// Invokes a command on the controllers presented. + /// Invokes a command. An implementation might choose to ignore the command, in this case the method should return . /// - /// Name of the command to invoke. - /// Command-specific arguments. - /// Thrown if the controller is disposed. + /// Command to invoke. /// Returns if the command has been handled; otherwise. - public bool InvokeCommand(string commandName, object args) + public bool InvokeCommand(TCommand command) { - ThrowIfDisposed(); - - if (!string.IsNullOrEmpty(commandName)) + if (command != null && !_disposed) { var node = _presentables.Last; @@ -396,7 +392,7 @@ public bool InvokeCommand(string commandName, object args) { var p = node.Value; - if (p.InvokeCommand(commandName, args)) + if (p.InvokeCommand(command)) { return true; } @@ -408,7 +404,6 @@ public bool InvokeCommand(string commandName, object args) node = node.Previous; } - } return false; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs index 0dba86a..081bfbf 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -24,12 +24,23 @@ public class MessageBoxController : IViewController, IViewControllerResult + /// Enumerates controller-specific commands. + /// + public enum Commands + { + Ok, + Cancel, + Close + } + /// /// Initializes a new instance of the class. /// public MessageBoxController(IPresentContext context) { _context = context; + _context.View.Command += OnCommand; if (context.PresentArgs is MessageBoxArgs args && context.View is IConfigurable view) { @@ -49,24 +60,23 @@ public MessageBoxController(IPresentContext context) #region ICommandTarget /// - public bool InvokeCommand(string commandName, object args) + public bool InvokeCommand(TCommand command) { - if (_context.IsDismissed || commandName is null) - { - return false; - } - - if (string.CompareOrdinal(commandName, ViewController.Commands.Ok) == 0) + if (command != null && !_context.IsDismissed) { - _context.Dismiss(MessageBoxResult.Ok); - return true; - } - - if (string.CompareOrdinal(commandName, ViewController.Commands.Cancel) == 0 || - string.CompareOrdinal(commandName, ViewController.Commands.Close) == 0) - { - _context.Dismiss(MessageBoxResult.Cancel); - return true; + if (CommandWrapper.TryUnpack(command, out var cmd)) + { + if (cmd == Commands.Ok) + { + _context.Dismiss(MessageBoxResult.Ok); + } + else + { + _context.Dismiss(MessageBoxResult.Cancel); + } + + return true; + } } return false; @@ -75,6 +85,12 @@ public bool InvokeCommand(string commandName, object args) #endregion #region implementation + + private void OnCommand(object sender, CommandEventArgs e) + { + InvokeCommand(e); + } + #endregion } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxView.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxView.cs index cd7aa4f..0bff31b 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxView.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxView.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -118,17 +118,17 @@ public void Configure(MessageBoxArgs args) private void OnOk() { - NotifyCommand(ViewController.Commands.Ok); + NotifyCommand(MessageBoxController.Commands.Ok); } private void OnCancel() { - NotifyCommand(ViewController.Commands.Cancel); + NotifyCommand(MessageBoxController.Commands.Cancel); } private void OnClose() { - NotifyCommand(ViewController.Commands.Close); + NotifyCommand(MessageBoxController.Commands.Close); } #endregion diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/AbstractController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/AbstractController.cs index 7ed4f04..e2e3bd4 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/AbstractController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/AbstractController.cs @@ -9,7 +9,7 @@ public abstract class AbstractController : IViewController { public IView View => null; - public bool InvokeCommand(string commandName, object args) + public bool InvokeCommand(TCommand command) { return false; } diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/MinimalController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/MinimalController.cs index be78d57..5e2fd8e 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/MinimalController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/MinimalController.cs @@ -14,7 +14,7 @@ public MinimalController(IView view) View = view; } - public bool InvokeCommand(string commandName, object args) + public bool InvokeCommand(TCommand command) { return false; } diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/TimerController.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/TimerController.cs index 5e49fc9..c97d02a 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/TimerController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Controllers/TimerController.cs @@ -17,7 +17,7 @@ public TimerController(IPresentContext context) _context.Schedule(OnTimer, 0.1f); } - public bool InvokeCommand(string commandName, object args) + public bool InvokeCommand(TCommand command) { return false; } diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultView.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultView.cs index 1a367fb..f5bec8c 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultView.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultView.cs @@ -21,7 +21,7 @@ public class DefaultView : IView public void OnCommand() { - Command?.Invoke(this, new CommandEventArgs("Dummy")); + Command?.Invoke(this, new CommandEventArgs()); } public void Dispose() diff --git a/Assets/Scripts/App/AppController.cs b/Assets/Scripts/App/AppController.cs index f304549..4798ce5 100644 --- a/Assets/Scripts/App/AppController.cs +++ b/Assets/Scripts/App/AppController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; using UnityFx.Mvc; @@ -15,13 +15,6 @@ public class AppController : ViewController #region interface - /// - /// Controller-specific commands. - /// - public abstract new class Commands : ViewController.Commands - { - } - /// /// Initializes a new instance of the class. /// @@ -37,10 +30,9 @@ public AppController(IPresentContext context) #region ViewController /// - protected override bool OnCommand(string commandName, object commandArgs) + protected override bool OnCommand(TCommand command) { - // TODO: Process view commands here. See list of commands in Commands. - return false; + return base.OnCommand(command); } #endregion diff --git a/Assets/Scripts/Lobby/LobbyController.cs b/Assets/Scripts/Lobby/LobbyController.cs index f1d90c6..505c8af 100644 --- a/Assets/Scripts/Lobby/LobbyController.cs +++ b/Assets/Scripts/Lobby/LobbyController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; using UnityFx.Mvc; @@ -15,13 +15,6 @@ public class LobbyController : ViewController #region interface - /// - /// Controller-specific commands. - /// - public abstract new class Commands : ViewController.Commands - { - } - /// /// Initializes a new instance of the class. /// @@ -37,10 +30,9 @@ public LobbyController(IPresentContext context) #region ViewController /// - protected override bool OnCommand(string commandName, object commandArgs) + protected override bool OnCommand(TCommand command) { - // TODO: Process view commands here. See list of commands in Commands. - return false; + return base.OnCommand(command); } #endregion From 5b90157fd3fcd62bafe01c919da5c7220290c422 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Mon, 30 Dec 2019 18:12:57 +0200 Subject: [PATCH 18/34] CHANGELOG update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97c96d3..6ff5d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/); this proj ## [0.2.0] - unreleased ### Added +- Added support for generic commands. - Added view layers support (via `ViewControllerAttribute`). - Added `IViewControllerResult` interface to tag controllers that have a result value. - Added `IConfigurable` interfaces. From 9afe6cbee2904f9b59c832a4c0b6d661d17d323d Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Wed, 1 Jan 2020 16:00:39 +0200 Subject: [PATCH 19/34] Added ICommandAccess interface --- .../Windows/CreateViewControllerWindow.cs | 4 +- .../CommandEventArgs{TCommand,TArgs}.cs | 2 +- .../Commands/CommandEventArgs{TCommand}.cs | 2 +- .../Abstractions/Commands/CommandUtilities.cs | 49 ++++++++++++ ...mand}.cs.meta => CommandUtilities.cs.meta} | 2 +- .../Commands/CommandWrapper{TCommand}.cs | 78 ------------------- .../Commands/ICommandAccess{TCommand}.cs | 18 +++++ .../Commands/ICommandAccess{TCommand}.cs.meta | 11 +++ .../Commands/ICommandArgsAccess{TArgs}.cs | 18 +++++ .../ICommandArgsAccess{TArgs}.cs.meta | 11 +++ .../MessageBox/MessageBoxController.cs | 2 +- 11 files changed, 113 insertions(+), 84 deletions(-) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandUtilities.cs rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/{CommandWrapper{TCommand}.cs.meta => CommandUtilities.cs.meta} (83%) delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandAccess{TCommand}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandAccess{TCommand}.cs.meta create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandArgsAccess{TArgs}.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandArgsAccess{TArgs}.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs index b4ed2be..edbe24b 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs @@ -149,9 +149,9 @@ private void CreateViewController(string path) controllerText.AppendLine(indent + " protected override bool OnCommand(TCommand command)"); controllerText.AppendLine(indent + " {"); controllerText.AppendLine(indent + " // TODO: Process view commands here. See list of commands in Commands."); - controllerText.AppendLine(indent + " if (CommandWrapper.TryUnpack(command, out var cmd))"); + controllerText.AppendLine(indent + " if (CommandUtilities.TryUnpack(command, out Commands cmd))"); controllerText.AppendLine(indent + " {"); - controllerText.AppendLine(indent + " switch (cmd.Command)"); + controllerText.AppendLine(indent + " switch (cmd)"); controllerText.AppendLine(indent + " {"); controllerText.AppendLine(indent + " case Commands.Close:"); controllerText.AppendLine(indent + " Dismiss();"); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs index 1010aad..2cadae6 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand,TArgs}.cs @@ -9,7 +9,7 @@ namespace UnityFx.Mvc /// Event arguments for an arbitraty action. /// /// Type of the command arguments. - public class CommandEventArgs : CommandEventArgs + public class CommandEventArgs : CommandEventArgs, ICommandResultAccess { /// /// Gets the command arguments. diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs index 3bbe142..1bf8ee9 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandEventArgs{TCommand}.cs @@ -8,7 +8,7 @@ namespace UnityFx.Mvc /// /// Event arguments for an arbitraty action. /// - public class CommandEventArgs : CommandEventArgs + public class CommandEventArgs : CommandEventArgs, ICommandAccess { /// /// Gets the command name. diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandUtilities.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandUtilities.cs new file mode 100644 index 0000000..63670cc --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandUtilities.cs @@ -0,0 +1,49 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// Command-related helpers. + /// + public static class CommandUtilities + { + /// + /// Attepts to unpack a command. + /// + public static bool TryUnpack(TPackedCommand packedCommand, out TCommand command) + { + if (packedCommand is ICommandAccess ea) + { + command = ea.Command; + return true; + } + + if (packedCommand is TCommand c) + { + command = c; + return true; + } + + command = default; + return false; + } + + /// + /// Attempts to unpack command arguments. + /// + public static bool TryUnpackArgs(TPackedCommand packedCommand, out TArgs args) + { + if (packedCommand is ICommandResultAccess ea) + { + args = ea.Args; + return true; + } + + args = default; + return false; + } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandUtilities.cs.meta similarity index 83% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandUtilities.cs.meta index 003dd6b..e0c3c0d 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs.meta +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandUtilities.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7c77b4728eb6ae645975d050a1fe7649 +guid: 6b7439042044478488710a0f7a760393 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs deleted file mode 100644 index 5aba72a..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/CommandWrapper{TCommand}.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. -// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; - -namespace UnityFx.Mvc -{ - /// - /// Wrapper of a generic command. - /// - /// Type of the command. - public readonly struct CommandWrapper - { - private readonly TCommand _command; - private readonly CommandEventArgs _args; - - /// - /// Gets the command. - /// - public TCommand Command => _command; - - /// - /// Initializes a new instance of the struct. - /// - private CommandWrapper(TCommand command, CommandEventArgs args) - { - _command = command; - _args = args; - } - - /// - /// Returns command arguments of the specified type (if any). - /// - /// Type of the argyments. - public T GetArgs() - { - if (_args is CommandEventArgs ea) - { - return ea.Args; - } - - return default; - } - - /// - /// Attepts to create an instance of . - /// - /// Type of the packed command. - /// Packed command. - /// The operation result. - /// Returns if matches the ; otherwise. - public static bool TryUnpack(TPackedCommand command, out CommandWrapper commandWrapper) - { - if (command is CommandEventArgs ea) - { - commandWrapper = new CommandWrapper(ea.Command, ea); - return true; - } - - if (command is TCommand c) - { - commandWrapper = new CommandWrapper(c, null); - return true; - } - - commandWrapper = default; - return false; - } - - /// - /// Implicit conversion to . - /// - public static implicit operator TCommand(CommandWrapper wrapper) - { - return wrapper._command; - } - } -} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandAccess{TCommand}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandAccess{TCommand}.cs new file mode 100644 index 0000000..8c67c90 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandAccess{TCommand}.cs @@ -0,0 +1,18 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// Event arguments for an arbitraty action. + /// + public interface ICommandAccess + { + /// + /// Gets the command. + /// + TCommand Command { get; } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandAccess{TCommand}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandAccess{TCommand}.cs.meta new file mode 100644 index 0000000..825eb33 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandAccess{TCommand}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2985597119cbef64abaceac68ba20b67 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandArgsAccess{TArgs}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandArgsAccess{TArgs}.cs new file mode 100644 index 0000000..7bc1bc5 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandArgsAccess{TArgs}.cs @@ -0,0 +1,18 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; + +namespace UnityFx.Mvc +{ + /// + /// Event arguments for an arbitraty action. + /// + public interface ICommandResultAccess + { + /// + /// Gets the command arguments. + /// + TArgs Args { get; } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandArgsAccess{TArgs}.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandArgsAccess{TArgs}.cs.meta new file mode 100644 index 0000000..def2bf5 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Commands/ICommandArgsAccess{TArgs}.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: edd3d06d145315e4e8430d8df595a1ef +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs index 081bfbf..2acffc5 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Extensions/MessageBox/MessageBoxController.cs @@ -64,7 +64,7 @@ public bool InvokeCommand(TCommand command) { if (command != null && !_context.IsDismissed) { - if (CommandWrapper.TryUnpack(command, out var cmd)) + if (CommandUtilities.TryUnpack(command, out Commands cmd)) { if (cmd == Commands.Ok) { From 7c671b88e7a14ad54f27dea4df6e2e7137810376 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Wed, 1 Jan 2020 16:38:34 +0200 Subject: [PATCH 20/34] Editor script fixes --- .../Windows/CreateViewControllerWindow.cs | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs index edbe24b..0468c03 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Text; +using System.Text.RegularExpressions; using UnityEditor; using UnityEngine; @@ -11,6 +12,7 @@ namespace UnityFx.Mvc { public class CreateViewControllerWindow : EditorWindow { + private string _basePath; private string _controllerName; private string _namespace; private string _controllerBaseClass = nameof(ViewController); @@ -19,6 +21,8 @@ public class CreateViewControllerWindow : EditorWindow private bool _modal; private bool _popup; + private Regex _classNamePattern = new Regex("^[_a-zA-Z][_a-zA-Z0-9]*$"); + [MenuItem("Assets/Create/UnityFx/New ViewController...")] public static void Init() { @@ -27,13 +31,18 @@ public static void Init() private void OnGUI() { - var path = GetSelectedPath(); + _basePath = GetSelectedPath(); - if (!string.IsNullOrEmpty(path)) + if (string.IsNullOrEmpty(_basePath)) { - _controllerName = Path.GetFileName(path); + EditorGUILayout.HelpBox("Invalid path. Please select an asset folder.", MessageType.Error); + return; } + GUI.enabled = false; + EditorGUILayout.TextField("Base path", _basePath); + GUI.enabled = true; + _controllerName = EditorGUILayout.TextField("Controller Name", _controllerName); _exclusive = EditorGUILayout.Toggle("Exclusive", _exclusive); _popup = EditorGUILayout.Toggle("Popup", _popup); @@ -42,6 +51,11 @@ private void OnGUI() _controllerBaseClass = EditorGUILayout.TextField("Controller Base Class", _controllerBaseClass); _viewBaseClass = EditorGUILayout.TextField("View Base Class", _viewBaseClass); + if (string.IsNullOrWhiteSpace(_controllerName) || !_classNamePattern.IsMatch(_controllerName)) + { + EditorGUILayout.HelpBox($"Invalid controller name. Controller names should match {_classNamePattern}.", MessageType.Error); + } + if (_exclusive) { _popup = false; @@ -65,7 +79,7 @@ private void OnGUI() if (GUILayout.Button("Create")) { - CreateViewController(path); + CreateViewController(_basePath); } } @@ -81,6 +95,13 @@ private void CreateViewController(string path) } else { + path = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(path, _controllerName)); + + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + var indent = " "; var controllerName = _controllerName + "Controller"; var controllerFileName = controllerName + ".cs"; From 731eb20908bc9cbf5e068db1dc0919af4e624d32 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Wed, 1 Jan 2020 18:01:46 +0200 Subject: [PATCH 21/34] README update --- README.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 87106f3..9b48144 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Channel | UnityFx.Mvc | ---------|---------------| Github | [![GitHub release](https://img.shields.io/github/release/Arvtesh/UnityFx.Mvc.svg?logo=github)](https://github.com/Arvtesh/UnityFx.Mvc/releases) -Unity Asset Store | [![MVC framework for Unity](https://img.shields.io/badge/tools-v0.1.0-green.svg)](https://assetstore.unity.com/packages/tools/TODO) +Unity Asset Store | [![MVC framework for Unity](https://img.shields.io/badge/tools-v0.2.0-green.svg)](https://assetstore.unity.com/packages/tools/TODO) Npm | [![Npm release](https://img.shields.io/npm/v/com.unityfx.mvc.svg)](https://www.npmjs.com/package/com.unityfx.mvc) ![npm](https://img.shields.io/npm/dt/com.unityfx.mvc) ## Synopsis @@ -44,14 +44,35 @@ Npm package is available at [npmjs.com](https://www.npmjs.com/package/com.unityf } ``` +## Understanding the concepts +As outlined in [ASP.NET Core documentation](https://docs.microsoft.com/en-us/aspnet/core/mvc/overview), the Model-View-Controller (MVC) architectural pattern separates an application into three main groups of components: Models, Views, and Controllers. This pattern helps to achieve separation of concerns. Using this pattern, user requests are routed to a Controller which is responsible for working with the Model to perform user actions and/or retrieve results of queries. The Controller chooses the View to display to the user, and provides it with any Model data it requires. + +This delineation of responsibilities helps you scale the application in terms of complexity because it's easier to code, debug, and test something (model, view, or controller) that has a single job. It's more difficult to update, test, and debug code that has dependencies spread across two or more of these three areas. For example, user interface logic tends to change more frequently than business logic. If presentation code and business logic are combined in a single object, an object containing business logic must be modified every time the user interface is changed. This often introduces errors and requires the retesting of business logic after every minimal user interface change. + +Both the view and the controller depend on the model. However, the model depends on neither the view nor the controller. This is one of the key benefits of the separation. This separation allows the model to be built and tested independent of the visual presentation. + +In the same way that MVC takes the position that you should separate model logic from view and controller logic, MVCS takes this notion a step further by advocating for application logic to live in the services. This is the recommended way of sharing pieces of logic between controllers. + +### Model +The Model in an MVC application represents the state of the application and any business logic or operations that should be performed by it. Business logic should be encapsulated in the model, along with any implementation logic for persisting the state of the application. + +### View +Views are responsible for presenting content through the user interface. There should be minimal logic within views, and any logic in them should relate to presenting content. + +### Controller +Controllers are the components that handle user interaction, work with the model. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. + +### Service +Services usually contian very specialized logic, that is shared between several controllers. Services may on may not depend on Model. Neither model not views should not depend on services. Examples of services: `IFileSystem`, `IAssetFactory`, `IAudioService`. + ## Usage Install the package and import the namespace: ```csharp using UnityFx.Mvc; +using UnityFx.Mvc.Extensions; ``` -## Understanding the concepts -TODO + ## Motivation The project was initially created to help author with his [Unity3d](https://unity3d.com) projects. Client .NET applications in general (and Unity applications specifically) do not have a standard structure or any kind of architecturing guidelines (like ASP.NET). This is an attempt to create a small yet effective and usable application framework suitable for Unity projects. @@ -63,6 +84,9 @@ Please see the links below for extended information on the product: - [SUPPORT](.github/SUPPORT.md). ## Useful links +- [MVC in Wikipedia](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller). +- [MVC in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/mvc/overview). +- [Architectural pronciples](https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/architectural-principles). ## Software requirements - [Microsoft Visual Studio](https://www.visualstudio.com/vs/community/) From 8c1dd898794b231283c4b7769f4bac22b3751727 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Thu, 2 Jan 2020 00:19:22 +0200 Subject: [PATCH 22/34] Added RouteAttribute --- .../ViewControllerAttribute.cs | 2 +- .../ViewControllerAttribute.cs.meta | 0 .../{Attributes.meta => Routing.meta} | 2 +- .../Abstractions/Routing/RouteAttribute.cs | 28 +++++++++++++++++++ .../Routing/RouteAttribute.cs.meta | 11 ++++++++ README.md | 8 ++++-- 6 files changed, 47 insertions(+), 4 deletions(-) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Attributes => Mvc}/ViewControllerAttribute.cs (94%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Attributes => Mvc}/ViewControllerAttribute.cs.meta (100%) rename Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/{Attributes.meta => Routing.meta} (77%) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs similarity index 94% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs index fb65b07..ba8ada3 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs.meta similarity index 100% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes/ViewControllerAttribute.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing.meta similarity index 77% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing.meta index feb6a5c..0dcd7ec 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Attributes.meta +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9f059ac5b3a67154c89aed670d71a0a3 +guid: 86d97ba9a74d9394dbca53d756a9c617 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs new file mode 100644 index 0000000..48ea018 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs @@ -0,0 +1,28 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using UnityEngine; + +namespace UnityFx.Mvc +{ + /// + /// Marks a route for a controller. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] + public sealed class RouteAttribute : Attribute + { + /// + /// Gets the route template. May be . + /// + public string Template { get; } + + /// + /// Initializes a new instance of the class. + /// + public RouteAttribute(string template) + { + Template = template; + } + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs.meta new file mode 100644 index 0000000..c9a3ca2 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c28c3d5aeed8e742990ea8ae45b4bcd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index 9b48144..21943ae 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ using UnityFx.Mvc; using UnityFx.Mvc.Extensions; ``` - +#### Dependency injection ## Motivation The project was initially created to help author with his [Unity3d](https://unity3d.com) projects. Client .NET applications in general (and Unity applications specifically) do not have a standard structure or any kind of architecturing guidelines (like ASP.NET). This is an attempt to create a small yet effective and usable application framework suitable for Unity projects. @@ -86,7 +86,11 @@ Please see the links below for extended information on the product: ## Useful links - [MVC in Wikipedia](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller). - [MVC in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/mvc/overview). -- [Architectural pronciples](https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/architectural-principles). +- [Dependency injection in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection). +- [Routing in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing). +- [Architectural pronciples in ASP.NET Core](https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/architectural-principles). +- [Deeplinking in Wikipedia](https://en.wikipedia.org/wiki/Deep_linking). +- [Deeplinking basics](https://www.appsflyer.com/resources/everything-marketer-needs-to-know-deep-linking/deep-linking-basics/). ## Software requirements - [Microsoft Visual Studio](https://www.visualstudio.com/vs/community/) From ad9c418d8c1473aa41322cf2faa9923882e6e677 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Thu, 2 Jan 2020 17:25:13 +0200 Subject: [PATCH 23/34] AOT compilation fixes --- .../Presenters/IPresenterExtensions.cs | 2 +- .../Core/Presenters/Presenter{TController}.cs | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenterExtensions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenterExtensions.cs index 18940a5..79b6e53 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenterExtensions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresenterExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs index 3579db9..0964cf6 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs @@ -5,13 +5,17 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using UnityEngine; +using UnityEngine.Scripting; namespace UnityFx.Mvc { + using Debug = UnityEngine.Debug; + /// /// Default -based presenter implementation. /// @@ -243,6 +247,18 @@ protected void ThrowIfDisposed() } } +#if ENABLE_IL2CPP + + /// + /// Call this on AOT platforms to make sure all needed code exists in runtime. + /// + protected static void AotCodegenGuard() + { + new PresentResult(null, null, typeof(TController), PresentOptions.None, PresentArgs.Default); + } + +#endif + #endregion #region virtual interface @@ -310,7 +326,7 @@ private void OnDestroy() IViewFactory IPresenterInternal.ViewFactory => _viewFactory; IViewControllerFactory IPresenterInternal.ControllerFactory => _controllerFactory; - + IPresentResult IPresenterInternal.PresentAsync(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) { return PresentInternal(presentable, controllerType, presentOptions, parent, args); @@ -608,6 +624,19 @@ private static void ThrowIfInvalidControllerType(Type controllerType) } } +#if ENABLE_IL2CPP + + [Preserve] + private static void AotCodegenHelper() + { + // NOTE: This method is needed for AOT compiler to generate code for PresentResult<,> specializations. + // It should never be executed, it's just here to mark specific type arguments as used. + new PresentResult(null, null, typeof(TController), PresentOptions.None, PresentArgs.Default); + new PresentResult(null, null, typeof(TController), PresentOptions.None, PresentArgs.Default); + } + +#endif + #endregion } } From 7b58cb0040021bf6aaab19b02f7e5fb312e265ec Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Thu, 2 Jan 2020 18:04:50 +0200 Subject: [PATCH 24/34] tt --- .../Abstractions/Presenters/IPresentContext.cs | 7 ++++++- .../Runtime/Abstractions/Routing/IRouter.cs | 16 ++++++++++++++++ .../Runtime/Abstractions/Routing/IRouter.cs.meta | 11 +++++++++++ .../PresentResult{TController,TResult}.cs | 16 ++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs.meta diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext.cs index ec2f621..8828dca 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentContext.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -17,6 +17,11 @@ public interface IPresentContext : IPresenter, IServiceProvider /// int Id { get; } + /// + /// Gets the deepling identifier for this controller. + /// + string DeeplinkId { get; } + /// /// Gets the controller present arguments. /// diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs new file mode 100644 index 0000000..a740497 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs @@ -0,0 +1,16 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using System.Threading.Tasks; + +namespace UnityFx.Mvc.Routing +{ + /// + /// A generic router. + /// + public interface IRouter + { + Task RouteAsync(); + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs.meta new file mode 100644 index 0000000..58eed99 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 279610838f00401459eae39533d792d7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs index 446028b..da8df93 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs @@ -47,6 +47,7 @@ private struct TimerData private readonly PresentOptions _presentOptions; private readonly IPresentable _parent; private readonly int _id; + private readonly string _deeplinkId; private IServiceProvider _serviceProvider; private IDisposable _scope; @@ -79,6 +80,7 @@ public PresentResult(IPresenterInternal presenter, IPresentable parent, Type con _presentArgs = args; _presentOptions = presentOptions; _id = presenter.GetNextId(); + _deeplinkId = GetDeeplinkId(controllerType); } #endregion @@ -244,6 +246,8 @@ public void Dismiss() public int Id => _id; + public string DeeplinkId => _deeplinkId; + public PresentArgs PresentArgs => _presentArgs; public PresentOptions PresentOptions => _presentOptions; @@ -470,6 +474,18 @@ private void ThrowIfDisposed() } } + private static string GetDeeplinkId(Type controllerType) + { + var deeplinkId = controllerType.Name; + + if (deeplinkId.EndsWith("Controller")) + { + deeplinkId = deeplinkId.Substring(0, deeplinkId.Length - 10); + } + + return deeplinkId; + } + #endregion } } From aaa610dc6d720c2e53e49061ccc419d46574546b Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sat, 4 Jan 2020 19:48:04 +0200 Subject: [PATCH 25/34] Changed view creation logic --- .../Runtime/Abstractions/Mvc/IViewFactory.cs | 7 ++-- .../Runtime/Abstractions/Mvc/View.cs | 32 --------------- .../Mvc/ViewControllerAttribute.cs | 20 +++------ .../Runtime/Abstractions/Routing.meta | 8 ---- .../Runtime/Abstractions/Routing/IRouter.cs | 16 -------- .../Abstractions/Routing/IRouter.cs.meta | 11 ----- .../Abstractions/Routing/RouteAttribute.cs | 28 ------------- .../Core/Presenters/IPresenterInternal.cs | 6 +-- .../Core/Presenters/PresentResultArgs.cs | 24 +++++++++++ .../Presenters/PresentResultArgs.cs.meta} | 2 +- .../PresentResult{TController,TResult}.cs | 40 ++++++++++++------ .../Core/Presenters/Presenter{TController}.cs | 41 ++++++++++--------- .../Runtime/Core/Views/UGUIViewFactory.cs | 38 +++++++++-------- .../Editor/Helpers/DefaultViewFactory.cs | 4 +- 14 files changed, 107 insertions(+), 170 deletions(-) delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing.meta delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs.meta delete mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs create mode 100644 Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResultArgs.cs rename Assets/Plugins/UnityFx.Mvc/Runtime/{Abstractions/Routing/RouteAttribute.cs.meta => Core/Presenters/PresentResultArgs.cs.meta} (83%) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewFactory.cs index b6de0d6..f49e276 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IViewFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -17,10 +17,11 @@ public interface IViewFactory /// /// Creates a view for a controller of the specified type. /// - /// Type of the view controller to create view for. + /// Path to the view prefab asset. + /// /// Z-order index. /// Present options. /// Parent transform for the view (or ). - Task CreateAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent); + Task CreateAsync(string prefabPath, int layer, int zIndex, PresentOptions options, Transform parent); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs index cec2940..0c56579 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.Collections.Generic; using System.ComponentModel; using UnityEngine; @@ -84,37 +83,6 @@ protected virtual void OnDispose() { } - /// - /// Gets name of a view prefab assigned to the controllers of the specified type. - /// - /// Type of the controller. - /// Prefab name. - public static string GetPrefabName(Type controllerType) - { - if (controllerType is null) - { - throw new ArgumentNullException(nameof(controllerType)); - } - - var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false); - - if (attrs != null && attrs.Length > 0 && !string.IsNullOrEmpty(attrs[0].ViewPrefabName)) - { - return attrs[0].ViewPrefabName; - } - else - { - var viewName = controllerType.Name; - - if (viewName.EndsWith("Controller")) - { - viewName = viewName.Substring(0, viewName.Length - 10); - } - - return viewName; - } - } - #endregion #region MonoBehaviour diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs index ba8ada3..c96b882 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/ViewControllerAttribute.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using UnityEngine; namespace UnityFx.Mvc { @@ -13,25 +12,18 @@ namespace UnityFx.Mvc public sealed class ViewControllerAttribute : Attribute { /// - /// Gets or sets name of the view prefab. + /// Gets or sets default present options value. /// - public string ViewPrefabName { get; set; } - - /// - /// Gets or sets index of the view layer. - /// - public int ViewLayer { get; set; } + public PresentOptions PresentOptions { get; set; } /// - /// Gets or sets present options. + /// Gets or sets path to the view prefab. If this is not set, controller name is used as the prefab path (i.e. 'Help' for controller named 'HelpController'). /// - public PresentOptions PresentOptions { get; set; } + public string PrefabPath { get; set; } /// - /// Initializes a new instance of the class. + /// Gets or sets layer index. /// - public ViewControllerAttribute() - { - } + public int Layer { get; set; } } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing.meta deleted file mode 100644 index 0dcd7ec..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 86d97ba9a74d9394dbca53d756a9c617 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs deleted file mode 100644 index a740497..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. -// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; -using System.Threading.Tasks; - -namespace UnityFx.Mvc.Routing -{ - /// - /// A generic router. - /// - public interface IRouter - { - Task RouteAsync(); - } -} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs.meta deleted file mode 100644 index 58eed99..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/IRouter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 279610838f00401459eae39533d792d7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs deleted file mode 100644 index 48ea018..0000000 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. -// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; -using UnityEngine; - -namespace UnityFx.Mvc -{ - /// - /// Marks a route for a controller. - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] - public sealed class RouteAttribute : Attribute - { - /// - /// Gets the route template. May be . - /// - public string Template { get; } - - /// - /// Initializes a new instance of the class. - /// - public RouteAttribute(string template) - { - Template = template; - } - } -} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresenterInternal.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresenterInternal.cs index 9fe9e6f..1bfe8dd 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresenterInternal.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresenterInternal.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -8,11 +8,7 @@ namespace UnityFx.Mvc { internal interface IPresenterInternal { - IServiceProvider ServiceProvider { get; } - IViewFactory ViewFactory { get; } - IViewControllerFactory ControllerFactory { get; } IPresentResult PresentAsync(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args); void Dismiss(IPresentable presentable); - int GetNextId(); } } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResultArgs.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResultArgs.cs new file mode 100644 index 0000000..9ed6da1 --- /dev/null +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResultArgs.cs @@ -0,0 +1,24 @@ +// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Licensed under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using UnityEngine; + +namespace UnityFx.Mvc +{ + internal class PresentResultArgs + { + public IServiceProvider ServiceProvider; + public IViewControllerFactory ControllerFactory; + public IViewFactory ViewFactory; + + public int Id; + public int Layer; + public string PrefabPath; + + public IPresentable Parent; + public Type ControllerType; + public PresentOptions PresentOptions; + public PresentArgs PresentArgs; + } +} diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs.meta b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResultArgs.cs.meta similarity index 83% rename from Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs.meta rename to Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResultArgs.cs.meta index c9a3ca2..d3c33e4 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Routing/RouteAttribute.cs.meta +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResultArgs.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6c28c3d5aeed8e742990ea8ae45b4bcd +guid: 47ae981f6e6aeb94c833b12f80c7c76c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs index da8df93..6532a6c 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs @@ -47,6 +47,8 @@ private struct TimerData private readonly PresentOptions _presentOptions; private readonly IPresentable _parent; private readonly int _id; + private readonly int _layer; + private readonly string _prefabPath; private readonly string _deeplinkId; private IServiceProvider _serviceProvider; @@ -65,22 +67,22 @@ private struct TimerData #region interface - public PresentResult(IPresenterInternal presenter, IPresentable parent, Type controllerType, PresentOptions presentOptions, PresentArgs args) - : base(parent) + public PresentResult(IPresenterInternal presenter, PresentResultArgs context) { Debug.Assert(presenter != null); - Debug.Assert(controllerType != null); - Debug.Assert(args != null); + Debug.Assert(context != null); _presenter = presenter; - _parent = parent; - _serviceProvider = presenter.ServiceProvider; - _controllerFactory = presenter.ControllerFactory; - _controllerType = controllerType; - _presentArgs = args; - _presentOptions = presentOptions; - _id = presenter.GetNextId(); - _deeplinkId = GetDeeplinkId(controllerType); + _id = context.Id; + _layer = context.Layer; + _parent = context.Parent; + _serviceProvider = context.ServiceProvider; + _controllerFactory = context.ControllerFactory; + _controllerType = context.ControllerType; + _presentArgs = context.PresentArgs; + _presentOptions = context.PresentOptions; + _deeplinkId = GetDeeplinkId(_controllerType); + _prefabPath = string.IsNullOrEmpty(context.PrefabPath) ? GetDefaultPrefabName(_controllerType) : context.PrefabPath; } #endregion @@ -120,7 +122,7 @@ public async Task PresentAsync(IViewFactory viewFactory, int index, Transform pa try { - _view = await viewFactory.CreateAsync(_controllerType, index, _presentOptions, parent); + _view = await viewFactory.CreateAsync(_prefabPath, _layer, index, _presentOptions, parent); if (_state == State.Initialized) { @@ -475,6 +477,18 @@ private void ThrowIfDisposed() } private static string GetDeeplinkId(Type controllerType) + { + var deeplinkId = controllerType.Name.ToLower(); + + if (deeplinkId.EndsWith("controller")) + { + deeplinkId = deeplinkId.Substring(0, deeplinkId.Length - 10); + } + + return deeplinkId; + } + + private static string GetDefaultPrefabName(Type controllerType) { var deeplinkId = controllerType.Name; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs index 0964cf6..fcef2fe 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs @@ -323,10 +323,6 @@ private void OnDestroy() #region IPresenterInternal - IViewFactory IPresenterInternal.ViewFactory => _viewFactory; - - IViewControllerFactory IPresenterInternal.ControllerFactory => _controllerFactory; - IPresentResult IPresenterInternal.PresentAsync(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args) { return PresentInternal(presentable, controllerType, presentOptions, parent, args); @@ -375,11 +371,6 @@ void IPresenterInternal.Dismiss(IPresentable presentable) } } - int IPresenterInternal.GetNextId() - { - return ++_idCounter; - } - #endregion #region IPresenter @@ -500,34 +491,46 @@ private IPresentable CreatePresentable(IPresentable parent, Type co var resultType = typeof(int); var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false); + var presentContext = new PresentResultArgs() + { + Id = ++_idCounter, + ServiceProvider = _serviceProvider, + ControllerFactory = _controllerFactory, + ViewFactory = _viewFactory, + ControllerType = controllerType, + Parent = parent, + PresentOptions = presentOptions, + PresentArgs = args ?? PresentArgs.Default + }; if (attrs != null && attrs.Length > 0) { var controllerAttr = attrs[0]; - presentOptions |= controllerAttr.PresentOptions; + + presentContext.PresentOptions |= controllerAttr.PresentOptions; + presentContext.Layer = controllerAttr.Layer; + presentContext.PrefabPath = controllerAttr.PrefabPath; } - // Types inherited from ViewController<,> do not require ViewControllerAttribute. + // Types inherited from IViewControllerResult<> use specific result values. if (typeof(IViewControllerResult<>).IsAssignableFrom(controllerType)) { resultType = controllerType.GenericTypeArguments[0]; } - // Make sure args are valid. - if (args is null) + // If parent is going to be dismissed, use its parent instead. + if ((presentOptions & PresentOptions.DismissAll) != 0) { - args = PresentArgs.Default; + presentContext.Parent = null; } - - // If parent is going to be dismissed, use its parent instead. - if ((presentOptions & PresentOptions.DismissCurrent) != 0) + else if ((presentOptions & PresentOptions.DismissCurrent) != 0) { - parent = parent?.Parent; + presentContext.Parent = parent?.Parent; } // https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/how-to-examine-and-instantiate-generic-types-with-reflection var presentResultType = typeof(PresentResult<,>).MakeGenericType(controllerType, resultType); - var c = (IPresentable)Activator.CreateInstance(presentResultType, this, parent, controllerType, presentOptions, args); + var c = (IPresentable)Activator.CreateInstance(presentResultType, this, presentContext); AddPresentable(c); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs index 56cc160..7eade01 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs @@ -81,14 +81,14 @@ protected void ClearPrefabCache() /// /// Gets root for a view of the specified controller. /// - protected virtual Transform GetViewRoot(Type controllerType, ViewControllerAttribute attr) + protected virtual Transform GetViewRoot(int layer) { if (_viewRoots is null || _viewRoots.Length == 0) { return transform; } - return _viewRoots[attr.ViewLayer]; + return _viewRoots[layer]; } /// @@ -160,42 +160,44 @@ private void OnDestroy() #region IViewFactory - public async Task CreateAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent) + public async Task CreateAsync(string prefabPath, int layer, int zIndex, PresentOptions options, Transform parent) { ThrowIfDisposed(); - if (controllerType is null) + if (prefabPath is null) { - throw new ArgumentNullException(nameof(controllerType)); + throw new ArgumentNullException(nameof(prefabPath)); + } + + if (string.IsNullOrWhiteSpace(prefabPath)) + { + throw new ArgumentException("Invalid prefab name.", nameof(prefabPath)); } ViewProxy viewProxy = null; try { - var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false); - var attr = attrs != null && attrs.Length > 0 ? attrs[0] : null; var exclusive = (options & PresentOptions.Exclusive) != 0; var modal = (options & PresentOptions.Modal) != 0; - var prefabName = GetPrefabName(controllerType, attr); - var viewRoot = GetViewRoot(controllerType, attr); + var viewRoot = GetViewRoot(layer); - viewProxy = CreateViewProxy(viewRoot, prefabName, zIndex, exclusive, modal); + viewProxy = CreateViewProxy(viewRoot, prefabPath, zIndex, exclusive, modal); - if (_viewPrefabCache.TryGetValue(prefabName, out var viewPrefab)) + if (_viewPrefabCache.TryGetValue(prefabPath, out var viewPrefab)) { return CreateView(viewPrefab, viewProxy, parent); } else { - if (_viewPrefabCacheTasks.TryGetValue(prefabName, out var task)) + if (_viewPrefabCacheTasks.TryGetValue(prefabPath, out var task)) { viewPrefab = await task; } else { - task = LoadViewPrefabAsync(prefabName); - _viewPrefabCacheTasks.Add(prefabName, task); + task = LoadViewPrefabAsync(prefabPath); + _viewPrefabCacheTasks.Add(prefabPath, task); try { @@ -203,7 +205,7 @@ public async Task CreateAsync(Type controllerType, int zIndex, PresentOpt } finally { - _viewPrefabCacheTasks.Remove(prefabName); + _viewPrefabCacheTasks.Remove(prefabPath); } } @@ -212,7 +214,7 @@ public async Task CreateAsync(Type controllerType, int zIndex, PresentOpt throw new OperationCanceledException(); } - _viewPrefabCache.Add(prefabName, viewPrefab); + _viewPrefabCache.Add(prefabPath, viewPrefab); return CreateView(viewPrefab, viewProxy, parent); } } @@ -340,9 +342,9 @@ private string GetPrefabName(Type controllerType, ViewControllerAttribute attr) { Debug.Assert(controllerType != null); - if (attr != null && !string.IsNullOrEmpty(attr.ViewPrefabName)) + if (attr != null && !string.IsNullOrEmpty(attr.PrefabPath)) { - return attr.ViewPrefabName; + return attr.PrefabPath; } else { diff --git a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultViewFactory.cs index 9e424ea..98563cf 100644 --- a/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Tests/Editor/Helpers/DefaultViewFactory.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. +// Copyright (C) 2019 Alexander Bogarsukov. All rights reserved. // See the LICENSE.md file in the project root for more information. using System; @@ -10,7 +10,7 @@ namespace UnityFx.Mvc { public class DefaultViewFactory : IViewFactory { - public async Task CreateAsync(Type controllerType, int zIndex, PresentOptions options, Transform parent) + public async Task CreateAsync(string prefabPath, int layer, int zIndex, PresentOptions options, Transform parent) { await Task.Delay(10); return new DefaultView(); From 60007b166f6c598cad922c01c7f15d6aea807923 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sat, 4 Jan 2020 22:39:06 +0200 Subject: [PATCH 26/34] IView does not implement IComponet now --- .../Editor/Inspectors/ViewProxyEditor.cs | 2 +- .../Runtime/Abstractions/Mvc/IView.cs | 10 +- .../Runtime/Abstractions/Mvc/View.cs | 41 +----- .../PresentResult{TController,TResult}.cs | 2 - .../Core/Presenters/Presenter{TController}.cs | 3 - .../Views/UGUIViewFactory.ViewCollection.cs | 20 +-- .../Core/Views/UGUIViewFactory.ViewProxy.cs | 51 +++----- .../Runtime/Core/Views/UGUIViewFactory.cs | 121 +----------------- 8 files changed, 40 insertions(+), 210 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs index c146917..2833056 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Inspectors/ViewProxyEditor.cs @@ -23,7 +23,7 @@ public override void OnInspectorGUI() EditorGUI.BeginDisabledGroup(true); - EditorGUILayout.ObjectField("View", _viewProxy.Component as Component, typeof(Component), true); + EditorGUILayout.ObjectField("View", _viewProxy.View as Component, typeof(Component), true); EditorGUILayout.Toggle("Modal", _viewProxy.Modal); EditorGUILayout.Toggle("Exclusive", _viewProxy.Exclusive); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IView.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IView.cs index 00a24df..e2c633f 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IView.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/IView.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.ComponentModel; using UnityEngine; namespace UnityFx.Mvc @@ -17,8 +16,13 @@ namespace UnityFx.Mvc /// /// /// - public interface IView : IComponent, INotifyCommand + public interface IView : INotifyCommand, IDisposable { + /// + /// Raised when the view is disposed. + /// + event EventHandler Disposed; + /// /// Gets the this view is attached to. /// diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs index 0c56579..c0c692d 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Mvc/View.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.ComponentModel; using UnityEngine; namespace UnityFx.Mvc @@ -15,18 +14,12 @@ public class View : MonoBehaviour, IView { #region data - private ISite _site; private bool _disposed; #endregion #region interface - /// - /// Gets a transform the is attached to (if any). - /// - protected Transform SiteTransform => (_site as UnityEngine.Component)?.transform; - /// /// Gets a value indicating whether the view is disposed. /// @@ -96,6 +89,13 @@ private void OnDestroy() #region IView + /// + /// Represents the method that handles the dispose event of the view. + /// + /// + /// + public event EventHandler Disposed; + /// /// Gets the this view is attached to. /// @@ -130,32 +130,6 @@ public bool Enabled #endregion - #region IComponent - - /// - /// Represents the method that handles the dispose event of a component. - /// - /// - /// - public event EventHandler Disposed; - - /// - /// Gets or sets the associated with the . - /// - public ISite Site - { - get - { - return _site; - } - set - { - _site = value; - } - } - - #endregion - #region IDisposable /// @@ -170,7 +144,6 @@ public void Dispose() if (!_disposed) { _disposed = true; - _site?.Container?.Remove(this); try { diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs index 6532a6c..5b973fe 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs @@ -4,8 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using UnityEngine; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs index fcef2fe..246d030 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs @@ -4,9 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using UnityEngine; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs index 20b8afb..5878717 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewCollection.cs @@ -93,7 +93,7 @@ public bool Contains(IView view) { var proxy = viewRoot.GetChild(i).GetComponent(); - if (proxy && proxy.Component == view) + if (proxy && proxy.View == view) { return true; } @@ -115,7 +115,7 @@ public void CopyTo(IView[] array, int arrayIndex) { for (var i = 0; i < viewRoot.childCount; ++i) { - array[arrayIndex + i] = viewRoot.GetChild(i).GetComponent()?.Component as IView; + array[arrayIndex + i] = viewRoot.GetChild(i).GetComponent()?.View; } } } @@ -136,7 +136,7 @@ public IEnumerator GetEnumerator() for (var i = 0; i < viewRoot.childCount; ++i) { var proxy = viewRoot.GetChild(i).GetComponent(); - yield return proxy?.Component as IView; + yield return proxy?.View; } } } @@ -144,19 +144,7 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - var viewRoots = _factory.ViewRoots; - - if (viewRoots != null) - { - foreach (var viewRoot in viewRoots) - { - for (var i = 0; i < viewRoot.childCount; ++i) - { - var proxy = viewRoot.GetChild(i).GetComponent(); - yield return proxy?.Component; - } - } - } + return GetEnumerator(); } #endregion diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs index 6c30673..07153f5 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs @@ -2,8 +2,6 @@ // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; -using System.Collections.Generic; -using System.ComponentModel; using UnityEngine; using UnityEngine.UI; @@ -13,11 +11,11 @@ partial class UGUIViewFactory { #region implementation - internal class ViewProxy : MonoBehaviour, ISite + internal class ViewProxy : MonoBehaviour { #region data - private IComponent _view; + private IView _view; #endregion @@ -27,17 +25,7 @@ internal class ViewProxy : MonoBehaviour, ISite public bool Exclusive { get; set; } public bool Modal { get; set; } - internal void DestroyInternal() - { - _view.Site = null; - Destroy(gameObject); - } - - #endregion - - #region ISite - - public IComponent Component + public IView View { get { @@ -49,14 +37,14 @@ public IComponent Component { if (_view != null) { - _view.Site?.Container?.Remove(_view); + _view.Disposed -= OnViewDisposed; } _view = value; if (_view != null) { - _view.Site = this; + _view.Disposed += OnViewDisposed; if (_view is MonoBehaviour b) { @@ -70,33 +58,30 @@ public IComponent Component } } - public IContainer Container { get; set; } - public bool DesignMode => false; - public string Name { get => name; set => name = value; } - #endregion - #region IServiceProvider + #region MonoBehaviour - public object GetService(Type serviceType) + private void OnDestroy() { - if (serviceType == typeof(ISite)) - { - return this; - } - - if (Container is IServiceProvider sp) + if (_view is MonoBehaviour b && b.gameObject) { - return sp.GetService(serviceType); + Destroy(b.gameObject); } - - return null; } - #endregion #region implementation + + private void OnViewDisposed(object sender, EventArgs args) + { + if (gameObject) + { + Destroy(gameObject); + } + } + #endregion } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs index 7eade01..10d3574 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; @@ -13,7 +12,7 @@ namespace UnityFx.Mvc /// /// Default -based view factory. /// - public partial class UGUIViewFactory : MonoBehaviour, IViewFactory, IContainer + public partial class UGUIViewFactory : MonoBehaviour, IViewFactory { #region data @@ -27,7 +26,6 @@ public partial class UGUIViewFactory : MonoBehaviour, IViewFactory, IContainer private Dictionary _viewPrefabCache = new Dictionary(); private Dictionary> _viewPrefabCacheTasks = new Dictionary>(); private ViewCollection _views; - private ComponentCollection _components; private bool _disposed; #endregion @@ -231,75 +229,6 @@ public async Task CreateAsync(string prefabPath, int layer, int zIndex, P #endregion - #region IContainer - - ComponentCollection IContainer.Components - { - get - { - ThrowIfDisposed(); - - if (_components is null) - { - _components = new ComponentCollection(Views.ToArray()); - } - - return _components; - } - } - - void IContainer.Add(IComponent component) - { - ThrowIfDisposed(); - - if (component is null) - { - throw new ArgumentNullException(nameof(component)); - } - - AddInternal(component, null); - } - - void IContainer.Add(IComponent component, string name) - { - ThrowIfDisposed(); - - if (component is null) - { - throw new ArgumentNullException(nameof(component)); - } - - AddInternal(component, name); - } - - void IContainer.Remove(IComponent component) - { - if (component != null && !_disposed) - { - _components = null; - - if (component.Site != null) - { - if (!ReferenceEquals(component.Site.Container, this)) - { - return; - } - - if (component.Site is ViewProxy p) - { - p.Container = null; - Destroy(p.gameObject); - } - - component.Site = null; - } - - UpdatePopupBackgrounds(); - } - } - - #endregion - #region IDisposable public void Dispose() @@ -307,7 +236,6 @@ public void Dispose() if (!_disposed) { _disposed = true; - _components = null; _viewPrefabCache = null; OnDispose(); @@ -318,47 +246,6 @@ public void Dispose() #region implementation - private void AddInternal(IComponent component, string name) - { - Debug.Assert(component != null); - - var view = component as IView; - - if (view is null) - { - throw new ArgumentException("The component should implement IView.", nameof(component)); - } - - if (string.IsNullOrEmpty(name)) - { - name = "View"; - } - - var viewProxy = CreateViewProxy(null, name, transform.childCount, false, false); - viewProxy.Component = component; - } - - private string GetPrefabName(Type controllerType, ViewControllerAttribute attr) - { - Debug.Assert(controllerType != null); - - if (attr != null && !string.IsNullOrEmpty(attr.PrefabPath)) - { - return attr.PrefabPath; - } - else - { - var viewName = controllerType.Name; - - if (viewName.EndsWith("Controller")) - { - viewName = viewName.Substring(0, viewName.Length - 10); - } - - return viewName; - } - } - private IView CreateView(GameObject viewPrefab, ViewProxy viewProxy, Transform parent) { Debug.Assert(viewProxy); @@ -384,7 +271,7 @@ private IView CreateView(GameObject viewPrefab, ViewProxy viewProxy, Transform p go.transform.SetParent(parent ?? viewProxy.transform); } - viewProxy.Component = view; + viewProxy.View = view; return view; } @@ -431,8 +318,6 @@ private ViewProxy CreateViewProxy(Transform viewRoot, string viewName, int zInde viewProxy.Modal = modal; viewProxy.Exclusive = exclusive; - viewProxy.Container = this; - viewProxy.Name = viewName; return viewProxy; } @@ -445,7 +330,7 @@ private void UpdatePopupBackgrounds() { var c = transform.GetChild(i).GetComponent(); - if (c && c.Container != null && c.Image) + if (c && c.Image) { if (modalFound) { From f07986574e46ab39658eafc6ff02c2f279a1a5ee Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sat, 4 Jan 2020 22:40:53 +0200 Subject: [PATCH 27/34] CHANGELOG update --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ff5d3f..5684e4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/); this proj - Renamed `IPresenter.PresentAsync` to `Present`. Added a group of `PresentAsync` extension methods returning `Task` instead of `IPresentResult`. - Renamed `IPresentResult.DismissTask` to `Task`. - Changed `Present`/`PresentAsync` arguments. +- Changed `IViewFactory` and `IViewControllerFactory` interfaces. +- `IView` now does not inherit `IComponent`. ### Removed - Removed `IPresentResult.PresentTask`. From 3dfcaa36b4c51a54a148354ad0d25665f2c2d983 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 5 Jan 2020 14:26:03 +0200 Subject: [PATCH 28/34] Added presenter event handlers --- .../Abstractions/Presenters/IPresentResult.cs | 2 +- .../Abstractions/Presenters/PresentOptions.cs | 7 +- .../Runtime/Core/Presenters/IPresentable.cs | 5 +- .../PresentResult{TController,TResult}.cs | 58 ++++++------- .../Core/Presenters/Presenter{TController}.cs | 82 ++++++++++++++----- Assets/Scenes/Test.unity | 1 + Assets/Scripts/AppRoot.cs | 7 +- 7 files changed, 101 insertions(+), 61 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult.cs index 951363e..b752870 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/IPresentResult.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs index 3184767..2d5f0c2 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs @@ -33,13 +33,18 @@ public enum PresentOptions /// Modal = 4, + /// + /// Do not parent the controller to any other. + /// + Detach = 0x10, + /// /// If set the caller presenter is dismissed. /// DismissCurrent = 0x1000, /// - /// If set the caller presenter is dismissed. + /// If set all controllers are dismissed before presenting the new one. /// DismissAll = 0x2000 } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable.cs index 176bb93..3eb530e 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/IPresentable.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -10,10 +10,13 @@ namespace UnityFx.Mvc { internal interface IPresentable : IPresentResult { + int Layer { get; } bool IsActive { get; } bool IsDismissed { get; } IPresentable Parent { get; } PresentOptions PresentOptions { get; } + PresentArgs PresentArgs { get; } + Type ControllerType { get; } Task PresentAsync(IViewFactory viewFactory, int index, Transform parent); void Update(float frameTime, bool isTop); void DismissUnsafe(); diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs index 5b973fe..f3a8819 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/PresentResult{TController,TResult}.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using UnityEngine; +using UnityEngine.Scripting; namespace UnityFx.Mvc { @@ -18,7 +19,8 @@ namespace UnityFx.Mvc /// controller context outside of actual controller. This class manages the controller created, provides its context /// (via interface) and serves as a proxy between the controller and user. /// - internal class PresentResult : TaskCompletionSource, IPresentContext, IPresentResult, IPresentResultOf, IPresentResultOf, IPresentable, IEnumerator where TController : class, IViewController + [Preserve] + internal sealed class PresentResult : TaskCompletionSource, IPresentContext, IPresentResult, IPresentResultOf, IPresentResultOf, IPresentable, IEnumerator where TController : class, IViewController { #region data @@ -87,8 +89,12 @@ public PresentResult(IPresenterInternal presenter, PresentResultArgs context) #region IPresentable + public int Layer => _layer; + public IPresentable Parent => _parent; + public Type ControllerType => _controllerType; + public bool TryActivate() { if (_state == State.Presented) @@ -147,6 +153,7 @@ public async Task PresentAsync(IViewFactory viewFactory, int index, Transform pa { LogException(e); DismissInternal(default, true); + throw; } } @@ -282,7 +289,12 @@ public IPresentResult Present(Type controllerType, PresentArgs args, PresentOpti public bool InvokeCommand(TCommand command) { - return _controller.InvokeCommand(command); + if (_state == State.Presented || _state == State.Active) + { + return _controller.InvokeCommand(command); + } + + return false; } #endregion @@ -379,38 +391,24 @@ private void DismissInternal(TResult result, bool cancelled) private void UpdateActive(bool isTop) { - try + if (isTop) { - if (isTop) + if (_state == State.Presented) { - if (_state == State.Presented) - { - _state = State.Active; - _controllerEvents?.OnActivate(); - } - } - else if (_state == State.Active) - { - _state = State.Presented; - _controllerEvents?.OnDeactivate(); + _state = State.Active; + _controllerEvents?.OnActivate(); } } - catch (Exception e) + else if (_state == State.Active) { - Debug.LogException(e); + _state = State.Presented; + _controllerEvents?.OnDeactivate(); } } private void UpdateController(float frameTime) { - try - { - _controllerEvents?.OnUpdate(frameTime); - } - catch (Exception e) - { - Debug.LogException(e); - } + _controllerEvents?.OnUpdate(frameTime); } private void UpdateTimers(float frameTime) @@ -427,16 +425,8 @@ private void UpdateTimers(float frameTime) if (timerData.Timer >= timerData.Timeout) { - try - { - timerData.Callback(timerData.Timer); - } - catch (Exception e) - { - Debug.LogException(e); - } - _timers.Remove(node); + timerData.Callback(timerData.Timer); } node = node.Next; @@ -446,8 +436,6 @@ private void UpdateTimers(float frameTime) private void LogException(Exception e) { - Debug.LogException(e); - if (!Task.IsCompleted) { if (_exceptions == null) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs index 246d030..c73a935 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs @@ -11,8 +11,6 @@ namespace UnityFx.Mvc { - using Debug = UnityEngine.Debug; - /// /// Default -based presenter implementation. /// @@ -260,6 +258,28 @@ protected static void AotCodegenGuard() #region virtual interface + /// + /// Called right before presenting a controller. + /// + protected virtual void OnPresent(Type controllerType, PresentOptions presentOptions, PresentArgs args) + { + } + + /// + /// Called right after presenting a controller. + /// + protected virtual void OnPresented(Type controllerType) + { + } + + /// + /// Called right before presenting a controller. + /// + protected virtual void OnPresentError(Type controllerType, Exception e) + { + Debug.LogException(e); + } + /// /// Called on each frame. Default implementation does nothing. /// @@ -449,35 +469,36 @@ private IPresentResult PresentInternal(IPresentable presentable, Type controller return result; } - private void PresentInternal(IPresentable presentable, IPresentable presentableParent, Transform transform) + private async void PresentInternal(IPresentable presentable, IPresentable presentableParent, Transform transform) { - var zIndex = 0; + var zIndex = GetZIndex(presentable); - foreach (var p in _presentables) + try { - if (p == presentable) - { - break; - } + OnPresent(presentable.ControllerType, presentable.PresentOptions, presentable.PresentArgs); - ++zIndex; - } - - presentable.PresentAsync(_viewFactory, zIndex, transform); + await presentable.PresentAsync(_viewFactory, zIndex, transform); - if ((presentable.PresentOptions & PresentOptions.DismissAll) != 0) - { - foreach (var p in _presentables) + if ((presentable.PresentOptions & PresentOptions.DismissAll) != 0) { - if (p != presentable) + foreach (var p in _presentables) { - p.Dispose(); + if (p != presentable) + { + p.Dispose(); + } } } + else if ((presentable.PresentOptions & PresentOptions.DismissCurrent) != 0) + { + presentableParent?.Dispose(); + } + + OnPresented(presentable.ControllerType); } - else if ((presentable.PresentOptions & PresentOptions.DismissCurrent) != 0) + catch (Exception e) { - presentableParent?.Dispose(); + OnPresentError(presentable.ControllerType, e); } } @@ -516,7 +537,7 @@ private IPresentable CreatePresentable(IPresentable parent, Type co } // If parent is going to be dismissed, use its parent instead. - if ((presentOptions & PresentOptions.DismissAll) != 0) + if ((presentOptions & PresentOptions.DismissAll) != 0 || (presentOptions & PresentOptions.Detach) != 0) { presentContext.Parent = null; } @@ -598,6 +619,25 @@ private void SetBusy(bool busy) } } + private int GetZIndex(IPresentable presentable) + { + var zIndex = 0; + + foreach (var p in _presentables) + { + if (p == presentable) + { + break; + } + else if (p.Layer == presentable.Layer) + { + ++zIndex; + } + } + + return zIndex; + } + private void ThrowIfBusy() { if (_busyCounter > 0) diff --git a/Assets/Scenes/Test.unity b/Assets/Scenes/Test.unity index c052107..5caf80c 100644 --- a/Assets/Scenes/Test.unity +++ b/Assets/Scenes/Test.unity @@ -179,6 +179,7 @@ MonoBehaviour: _viewPrefabs: - {fileID: 240879178860548289, guid: 3091374f3c0c527468342f660648e692, type: 3} - {fileID: 7846704816992948672, guid: 7fb867d34bbeca048a50534ffe67f80d, type: 3} + - {fileID: 2865599842196110682, guid: 03caa09d8ee99b241a82254be16bc57e, type: 3} --- !u!114 &1385712683 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/AppRoot.cs b/Assets/Scripts/AppRoot.cs index 0c2ff39..527d6bc 100644 --- a/Assets/Scripts/AppRoot.cs +++ b/Assets/Scripts/AppRoot.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Alexander Bogarsukov. +// Copyright (c) 2018-2020 Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; @@ -31,8 +31,11 @@ private async void Start() { try { + _ = _presenter.PresentAsync(); + await _presenter.PresentAsync(); - await _presenter.PresentAsync(); + + _ = _presenter.PresentAsync(); } catch (OperationCanceledException) { From dada9f5d4d076303919395d3fa27c89aa3ad5d36 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 5 Jan 2020 15:06:05 +0200 Subject: [PATCH 29/34] Added present args auto-creation support --- .../Windows/CreateViewControllerWindow.cs | 95 +++++++++++++++++-- 1 file changed, 87 insertions(+), 8 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs index 0468c03..85680e8 100644 --- a/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs +++ b/Assets/Plugins/UnityFx.Mvc/Editor/Windows/CreateViewControllerWindow.cs @@ -20,6 +20,7 @@ public class CreateViewControllerWindow : EditorWindow private bool _exclusive; private bool _modal; private bool _popup; + private bool _createArgs; private Regex _classNamePattern = new Regex("^[_a-zA-Z][_a-zA-Z0-9]*$"); @@ -44,6 +45,7 @@ private void OnGUI() GUI.enabled = true; _controllerName = EditorGUILayout.TextField("Controller Name", _controllerName); + _createArgs = EditorGUILayout.Toggle("Create PresentArgs", _createArgs); _exclusive = EditorGUILayout.Toggle("Exclusive", _exclusive); _popup = EditorGUILayout.Toggle("Popup", _popup); _modal = EditorGUILayout.Toggle("Modal", _modal); @@ -95,22 +97,29 @@ private void CreateViewController(string path) } else { - path = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(path, _controllerName)); + path = Path.Combine(path, _controllerName); - if (!Directory.Exists(path)) + var fullPath = Path.Combine(Directory.GetCurrentDirectory(), path); + + if (!Directory.Exists(fullPath)) { - Directory.CreateDirectory(path); + Directory.CreateDirectory(fullPath); } var indent = " "; var controllerName = _controllerName + "Controller"; var controllerFileName = controllerName + ".cs"; - var controllerPath = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(path, controllerFileName)); + var controllerPath = Path.Combine(fullPath, controllerFileName); var controllerText = new StringBuilder(); + var argsName = _controllerName + "Args"; + var argsFileName = argsName + ".cs"; + var argsPath = Path.Combine(fullPath, argsFileName); + var argsText = new StringBuilder(); + var viewName = _controllerName + "View"; var viewFileName = viewName + ".cs"; - var viewPath = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(path, viewFileName)); + var viewPath = Path.Combine(fullPath, viewFileName); var viewText = new StringBuilder(); var prefabPath = Path.Combine(path, _controllerName + ".prefab"); @@ -136,6 +145,12 @@ private void CreateViewController(string path) controllerText.AppendLine(indent + "/// " + controllerName); controllerText.AppendLine(indent + "/// "); controllerText.AppendFormat(indent + "/// " + Environment.NewLine, viewName); + + if (_createArgs) + { + controllerText.AppendFormat(indent + "/// " + Environment.NewLine, argsName); + } + controllerText.AppendFormat(indent + "[ViewController(PresentOptions = {0})]" + Environment.NewLine, GetPresentOptions(_exclusive, _popup, _modal)); controllerText.AppendFormat(indent + "public class {0} : {1}<{2}>" + Environment.NewLine, controllerName, _controllerBaseClass, viewName); controllerText.AppendLine(indent + "{"); @@ -155,11 +170,30 @@ private void CreateViewController(string path) controllerText.AppendLine(indent + " /// "); controllerText.AppendFormat(indent + " /// Initializes a new instance of the class." + Environment.NewLine, controllerName); controllerText.AppendLine(indent + " /// "); - controllerText.AppendFormat(indent + " public {0}({1} context)" + Environment.NewLine, controllerName, nameof(IPresentContext)); + controllerText.AppendFormat(indent + " public {0}({1} context", controllerName, nameof(IPresentContext)); + + if (_createArgs) + { + controllerText.AppendFormat(", {0} args)" + Environment.NewLine, argsName); + } + else + { + controllerText.AppendLine(")"); + } + controllerText.AppendLine(indent + " : base(context)"); controllerText.AppendLine(indent + " {"); controllerText.AppendLine(indent + " // TODO: Initialize the controller view here. Add arguments to the Configure() as needed."); - controllerText.AppendLine(indent + " View.Configure();"); + + if (_createArgs) + { + controllerText.AppendLine(indent + " View.Configure(args);"); + } + else + { + controllerText.AppendLine(indent + " View.Configure();"); + } + controllerText.AppendLine(indent + " }"); controllerText.AppendLine(""); controllerText.AppendLine(indent + " #endregion"); @@ -214,6 +248,12 @@ private void CreateViewController(string path) viewText.AppendFormat(indent + "/// View for the ." + Environment.NewLine, controllerName); viewText.AppendLine(indent + "/// "); viewText.AppendFormat(indent + "/// " + Environment.NewLine, controllerName); + + if (_createArgs) + { + viewText.AppendFormat(indent + "/// " + Environment.NewLine, argsName); + } + viewText.AppendFormat(indent + "public class {0} : {1}" + Environment.NewLine, viewName, _viewBaseClass); viewText.AppendLine(indent + "{"); viewText.AppendLine(indent + " #region data"); @@ -231,7 +271,16 @@ private void CreateViewController(string path) viewText.AppendLine(indent + " /// "); viewText.AppendLine(indent + " /// Initializes the view. Called from the controller ctor." ); viewText.AppendLine(indent + " /// "); - viewText.AppendLine(indent + " public void Configure()"); + + if (_createArgs) + { + viewText.AppendFormat(indent + " public void Configure({0} args)" + Environment.NewLine, argsName); + } + else + { + viewText.AppendLine(indent + " public void Configure()"); + } + viewText.AppendLine(indent + " {"); viewText.AppendLine(indent + " // TODO: Setup the view. Add additional arguments as needed."); viewText.AppendLine(indent + " }"); @@ -251,6 +300,36 @@ private void CreateViewController(string path) } File.WriteAllText(viewPath, viewText.ToString()); + + // Args source. + argsText.AppendLine("using System;"); + argsText.AppendLine("using System.Collections.Generic;"); + argsText.AppendLine("using UnityEngine;"); + argsText.AppendLine("using UnityFx.Mvc;"); + argsText.AppendLine(""); + + if (!string.IsNullOrEmpty(_namespace)) + { + argsText.AppendLine("namespace " + _namespace); + argsText.AppendLine("{"); + } + + argsText.AppendLine(indent + "/// "); + argsText.AppendFormat(indent + "/// Arguments for the ." + Environment.NewLine, controllerName); + argsText.AppendLine(indent + "/// "); + argsText.AppendFormat(indent + "/// " + Environment.NewLine, controllerName); + argsText.AppendFormat(indent + "/// " + Environment.NewLine, viewName); + + argsText.AppendFormat(indent + "public class {0} : PresentArgs" + Environment.NewLine, argsName); + argsText.AppendLine(indent + "{"); + argsText.AppendLine(indent + "}"); + + if (!string.IsNullOrEmpty(_namespace)) + { + argsText.AppendLine("}"); + } + + File.WriteAllText(argsPath, argsText.ToString()); AssetDatabase.Refresh(); // Prefab. From db4910a4669d21356d8f7dfe8baed4faf9cfc3be Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 5 Jan 2020 23:09:57 +0200 Subject: [PATCH 30/34] README update --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 21943ae..05c381e 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Views are responsible for presenting content through the user interface. There s Controllers are the components that handle user interaction, work with the model. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. ### Service -Services usually contian very specialized logic, that is shared between several controllers. Services may on may not depend on Model. Neither model not views should not depend on services. Examples of services: `IFileSystem`, `IAssetFactory`, `IAudioService`. +Services usually contian very specialized logic, that is shared between several controllers. Services may on may not depend on Model. Neither model not views should depend on services. Examples of services: `IFileSystem`, `IAssetFactory`, `IAudioService`. ## Usage Install the package and import the namespace: @@ -72,7 +72,61 @@ using UnityFx.Mvc; using UnityFx.Mvc.Extensions; ``` -#### Dependency injection +### Presenters +A presenter is an object capable of presenting view controllers. It should implement `IPresenter` interface. There are `MonoBehaviour`-based presenter implementations `Presenter` and `Presenter`. A typical scenario of presenter usage is: +```csharp +presenter.Present(); +``` +The following code presents a message box and awaits its result: +```csharp +var result = await presenter.PresentAsync(); +``` +There are a lot of overloads of the `Present` method accepting additional arguments. In any case it needs a controller type specified to do the work. + +### Controllers + +Controller is any class that implements `IViewController` interface. There are several default controller implementations, like `ViewController` and `ViewController`. In most cases users should inherit new controllers from one of these. A controller constructor usually accepts at least an argument of type `IPresentContext`, which provides access to the its context (including the view). + +```csharp +public class SplashController : ViewController +{ + public SplashController(IPresentContext context) + : base(context) + { + context.Schedule(OnTimer, 5); + } + + private void OnTimer(float t) + { + Dismiss(); + } +} +``` + +### Views + +View is a class that implements `IView` interface. There is a default `MonoBehaviour`-based view implementation (`View`). It is recommended to inherit user views from this class. View is supposed to manage presentation-related logic, and send user input to its controller. Please note, that there is no explicit reference to the controller. The preffered way of sending controller notifications is calling one of `NotifyCommand` overloads (which in turn raises `INotifyCommand.Command` event). + +```csharp +public class MinimalView : View +{ + [SerializeField] + private Button _closeButton; + + public void Configure(MinimalViewArgs args) + { + _closeButton.onClick.AddListener(OnCLose); + } + + private OnClose() + { + NotifyCommand("close"); + } +} +``` + +### Dependency injection +*UnityFx.Mvc* controllers request dependencies explicitly via constructors. The framework has built-in support for dependency injection (DI). DI makes apps easier to test and maintain. Services are added as a constructor parameter, and the runtime resolves the service from the service container (via `IServiceProvider`). Services are typically defined using interfaces. ## Motivation The project was initially created to help author with his [Unity3d](https://unity3d.com) projects. Client .NET applications in general (and Unity applications specifically) do not have a standard structure or any kind of architecturing guidelines (like ASP.NET). This is an attempt to create a small yet effective and usable application framework suitable for Unity projects. From f1b6784ecea604d69b5c26f1e133203fc09536be Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 5 Jan 2020 23:15:56 +0200 Subject: [PATCH 31/34] Misc fixes --- .../Runtime/Abstractions/Presenters/PresentOptions.cs | 7 ++++--- .../Runtime/Core/Presenters/Presenter{TController}.cs | 6 +++++- .../Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs index 2d5f0c2..ef1dc66 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Abstractions/Presenters/PresentOptions.cs @@ -19,7 +19,8 @@ public enum PresentOptions None = 0, /// - /// Marks the controller as exclusive. Exclusive controllers cover all other controllers below. Cannot be combined with . + /// Marks the controller as exclusive. Exclusive controllers do not forward unprocessed commands to controllers below them is the stack + /// and it is assumed their views are full-screen. Cannot be combined with . /// Exclusive = 1, @@ -34,9 +35,9 @@ public enum PresentOptions Modal = 4, /// - /// Do not parent the controller to any other. + /// Parents the presented controller to the caller. Child controllers are dismissed with their parent controllers. /// - Detach = 0x10, + Child = 0x10, /// /// If set the caller presenter is dismissed. diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs index c73a935..171d3a7 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Presenters/Presenter{TController}.cs @@ -537,7 +537,11 @@ private IPresentable CreatePresentable(IPresentable parent, Type co } // If parent is going to be dismissed, use its parent instead. - if ((presentOptions & PresentOptions.DismissAll) != 0 || (presentOptions & PresentOptions.Detach) != 0) + if ((presentOptions & PresentOptions.Child) == 0) + { + presentContext.Parent = null; + } + else if ((presentOptions & PresentOptions.DismissAll) != 0) { presentContext.Parent = null; } diff --git a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs index 07153f5..de768c1 100644 --- a/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs +++ b/Assets/Plugins/UnityFx.Mvc/Runtime/Core/Views/UGUIViewFactory.ViewProxy.cs @@ -64,7 +64,7 @@ public IView View private void OnDestroy() { - if (_view is MonoBehaviour b && b.gameObject) + if (_view is MonoBehaviour b && b && b.gameObject) { Destroy(b.gameObject); } From 60c7c05fdcfe26c737ed695000e9dfba552482f0 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 5 Jan 2020 23:18:55 +0200 Subject: [PATCH 32/34] README update --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 05c381e..e6f5126 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ var result = await presenter.PresentAsync(); ``` There are a lot of overloads of the `Present` method accepting additional arguments. In any case it needs a controller type specified to do the work. +Presenter uses `IServiceProvider` instance to resolve controller dependencies. It also requires `IViewFactory` to create views for the controllers presented. + ### Controllers Controller is any class that implements `IViewController` interface. There are several default controller implementations, like `ViewController` and `ViewController`. In most cases users should inherit new controllers from one of these. A controller constructor usually accepts at least an argument of type `IPresentContext`, which provides access to the its context (including the view). From b923698c531b4cfc4d1d2f8172067fabf685f343 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 5 Jan 2020 23:19:08 +0200 Subject: [PATCH 33/34] Updated npm package version --- Assets/Plugins/UnityFx.Mvc/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Plugins/UnityFx.Mvc/package.json b/Assets/Plugins/UnityFx.Mvc/package.json index 7466b04..9fa9f6f 100644 --- a/Assets/Plugins/UnityFx.Mvc/package.json +++ b/Assets/Plugins/UnityFx.Mvc/package.json @@ -1,6 +1,6 @@ { "name": "com.unityfx.mvc", - "version": "0.1.0", + "version": "0.2.0", "displayName": "MVC framework for Unity.", "description": "", "unity": "2018.4", From fc758febaa2e07af3d01fa2d692d5a6f95898423 Mon Sep 17 00:00:00 2001 From: Alexander Bogarsukov Date: Sun, 5 Jan 2020 23:21:18 +0200 Subject: [PATCH 34/34] CHANGELOG update --- Assets/Plugins/UnityFx.Mvc/CHANGELOG.md | 22 +++++++++++++++++++++- CHANGELOG.md | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Assets/Plugins/UnityFx.Mvc/CHANGELOG.md b/Assets/Plugins/UnityFx.Mvc/CHANGELOG.md index 356dbf5..d0ce834 100644 --- a/Assets/Plugins/UnityFx.Mvc/CHANGELOG.md +++ b/Assets/Plugins/UnityFx.Mvc/CHANGELOG.md @@ -1,8 +1,28 @@ -# UnityFx.Mvc changelog +# UnityFx.Mvc changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.0] - 2020.01.05 + +### Added +- Added support for generic commands. +- Added view layers support (via `ViewControllerAttribute`). +- Added `IViewControllerResult` interface to tag controllers that have a result value. +- Added `IConfigurable` interfaces. +- Added message box extensions. + +### Changed +- Changed the package layout. The code is now splitted into 3 assemblies (`UnityFx.Mvc`, `UnityFx.Mvc.Abstractions` and `UnityFx.Mvc.Extensions`). +- Renamed `IPresenter.PresentAsync` to `Present`. Added a group of `PresentAsync` extension methods returning `Task` instead of `IPresentResult`. +- Renamed `IPresentResult.DismissTask` to `Task`. +- Changed `Present`/`PresentAsync` arguments. +- Changed `IViewFactory` and `IViewControllerFactory` interfaces. +- `IView` now does not inherit `IComponent`. + +### Removed +- Removed `IPresentResult.PresentTask`. + ## [0.1.0] - 2019.11.14 ### Added diff --git a/CHANGELOG.md b/CHANGELOG.md index 5684e4e..d0ce834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/). -## [0.2.0] - unreleased +## [0.2.0] - 2020.01.05 ### Added - Added support for generic commands.