From 45090c03bb45ebf62ea6bdbcf0eb2ecc4c222518 Mon Sep 17 00:00:00 2001 From: poi-vrc <77053052+poi-vrc@users.noreply.github.com> Date: Mon, 30 Dec 2024 01:40:07 +0800 Subject: [PATCH] fix: avatar selection change event bug causing null ref --- Editor/UI/Presenters/MainPresenter.cs | 4 ++-- Editor/UI/Views/IMainView.cs | 3 ++- Editor/UI/Views/MainView.cs | 11 ++++++----- Editor/UI/Views/OneConfDressSubView.cs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Editor/UI/Presenters/MainPresenter.cs b/Editor/UI/Presenters/MainPresenter.cs index 8f9ca07c..e2e293a1 100644 --- a/Editor/UI/Presenters/MainPresenter.cs +++ b/Editor/UI/Presenters/MainPresenter.cs @@ -143,9 +143,9 @@ private void UpdateView() _view.SelectedAvatarIndex = 0; } - if (oldIndex != _view.SelectedAvatarIndex) + if (oldIndex != -1 && oldIndex != _view.SelectedAvatarIndex) { - _view.RaiseAvatarSelectionPopupChangeEvent(); + _view.RaiseAvatarSelectionChangeEvent(); } _view.ToolVersionText = UpdateChecker.CurrentVersion?.fullString; diff --git a/Editor/UI/Views/IMainView.cs b/Editor/UI/Views/IMainView.cs index ba118678..f894dcf7 100644 --- a/Editor/UI/Views/IMainView.cs +++ b/Editor/UI/Views/IMainView.cs @@ -36,6 +36,7 @@ internal interface IMainView : IEditorView event Action PrefabStageClosing; event Action PrefabStageOpened; event Action AvatarSelectionPopupChange; + event Action AvatarSelectionChange; string UpdateAvailableFromVersion { get; set; } string UpdateAvailableToVersion { get; set; } @@ -50,6 +51,6 @@ internal interface IMainView : IEditorView void ForceUpdateCabinetSubView(); void StartDressing(GameObject outfitGameObject = null, GameObject avatarGameObject = null); void OpenUrl(string url); - void RaiseAvatarSelectionPopupChangeEvent(); + void RaiseAvatarSelectionChangeEvent(); } } diff --git a/Editor/UI/Views/MainView.cs b/Editor/UI/Views/MainView.cs index 8e770dbd..1f7ab37a 100644 --- a/Editor/UI/Views/MainView.cs +++ b/Editor/UI/Views/MainView.cs @@ -45,6 +45,7 @@ internal class MainView : ElementView, IMainView public event Action UpdateAvailableUpdateButtonClick; public event Action MouseMove; public event Action AvatarSelectionPopupChange; + public event Action AvatarSelectionChange; public int SelectedAvatarIndex { get; set; } public List AvailableAvatars { get; set; } @@ -94,8 +95,8 @@ public MainView() UpdateAvailableFromVersion = null; UpdateAvailableToVersion = null; ShowExitPlayModeHelpbox = false; - SelectedAvatarIndex = 0; - _lastSelectedAvatarIndex = 0; + SelectedAvatarIndex = -1; + _lastSelectedAvatarIndex = -1; AvailableAvatars = new List(); } @@ -272,11 +273,11 @@ private void RepaintAvatarSelection() _avatarSelectionPopupContainer.Add(_avatarSelectionPopup); // force update avatar subview if the selected index has changed - if (_lastSelectedAvatarIndex != SelectedAvatarIndex) + if (_lastSelectedAvatarIndex != -1 && _lastSelectedAvatarIndex != SelectedAvatarIndex) { - _lastSelectedAvatarIndex = SelectedAvatarIndex; _avatarSubView.RaiseForceUpdateViewEvent(); } + _lastSelectedAvatarIndex = SelectedAvatarIndex; } private void RepaintDebugInfo() @@ -294,6 +295,6 @@ public override void Repaint() RepaintDebugInfo(); } - public void RaiseAvatarSelectionPopupChangeEvent() => AvatarSelectionPopupChange?.Invoke(); + public void RaiseAvatarSelectionChangeEvent() => AvatarSelectionChange?.Invoke(); } } diff --git a/Editor/UI/Views/OneConfDressSubView.cs b/Editor/UI/Views/OneConfDressSubView.cs index 13ae9c43..9ffa10a2 100644 --- a/Editor/UI/Views/OneConfDressSubView.cs +++ b/Editor/UI/Views/OneConfDressSubView.cs @@ -34,7 +34,7 @@ internal class OneConfDressSubView : ElementView, IOneConfDressSubView, IOneConf { private static readonly I18nTranslator t = I18n.ToolTranslator; - public event Action TargetAvatarChange { add => _mainView.AvatarSelectionPopupChange += value; remove => _mainView.AvatarSelectionPopupChange -= value; } + public event Action TargetAvatarChange { add => _mainView.AvatarSelectionChange += value; remove => _mainView.AvatarSelectionChange -= value; } public event Action TargetWearableChange; public event Action AddToCabinetButtonClick; public GameObject TargetAvatar { get => _mainView.SelectedAvatarGameObject; }