void Log(string message) { if (m_Preferences.GetBool(VSPreferences.BoolPref.DependenciesLogging)) { Debug.Log(message); } }
public override void Dispatch <TAction>(TAction action) { VSPreferences vsPreferences = GetState().Preferences; if (vsPreferences != null && vsPreferences.GetBool(VSPreferences.BoolPref.LogAllDispatchedActions)) { Debug.Log(action); } int currentFrame = GetState()?.EditorDataModel == null ? -1 : GetState().EditorDataModel.UpdateCounter; if (vsPreferences != null && currentFrame == m_LastActionFrame && vsPreferences.GetBool(VSPreferences.BoolPref.ErrorOnMultipleDispatchesPerFrame)) { // TODO: Specific case for a non-model specific action, possibly triggered by a callback that is unaware of the store's current state; // About RefreshUIAction: maybe this is not a good idea to update the UI via an action, as it has nothing // to do with the model. Problem is, currently, the Store reacts on state changes and is responsible // of updating the UI accordingly. This UI update loop could be moved elsewhere and detach itself // from the editor model. Same goes for PanToNode action. if (!(action is RefreshUIAction || action is PanToNodeAction)) { Debug.LogError($"Multiple actions dispatched during the same frame (previous one was {m_LastActionThisFrame.GetType().Name}), current: {action.GetType().Name}"); } } m_LastActionFrame = currentFrame; m_LastActionThisFrame = action; if (vsPreferences != null && m_CurrentAction != null && vsPreferences.GetBool(VSPreferences.BoolPref.ErrorOnRecursiveDispatch)) { // TODO: Same check here, see comments above if (!(action is RefreshUIAction)) { Debug.LogError($"Recursive dispatch detected: action {action.GetType().Name} dispatched during {m_CurrentAction.GetType().Name}'s dispatch"); } } m_CurrentAction = action; try { base.Dispatch(action); } finally { m_CurrentAction = null; } }
void OnOptionsButton() { GenericMenu menu = new GenericMenu(); VSGraphModel vsGraphModel = (VSGraphModel)m_Store.GetState().CurrentGraphModel; VSPreferences pref = m_Store.GetState().Preferences; void MenuItem(string title, bool value, GenericMenu.MenuFunction onToggle) => menu.AddItem(VseUtility.CreatTextContent(title), value, onToggle); void MenuToggle(string title, BoolPref k, Action callback = null) => MenuItem(title, pref.GetBool(k), () => { pref.ToggleBool(k); callback?.Invoke(); }); void MenuMapToggle(string title, Func <bool> match, GenericMenu.MenuFunction onToggle) => MenuItem(title, match(), onToggle); void MenuItemDisable(string title, bool value, GenericMenu.MenuFunction onToggle, Func <bool> shouldDisable) { if (shouldDisable()) { menu.AddDisabledItem(VseUtility.CreatTextContent(title)); } else { menu.AddItem(VseUtility.CreatTextContent(title), value, onToggle); } } MenuItem("Build All", false, AssetDatabase.SaveAssets); MenuItemDisable("Compile", false, () => { m_Store.GetState().EditorDataModel.RequestCompilation(RequestCompilationOptions.SaveGraph); }, () => (vsGraphModel == null || !vsGraphModel.Stencil.CreateTranslator().SupportsCompilation())); MenuItem("Auto-itemize/Variables", pref.CurrentItemizeOptions.HasFlag(ItemizeOptions.Variables), () => pref.ToggleItemizeOption(ItemizeOptions.Variables)); MenuItem("Auto-itemize/System Constants", pref.CurrentItemizeOptions.HasFlag(ItemizeOptions.SystemConstants), () => pref.ToggleItemizeOption(ItemizeOptions.SystemConstants)); MenuItem("Auto-itemize/Constants", pref.CurrentItemizeOptions.HasFlag(ItemizeOptions.Constants), () => pref.ToggleItemizeOption(ItemizeOptions.Constants)); MenuToggle("Show unused nodes", BoolPref.ShowUnusedNodes, () => m_Store.Dispatch(new RefreshUIAction(UpdateFlags.All))); if (Unsupported.IsDeveloperMode()) { MenuItem("Log compile time stats", LogCompileTimeStats, () => LogCompileTimeStats = !LogCompileTimeStats); MenuItem("Rebuild UI", false, () => { m_Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); }); MenuItem("Rebuild Blackboard", false, () => { m_GraphView.UIController.Blackboard?.Rebuild(Blackboard.RebuildMode.BlackboardOnly); }); menu.AddSeparator(""); MenuItem("Reload and Rebuild UI", false, () => { if (m_Store.GetState()?.CurrentGraphModel != null) { var path = m_Store.GetState().CurrentGraphModel.GetAssetPath(); Selection.activeObject = null; Resources.UnloadAsset((Object)m_Store.GetState().CurrentGraphModel.AssetModel); Resources.UnloadAsset((Object)m_Store.GetState().CurrentGraphModel); m_Store.Dispatch(new LoadGraphAssetAction(path)); } }); MenuItem("Layout", false, () => { m_GraphView.FrameAll(); m_Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); }); menu.AddSeparator(""); MenuItem("Clear Searcher Databases", false, () => { var provider = m_Store.GetState().CurrentGraphModel.Stencil.GetSearcherDatabaseProvider(); provider.ClearTypesItemsSearcherDatabases(); provider.ClearTypeMembersSearcherDatabases(); provider.ClearGraphElementsSearcherDatabases(); provider.ClearGraphVariablesSearcherDatabases(); provider.ClearReferenceItemsSearcherDatabases(); }); MenuItem("Integrity Check", false, () => vsGraphModel.CheckIntegrity(GraphModel.Verbosity.Verbose)); MenuItem("Graph cleanup", false, () => { vsGraphModel.QuickCleanup(); vsGraphModel.CheckIntegrity(GraphModel.Verbosity.Verbose); }); MenuItem("Fix and reimport all textures", false, OnFixAndReimportTextures); MenuToggle("Auto compilation when idle", BoolPref.AutoRecompile); MenuToggle("Auto align new dragged edges", BoolPref.AutoAlignDraggedEdges); if (Unsupported.IsDeveloperMode()) { MenuToggle("Bound object logging", BoolPref.BoundObjectLogging); MenuToggle("Dependencies logging", BoolPref.DependenciesLogging); MenuToggle("UI Performance/Always fully rebuild UI on change", BoolPref.FullUIRebuildOnChange); MenuToggle("UI Performance/Warn when UI gets fully rebuilt", BoolPref.WarnOnUIFullRebuild); MenuToggle("UI Performance/Log UI build time", BoolPref.LogUIBuildTime); if (DebugDisplayElement.Allowed) { MenuItem("Show Debug", m_GraphView.ShowDebug, () => m_GraphView.ShowDebug = !m_GraphView.ShowDebug); } MenuToggle("Diagnostics/Log Recursive Action Dispatch", BoolPref.ErrorOnRecursiveDispatch); MenuToggle("Diagnostics/Log Multiple Actions Dispatch", BoolPref.ErrorOnMultipleDispatchesPerFrame); MenuToggle("Diagnostics/Log All Dispatched Actions", BoolPref.LogAllDispatchedActions); MenuItem("Spawn all node types in graph", false, () => { VSGraphModel graph = (VSGraphModel)m_Store.GetState().CurrentGraphModel; Stencil stencil = graph.Stencil; Vector2 nextPosition = Vector2.zero; Vector2 spaceBetween = new Vector2(300, 0); foreach (var node in stencil.SpawnAllNodes(graph)) { node.Position += nextPosition; nextPosition += spaceBetween; } }); } var compilationResult = m_Store.GetState()?.CompilationResultModel?.GetLastResult(); if (compilationResult != null) { foreach (var pluginType in compilationResult.pluginSourceCode.Keys) { MenuMapToggle(title: "CodeViewer/Plugin/" + pluginType.Name, match: () => pref.PluginTypePref == pluginType, onToggle: () => { VseUtility.UpdateCodeViewer(show: true, pluginIndex: pluginType, compilationResult: compilationResult, selectionDelegate: lineMetadata => { if (lineMetadata == null) { return; } GUID nodeGuid = (GUID)lineMetadata; m_Store.Dispatch(new PanToNodeAction(nodeGuid)); }); pref.PluginTypePref = pluginType; }); } } } menu.ShowAsContext(); }