public NavigationService(EventSystem eventSystem) { _eventSystem = eventSystem; if (Instance != null) { throw new InvalidOperationException("NavigationService should only be instantiated once."); } Instance = this; // Ensure to synch Selection property with actual selected object // just in case the NavigationService was by-passed for changing // selection (should not happen if we refactor everything properly). Observable .EveryUpdate() .Select(_ => eventSystem.currentSelectedGameObject) .DistinctUntilChanged() .Subscribe(SetSelection) .AddTo(_disposables); Selection .PairWithPrevious() .Subscribe(OnSelectionChanged); if (Log.IsDebugEnabled) { SelectionAndAncestors.Subscribe(x => Debug.Log($"Selection: {x.JoinAsString(" > ")}")); } }
public void Dispose() { Selection.Dispose(); SelectionAndAncestors.Dispose(); _disposables.Dispose(); }