Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): events not resubscribed once unloaded #448

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Editor/Configurator/Presenters/OneConfCabinetPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,19 @@ public OneConfCabinetPresenter(IOneConfCabinetView view, GameObject avatarGameOb
_view = view;
_avatarGameObject = avatarGameObject;

SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.SettingsChanged += OnSettingsChanged;
_view.ForceUpdateView += OnForceUpdateView;
}

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.SettingsChanged -= OnSettingsChanged;
_view.ForceUpdateView -= OnForceUpdateView;
}
Expand Down Expand Up @@ -125,6 +121,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
7 changes: 2 additions & 5 deletions Editor/Inspector/Presenters/AnimatorParametersPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ public AnimatorParametersPresenter(IAnimatorParametersView view)
{
_view = view;
_parameters = new Dictionary<string, AnimatorControllerParameterType>();
SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.AddConfig += OnAddConfig;
_view.RemoveConfig += OnRemoveConfig;
_view.ChangeConfig += OnChangeConfig;
Expand All @@ -52,9 +50,7 @@ private void SubscribeEvents()

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.AddConfig -= OnAddConfig;
_view.RemoveConfig -= OnRemoveConfig;
_view.ChangeConfig -= OnChangeConfig;
Expand Down Expand Up @@ -194,6 +190,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
8 changes: 2 additions & 6 deletions Editor/Inspector/Presenters/GroupDynamicsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ internal class GroupDynamicsPresenter
public GroupDynamicsPresenter(IGroupDynamicsView view)
{
_view = view;

SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.ConfigChange += OnConfigChange;
_view.AddInclude += OnAddInclude;
_view.AddExclude += OnAddExclude;
Expand All @@ -44,9 +41,7 @@ private void SubscribeEvents()

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.ConfigChange -= OnConfigChange;
_view.AddInclude -= OnAddInclude;
_view.AddExclude -= OnAddExclude;
Expand Down Expand Up @@ -107,6 +102,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
7 changes: 2 additions & 5 deletions Editor/Inspector/Presenters/MenuGroupPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ internal class MenuGroupPresenter
public MenuGroupPresenter(IMenuGroupView view)
{
_view = view;
SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.AddItem += OnAddItem;
_view.AddSmartControl += OnAddSmartControl;
_view.RemoveItem += OnRemoveItem;
Expand All @@ -44,9 +42,7 @@ private void SubscribeEvents()

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.AddItem -= OnAddItem;
_view.AddSmartControl -= OnAddSmartControl;
_view.RemoveItem -= OnRemoveItem;
Expand Down Expand Up @@ -100,6 +96,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
6 changes: 2 additions & 4 deletions Editor/Inspector/Presenters/MenuInstallPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ internal class MenuInstallPresenter
public MenuInstallPresenter(IMenuInstallView view)
{
_view = view;
SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.SettingsChanged += OnSettingsChanged;

EditorApplication.hierarchyChanged += OnHierarchyChange;
}

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;
_view.SettingsChanged -= OnSettingsChanged;

Expand Down Expand Up @@ -78,6 +75,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
5 changes: 2 additions & 3 deletions Editor/Inspector/Presenters/MenuItemPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ internal class MenuItemPresenter
public MenuItemPresenter(IMenuItemView view)
{
_view = view;
SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.NameChanged += OnNameChanged;
Expand All @@ -55,7 +54,6 @@ private void SubscribeEvents()

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.NameChanged -= OnNameChanged;
Expand Down Expand Up @@ -297,6 +295,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
7 changes: 2 additions & 5 deletions Editor/Inspector/Presenters/ParameterSlotPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ internal class ParameterSlotPresenter
public ParameterSlotPresenter(IParameterSlotView view)
{
_view = view;
SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.ConfigChanged += OnConfigChanged;
_view.AddMapping += OnAddMapping;

Expand All @@ -44,9 +42,7 @@ private void SubscribeEvents()

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.ConfigChanged -= OnConfigChanged;
_view.AddMapping -= OnAddMapping;

Expand Down Expand Up @@ -171,6 +167,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
5 changes: 2 additions & 3 deletions Editor/Inspector/Presenters/SmartControlPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ internal class SmartControlPresenter
public SmartControlPresenter(ISmartControlView view)
{
_view = view;
SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.DriverChanged += OnDriverChanged;
Expand Down Expand Up @@ -64,7 +63,6 @@ private void SubscribeEvents()

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.DriverChanged -= OnDriverChanged;
Expand Down Expand Up @@ -499,6 +497,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ public SmartControlPropertyGroupComponentPresenter(ISmartControlPropertyGroupCom
_blendshapes = new Dictionary<string, Tuple<Type, object>>();
_materialProperties = new Dictionary<string, Tuple<Type, object>>();
_genericProperties = new Dictionary<string, Tuple<Type, object>>();
SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.SearchResultModeChange += OnSearchResultModeChange;
_view.SearchQueryChange += OnSearchQueryChange;
_view.AddProperty += OnAddProperty;
Expand All @@ -57,9 +55,7 @@ private void SubscribeEvents()

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.SearchResultModeChange -= OnSearchResultModeChange;
_view.SearchQueryChange -= OnSearchQueryChange;
_view.AddProperty -= OnAddProperty;
Expand Down Expand Up @@ -686,6 +682,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
SearchComponentProperties();
UpdateView();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ internal class SmartControlPropertyGroupPresenter
public SmartControlPropertyGroupPresenter(ISmartControlPropertyGroupView view)
{
_view = view;
SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.SettingsChanged += OnSettingsChanged;
_view.AddGameObject += OnAddGameObject;
_view.RemoveGameObject += OnRemoveGameObject;
Expand All @@ -42,9 +40,7 @@ private void SubscribeEvents()

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.SettingsChanged -= OnSettingsChanged;
_view.AddGameObject -= OnAddGameObject;
_view.RemoveGameObject -= OnRemoveGameObject;
Expand Down Expand Up @@ -136,6 +132,7 @@ private void SuggestPickFromTransform(bool mustSet = false)

private void OnLoad()
{
SubscribeEvents();
UpdateView();

SuggestPickFromTransform(true);
Expand Down
2 changes: 1 addition & 1 deletion Editor/Inspector/Views/AnimatorParametersView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void InitVisualTree()
_helpBoxContainer.Add(CreateHelpBox(t._("inspector.animParams.helpbox.description"), MessageType.Info));
_configsContainer = Q<VisualElement>("configs-container");
var addConfigBtn = Q<Button>("add-config-btn");
addConfigBtn.clicked += AddConfig;
addConfigBtn.clicked += () => AddConfig?.Invoke();
}

private Box MakeConfigBox(int idx, AnimatorParametersConfig config)
Expand Down
4 changes: 2 additions & 2 deletions Editor/Inspector/Views/MenuGroupView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ private void InitVisualTree()
_itemsContainer = Q<VisualElement>("items-container");

_addItemBtn = Q<Button>("add-item-btn");
_addItemBtn.clicked += AddItem;
_addItemBtn.clicked += () => AddItem?.Invoke();

_addSmartControlBtn = Q<Button>("add-smart-control-btn");
_addSmartControlBtn.clicked += AddSmartControl;
_addSmartControlBtn.clicked += () => AddSmartControl?.Invoke();
}

private Box MakeMenuItemBox<T>(int i, T comp) where T : Component
Expand Down
2 changes: 1 addition & 1 deletion Editor/Inspector/Views/SmartControlView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ private void InitPropertyGroupsFoldout()

_propGpsListContainer = Q<VisualElement>("prop-gps-list-container");
_propGpAddBtn = Q<Button>("prop-gp-add-btn");
_propGpAddBtn.clicked += AddNewPropertyGroup;
_propGpAddBtn.clicked += () => AddNewPropertyGroup?.Invoke();
}

private void InitCrossCtrlValuesFoldout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,19 @@ public VRCMergeAnimLayerWearableModuleEditorPresenter(IVRCMergeAnimLayerWearable
_view = view;
_parentView = parentView;
_module = module;

SubscribeEvents();
_view.Load += OnLoad;
}

private void SubscribeEvents()
{
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.ForceUpdateView += OnForceUpdateView;
_view.ConfigChange += OnConfigChange;
}

private void UnsubscribeEvents()
{
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.ForceUpdateView -= OnForceUpdateView;
_view.ConfigChange -= OnConfigChange;
}
Expand Down Expand Up @@ -166,6 +161,7 @@ private void UpdateView()

private void OnLoad()
{
SubscribeEvents();
UpdateView();
}

Expand Down
Loading
Loading