Skip to content

Commit

Permalink
- Fixed double click on asset not opening graph, when window was alre…
Browse files Browse the repository at this point in the history
…ady open. [#7](#7)

- Some refactoring to opening a graph externally
  • Loading branch information
Doppelkeks committed Mar 27, 2023
1 parent 4b351de commit d406fd1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 29 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.3.0] - 2023-03-17
### Added
- Added ShouldColorizeBackground that can be overridden in NodeEditors to prevent the background from being automatically colorized
- Added ShouldColorizeBackground that can be overridden in NodeEditors to prevent the background from being automatically colorized

## [0.3.1] - 2023-03-27
### Fixed
- Fixed double click on asset not opening graph, when window was already open. [#7](https://github.com/Gentlymad-Studios/NewGraph/issues/7)
- Some refactoring to opening a graph externally
4 changes: 2 additions & 2 deletions Editor/Controllers/GraphController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ private void OnAfterGraphCreated(GraphModel graphData) {
/// </summary>
/// <param name="graphData"></param>
private void OnShouldLoadGraph(GraphModel graphData) {
inspector.CreateRenameGraphUI(graphData);
inspector.Clear();
Load(graphData);
}

Expand All @@ -400,8 +402,6 @@ private void OnShouldLoadGraph(GraphModel graphData) {
/// </summary>
/// <param name="baseGraphModel">The graph data that should get loaded.</param>
public void OpenGraphExternal(GraphModel baseGraphModel) {
inspector.CreateRenameGraphUI(baseGraphModel);
inspector.Clear();
OnShouldLoadGraph(baseGraphModel);
}

Expand Down
3 changes: 1 addition & 2 deletions Editor/Views/GraphModelEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ private void OpenGraphClicked() {
}

private static void OpenGraph(GraphModel graphModel) {
GraphSettings.LastOpenedGraphModel = graphModel;
GraphWindow.Initialize();
GraphWindow.LoadGraph(graphModel);
}

[OnOpenAsset]
Expand Down
62 changes: 39 additions & 23 deletions Editor/Views/GraphWindow.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
Expand All @@ -15,15 +16,31 @@ public class GraphWindow : EditorWindow {
private EventType eventType;
private GraphController graphController;
private PlayModeStateChange lastState;
private static GraphWindow window;

public static event System.Action<Event> OnGlobalKeyDown;

[NonSerialized]
private static GraphWindow window = null;
[NonSerialized]
private static bool loadRequested = false;

private static GraphWindow Window {
get {
CacheWindow();
return window;
}
}
private static void CacheWindow() {
if (window == null) {
window = GetWindow<GraphWindow>(nameof(GraphWindow));
window.wantsMouseMove = true;
window.Show();
}
}

[MenuItem(GraphSettings.menuItemBase+nameof(GraphWindow))]
public static void Initialize() {
window = GetWindow<GraphWindow>(nameof(GraphWindow));
window.wantsMouseMove= true;
window.Show();
private static void Initialize() {
CacheWindow();
}

private void OnEnable() {
Expand Down Expand Up @@ -63,22 +80,18 @@ private void OnDisable() {
graphController?.Disable();
GlobalKeyEventHandler.OnKeyEvent -= HandleGlobalKeyPressEvents;
EditorApplication.playModeStateChanged -= LogPlayModeState;
}

public static Vector2 screenPosition {
get {
if (window == null) {
Initialize();
}
return window.position.position;
}
loadRequested = false;
}

public static void Redraw() {
if (window == null) {
Initialize();
public static void LoadGraph(GraphModel graph=null) {
if (graph != null) {
GraphSettings.LastOpenedGraphModel = graph;
} else {
graph = GraphSettings.LastOpenedGraphModel;
}
window.Repaint();

Window.graphController.OpenGraphExternal(graph);
loadRequested = true;
}

private void CreateGUI() {
Expand All @@ -95,11 +108,14 @@ private void CreateGUI() {
rootVisualElement.styleSheets.Add(Settings.customStylesheet);
}

// re-open the last opened graph
GraphModel lastLoadedGraph = GraphSettings.LastOpenedGraphModel;
if (lastLoadedGraph != null) {
graphController.OpenGraphExternal(lastLoadedGraph);
}
// delay loading the last graph to the next frame
// otherwise this method will be called before loadRequested could be set
rootVisualElement.schedule.Execute(() =>{
if (!loadRequested) {
LoadGraph();
}
loadRequested = false;
});

}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.gentlymad.newgraph",
"version": "0.3.0",
"version": "0.3.1",
"displayName": "NewGraph",
"description": "A general data oriented node graph solution. This is build upon the idea to visualize complex data structures as graph networks without having to modify already established data classes, except adding [Node], [Port] and [SerializeReference] attributes to call classes that should show in the Graph View.",
"unity": "2022.2",
Expand Down

0 comments on commit d406fd1

Please sign in to comment.