Skip to content

Commit

Permalink
- Fixed issue with undoing changes
Browse files Browse the repository at this point in the history
- Fixed port list connections not regenerating when adding a new item
  • Loading branch information
Doppelkeks committed Apr 26, 2023
1 parent 7b902ed commit ebe7d3e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.3.5] - 2023-04-25
### Fixed
- Made it easier to derive custom ScriptableGraph models
- Made it easier to derive custom ScriptableGraph models

## [0.3.6] - 2023-04-28
### Fixed
- Fixed issue with undoing changes
- Fixed port list connections not regenerating when adding a new item
4 changes: 2 additions & 2 deletions Editor/Controllers/GraphController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GraphViewBase;
using GraphViewBase;
using System;
using System.Collections.Generic;
using UnityEditor;
Expand Down Expand Up @@ -335,7 +335,7 @@ private void OnViewportChanged(GraphElementContainer contentContainer) {
/// </summary>
public void Reload() {
Logger.Log("reload");
if (graphData != null && graphData.BaseObject != null) {
if (graphData != null /*&& graphData.BaseObject != null*/) {
Load(graphData);
}
}
Expand Down
47 changes: 27 additions & 20 deletions Editor/Views/PortListView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using UnityEditor;
using UnityEditor.UIElements;
Expand Down Expand Up @@ -76,12 +77,25 @@ public PortListView(SerializedProperty listProperty, PortInfo portListInfo, Node
private void OnAddClicked() {
listProperty.arraySize++;
listProperty.serializedObject.ApplyModifiedProperties();

nodeView.RebuildPortListView(this);

RemoveEdges();
nodeView.RebuildPortListView(this);
}

private void RemoveEdges() {
for (int i = ports.Count - 1; i >= 0; i--) {
PortView port = ports[i];
GraphViewBase.BaseEdge[] edges = port.Connections.ToArray();
for (int j = edges.Length - 1; j >= 0; j--) {
edges[j].Disconnect();
}

ports.Remove(port);
}
}

private void OnItemsRemoved(IEnumerable<int> indices) {
/*
/*
foreach (var index in indices) {
PortView port = ports[index];
Expand All @@ -93,18 +107,9 @@ private void OnItemsRemoved(IEnumerable<int> indices) {
Debug.Log("disconnect");
ports.Remove(port);
}*/

for (int i= ports.Count-1; i>=0; i--) {
PortView port = ports[i];
GraphViewBase.BaseEdge[] edges = port.Connections.ToArray();
for (int j = edges.Length - 1; j >= 0; j--) {
edges[j].Disconnect();
}

ports.Remove(port);
}

nodeView.RebuildPortListView(this);
RemoveEdges();
nodeView.RebuildPortListView(this);
}

/// <summary>
Expand All @@ -116,15 +121,15 @@ private void OnRemoveClicked() {

listProperty.serializedObject.Update();
if (indices.Any()) {
for (var i = indices.Count - 1; i >= 0; i--) {
for (int i = indices.Count - 1; i >= 0; i--) {
int index = indices[i];
if (index >= 0 && index < listProperty.arraySize) {
listProperty.DeleteArrayElementAtIndex(index);

if (index < listProperty.arraySize - 1) {
var currentProperty = listProperty.GetArrayElementAtIndex(index);
for (var j = index + 1; j < listProperty.arraySize; j++) {
var nextProperty = listProperty.GetArrayElementAtIndex(j);
SerializedProperty currentProperty = listProperty.GetArrayElementAtIndex(index);
for (int j = index + 1; j < listProperty.arraySize; j++) {
SerializedProperty nextProperty = listProperty.GetArrayElementAtIndex(j);
if (nextProperty != null) {
currentProperty.isExpanded = nextProperty.isExpanded;
currentProperty = nextProperty;
Expand All @@ -135,7 +140,7 @@ private void OnRemoveClicked() {
}
ClearSelection();
} else if (listProperty.arraySize > 0) {
var index = listProperty.arraySize - 1;
int index = listProperty.arraySize - 1;
viewController.RemoveItem(index);
indices.Add(index);
}
Expand Down Expand Up @@ -246,6 +251,8 @@ private void RedrawConnection(PortView port, SerializedProperty prop) {
}

private void ItemIndexChanged(int draggedIndex, int dropIndex) {
UnityEngine.Debug.Log("ItemIndexChanged");

// get "real" indices
draggedIndex = viewController.GetIndexForId(draggedIndex);
dropIndex = viewController.GetIndexForId(dropIndex);
Expand Down
12 changes: 7 additions & 5 deletions Editor/Views/PortView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GraphViewBase;
using GraphViewBase;
using System;
using System.Collections.Generic;
using UnityEditor;
Expand Down Expand Up @@ -56,10 +56,12 @@ public override void Connect(BaseEdge edge) {
}

public void Reset() {
// set its value to null = remove reference
boundProperty.managedReferenceValue = null;
boundProperty.serializedObject.ApplyModifiedProperties();
connectionChangedCallback?.Invoke();
// set its value to null = remove reference
if (boundProperty != null) {
boundProperty.managedReferenceValue = null;
boundProperty.serializedObject.ApplyModifiedProperties();
connectionChangedCallback?.Invoke();
}
}

public override bool CanConnectTo(BasePort other, bool ignoreCandidateEdges = true) {
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.5",
"version": "0.3.6",
"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 ebe7d3e

Please sign in to comment.