diff --git a/Runtime/Binding/Tooltips/Manipulator/TooltipManipulator.cs b/Runtime/Binding/Tooltips/Manipulator/TooltipManipulator.cs index 593760a..81b18f9 100644 --- a/Runtime/Binding/Tooltips/Manipulator/TooltipManipulator.cs +++ b/Runtime/Binding/Tooltips/Manipulator/TooltipManipulator.cs @@ -64,19 +64,19 @@ private void OnPointerEnter(PointerEnterEvent evt) private CancellationTokenSource _cts; - private float timeTillShow; + private float _timeTillShow; private void ResetTime() { - timeTillShow = MVVMTKSettings.Instance.tooltipHoverTime / 1000f; + _timeTillShow = MVVMTKSettings.Instance.tooltipHoverTime / 1000f; } private async UniTask ShowTooltipAsync(CancellationToken ct) { - while (timeTillShow > 0) + while (_timeTillShow > 0) { if (ct.IsCancellationRequested) return; - timeTillShow -= Time.deltaTime; + _timeTillShow -= Time.deltaTime; await UniTask.Yield(); } diff --git a/Runtime/Common/UIRoot.cs b/Runtime/Common/UIRoot.cs index 6355f7e..7e62ad2 100644 --- a/Runtime/Common/UIRoot.cs +++ b/Runtime/Common/UIRoot.cs @@ -6,13 +6,15 @@ using UnityEngine; using UnityEngine.Localization; using UnityEngine.Localization.Settings; +using UnityEngine.Serialization; using UnityEngine.UIElements; namespace MVVMToolkit { public class UIRoot : MonoBehaviour { - [SerializeField] private UIDocument uiDocument; + [FormerlySerializedAs("uiDocument")] [SerializeField] + private UIDocument _initialDocument; private UIDocument _uiDocument; @@ -23,7 +25,9 @@ public UIDocument UIDocument { if (_uiDocument != value) { + // ReSharper disable once Unity.NoNullPropagation value?.rootVisualElement.Add(Root); +// ReSharper disable once Unity.NoNullPropagation _uiDocument?.rootVisualElement.Remove(Root); _uiDocument = value; } @@ -35,7 +39,6 @@ public UIDocument UIDocument private readonly List _views = new(); private readonly List _viewModels = new(); private ServiceProvider _serviceProvider; - private StrongReferenceMessenger _messenger; public const string RootUssClassName = "mvvmtk-root"; @@ -44,13 +47,12 @@ public async UniTask Initialize(StrongReferenceMessenger messenger, ServiceProvi { if (Root is not null) throw new InvalidOperationException("Cannot initialize UIRoot multiple times"); - _messenger = messenger; _serviceProvider = serviceProvider; Root = new(); Root.AddToClassList(RootUssClassName); Root.pickingMode = PickingMode.Ignore; - UIDocument = uiDocument; + UIDocument = _initialDocument; GetComponentsInChildren(_viewModels); foreach (var viewModel in _viewModels) diff --git a/Runtime/Common/View/BaseView.cs b/Runtime/Common/View/BaseView.cs index a0ca41a..f8dd0db 100644 --- a/Runtime/Common/View/BaseView.cs +++ b/Runtime/Common/View/BaseView.cs @@ -19,13 +19,13 @@ public class BaseView : UIObject, IRecipient private LocalizedStringTable[] _localizationStringTables; public LocalizedStringTable[] LocalizedStringTables => _localizationStringTables; - [SerializeField] private VisualTreeAsset asset; - protected VisualTreeAsset Asset => asset; - [SerializeField] private int sortLayer; - public int SortLayer => sortLayer; + [FormerlySerializedAs("asset")] [SerializeField] private VisualTreeAsset _asset; + protected VisualTreeAsset Asset => _asset; + [FormerlySerializedAs("sortLayer")] [SerializeField] private int _sortLayer; + public int SortLayer => _sortLayer; - [SerializeField] private ViewModel bindingContext; - protected ViewModel BindingContext => bindingContext; + [FormerlySerializedAs("bindingContext")] [SerializeField] private ViewModel _bindingContext; + protected ViewModel BindingContext => _bindingContext; protected BindingParser BindingParser { get; set; } public VisualElement RootVisualElement { get; private set; } @@ -35,7 +35,7 @@ public class BaseView : UIObject, IRecipient protected VisualElement InstantiateAsset() { - var root = asset.Instantiate(); + var root = _asset.Instantiate(); root.pickingMode = PickingMode.Ignore; root.name = gameObject.name; return root; diff --git a/Runtime/Common/View/EmbeddedView.cs b/Runtime/Common/View/EmbeddedView.cs index a985af5..bc3c1ad 100644 --- a/Runtime/Common/View/EmbeddedView.cs +++ b/Runtime/Common/View/EmbeddedView.cs @@ -1,14 +1,17 @@ using UnityEngine; +using UnityEngine.Serialization; using UnityEngine.UIElements; namespace MVVMToolkit { public class EmbeddedView : BaseView { + [FormerlySerializedAs("containerName")] [SerializeField, Tooltip("ContainerName will be used to query proper container in parent's RootVisualElement")] - private string containerName; + private string _containerName; - [SerializeField] private BaseView parent; + [FormerlySerializedAs("parent")] [SerializeField] + private BaseView _parent; public const string EmbeddedRootUssClassName = "mvvmtk-root-view-embedded"; @@ -21,11 +24,11 @@ protected override VisualElement Instantiate() public override VisualElement ResolveParent() { - var container = parent.RootVisualElement.Q(containerName); + var container = _parent.RootVisualElement.Q(_containerName); if (container is null) { throw new( - $"No VisualElement with name: {containerName} was found in hierarchy instantiated from {parent.name}."); + $"No VisualElement with name: {_containerName} was found in hierarchy instantiated from {_parent.name}."); } return container;