public void OnDisable() { Destroy(_current?.gameObject); _current = null; if (_uiRefreshCoroutine != null) { StopCoroutine(_uiRefreshCoroutine); } _uiRefreshInProgress = false; _uiRefreshInvalidated = false; _uiRefreshScheduled = false; }
public void Disable() { _current?.Dispose(); _current = null; _currentScreen = null; }
private IEnumerator RefreshCurrentUIDeferred(string screen) { // Let every event trigger a UI refresh yield return(0); _uiRefreshScheduled = false; // Cannot proceed if (_plugin == null || _plugin.animation == null || _plugin.animation.Current == null) { yield break; } // Same UI, just refresh if (_current != null && _current.name == screen) { yield break; } // UI Change _uiRefreshInProgress = true; // Dispose previous if (_current != null) { try { _current.Dispose(); } catch (Exception exc) { SuperController.LogError($"VamTimeline.{nameof(ScreensManager)}.{nameof(RefreshCurrentUIDeferred)} (while removing {_current.name}): {exc}"); } _current = null; } yield return(0); // Create new screen switch (screen) { case SettingsScreen.ScreenName: _current = new SettingsScreen(_plugin); break; case TargetsScreen.ScreenName: _current = new TargetsScreen(_plugin); break; case EditScreen.ScreenName: _current = new EditScreen(_plugin); break; case BulkScreen.ScreenName: _current = new BulkScreen(_plugin); break; case AdvancedScreen.ScreenName: _current = new AdvancedScreen(_plugin); break; case MocapScreen.ScreenName: _current = new MocapScreen(_plugin); break; case MoreScreen.ScreenName: _current = new MoreScreen(_plugin); break; case EditAnimationScreen.ScreenName: _current = new EditAnimationScreen(_plugin); break; case EditSequenceScreen.ScreenName: _current = new EditSequenceScreen(_plugin); break; case AddAnimationScreen.ScreenName: _current = new AddAnimationScreen(_plugin); break; case ManageAnimationsScreen.ScreenName: _current = new ManageAnimationsScreen(_plugin); break; case PerformanceScreen.ScreenName: _current = new PerformanceScreen(_plugin); break; case HelpScreen.ScreenName: _current = new HelpScreen(_plugin); break; default: throw new InvalidOperationException($"Unknown screen {screen}"); } try { _current.onScreenChangeRequested.AddListener(ChangeScreen); _current.Init(); } catch (Exception exc) { SuperController.LogError($"VamTimeline.{nameof(ScreensManager)}.{nameof(RefreshCurrentUIDeferred)} (while initializing {_current.name}): {exc}"); } yield return(0); _uiRefreshInProgress = false; if (_uiRefreshInvalidated) { _uiRefreshInvalidated = false; _uiRefreshScheduled = true; _plugin.StartCoroutine(RefreshCurrentUIDeferred(_currentScreen)); } if (_animationUI.popup.visible) { // Fix for when the popup is open, it becomes hidden by newer components _animationUI.popup.visible = false; } }
private IEnumerator RefreshCurrentUIDeferred(string screen) { // Let every event trigger a UI refresh yield return(0); _uiRefreshScheduled = false; // Cannot proceed if (_plugin == null || _plugin.animation == null || _plugin.animationEditContext.current == null) { yield break; } // Same UI, just refresh if (_current != null && _current.screenId == screen) { _uiRefreshCoroutine = null; yield break; } // UI Change _uiRefreshInProgress = true; // Dispose previous if (_current != null) { try { Destroy(_current.gameObject); } catch (Exception exc) { SuperController.LogError($"Timeline.{nameof(ScreensManager)}.{nameof(RefreshCurrentUIDeferred)} (while removing {_current.screenId}): {exc}"); } _current = null; } yield return(0); var screenContainer = CreateScreenContainer(); switch (screen) { case OptionsScreen.ScreenName: _current = screenContainer.AddComponent <OptionsScreen>(); break; case AddRemoveTargetsScreen.ScreenName: _current = screenContainer.AddComponent <AddRemoveTargetsScreen>(); break; case TargetsScreen.ScreenName: _current = screenContainer.AddComponent <TargetsScreen>(); break; case AnimationsScreen.ScreenName: _current = screenContainer.AddComponent <AnimationsScreen>(); break; case BulkScreen.ScreenName: _current = screenContainer.AddComponent <BulkScreen>(); break; case AdvancedKeyframeToolsScreen.ScreenName: _current = screenContainer.AddComponent <AdvancedKeyframeToolsScreen>(); break; case MocapScreen.ScreenName: _current = screenContainer.AddComponent <MocapScreen>(); break; case RecordScreen.ScreenName: _current = screenContainer.AddComponent <RecordScreen>(); break; case ReduceScreen.ScreenName: _current = screenContainer.AddComponent <ReduceScreen>(); break; case MoreScreen.ScreenName: _current = screenContainer.AddComponent <MoreScreen>(); break; case ImportExportScreen.ScreenName: _current = screenContainer.AddComponent <ImportExportScreen>(); break; case EditAnimationScreen.ScreenName: _current = screenContainer.AddComponent <EditAnimationScreen>(); break; case SequencingScreen.ScreenName: _current = screenContainer.AddComponent <SequencingScreen>(); break; case AddAnimationScreen.ScreenName: _current = screenContainer.AddComponent <AddAnimationScreen>(); break; case ManageAnimationsScreen.ScreenName: _current = screenContainer.AddComponent <ManageAnimationsScreen>(); break; case LockedScreen.ScreenName: _current = screenContainer.AddComponent <LockedScreen>(); break; case DiagnosticsScreen.ScreenName: _current = screenContainer.AddComponent <DiagnosticsScreen>(); break; case HelpScreen.ScreenName: _current = screenContainer.AddComponent <HelpScreen>(); break; case ControllerTargetSettingsScreen.ScreenName: _current = screenContainer.AddComponent <ControllerTargetSettingsScreen>(); break; default: throw new InvalidOperationException($"Unknown screen {screen}"); } try { _current.transform.SetParent(transform, false); _current.popupParent = popupParent; _current.onScreenChangeRequested.AddListener(ChangeScreen); _current.Init(_plugin, _currentScreenArg); onScreenChanged.Invoke(new ScreenChangedEventArgs { screenName = _current.screenId, screenArg = _currentScreenArg }); } catch (Exception exc) { SuperController.LogError($"Timeline.{nameof(ScreensManager)}.{nameof(RefreshCurrentUIDeferred)} (while initializing {_current.screenId}): {exc}"); } yield return(0); _uiRefreshInProgress = false; _uiRefreshCoroutine = null; if (_uiRefreshInvalidated) { _uiRefreshInvalidated = false; _uiRefreshScheduled = true; _uiRefreshCoroutine = StartCoroutine(RefreshCurrentUIDeferred(_currentScreen)); } }